Skip to content

Commit 924618f

Browse files
committed
Merge pull request #52 from kuzzleio/KUZ-378-whoami
KUZ-378 OMG Who Am I? (identity crisis)
2 parents 6a40485 + 8e578b0 commit 924618f

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

dist/kuzzle.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ module.exports = Kuzzle = function (url, options, cb) {
541541
filter: function (name, func, target, passes) {
542542
var whitelist = ['getAllStatistics', 'getServerInfo', 'getStatistics',
543543
'listCollections', 'listIndexes', 'login', 'logout', 'now', 'query',
544-
'checkToken'];
544+
'checkToken', 'whoAmI'];
545545

546546
return passes && whitelist.indexOf(name) !== -1;
547547
}
@@ -753,6 +753,23 @@ Kuzzle.prototype.checkToken = function (token, callback) {
753753
return self;
754754
};
755755

756+
/**
757+
* Fetches the current user.
758+
*
759+
* @param {function} callback The callback to be called when the response is
760+
* available. The signature is `function(error, response)`.
761+
* @return {Kuzzle} The Kuzzle instance to enable chaining.
762+
*/
763+
Kuzzle.prototype.whoAmI = function (callback) {
764+
var self = this;
765+
766+
this.callbackRequired('Kuzzle.whoAmI', callback);
767+
768+
this.query({controller: 'auth', action: 'getCurrentUser'}, {}, {}, callback);
769+
770+
return self;
771+
};
772+
756773
/**
757774
* Clean up the queue, ensuring the queryTTL and queryMaxSize properties are respected
758775
*/

dist/kuzzle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/kuzzle.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/kuzzle.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ module.exports = Kuzzle = function (url, options, cb) {
266266
filter: function (name, func, target, passes) {
267267
var whitelist = ['getAllStatistics', 'getServerInfo', 'getStatistics',
268268
'listCollections', 'listIndexes', 'login', 'logout', 'now', 'query',
269-
'checkToken'];
269+
'checkToken', 'whoAmI'];
270270

271271
return passes && whitelist.indexOf(name) !== -1;
272272
}
@@ -478,6 +478,23 @@ Kuzzle.prototype.checkToken = function (token, callback) {
478478
return self;
479479
};
480480

481+
/**
482+
* Fetches the current user.
483+
*
484+
* @param {function} callback The callback to be called when the response is
485+
* available. The signature is `function(error, response)`.
486+
* @return {Kuzzle} The Kuzzle instance to enable chaining.
487+
*/
488+
Kuzzle.prototype.whoAmI = function (callback) {
489+
var self = this;
490+
491+
this.callbackRequired('Kuzzle.whoAmI', callback);
492+
493+
this.query({controller: 'auth', action: 'getCurrentUser'}, {}, {}, callback);
494+
495+
return self;
496+
};
497+
481498
/**
482499
* Clean up the queue, ensuring the queryTTL and queryMaxSize properties are respected
483500
*/

test/kuzzle/constructor.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ describe('Kuzzle constructor', () => {
186186
should.exist(kuzzle.nowPromise);
187187
should.exist(kuzzle.queryPromise);
188188
should.exist(kuzzle.checkTokenPromise);
189+
should.exist(kuzzle.whoAmIPromise);
189190
should.not.exist(kuzzle.removeAllListenersPromise);
190191
should.not.exist(kuzzle.removeListenerPromise);
191192
should.not.exist(kuzzle.replayQueuePromise);

test/kuzzle/methods.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,24 @@ describe('Kuzzle methods', function () {
542542
}
543543
});
544544
});
545+
546+
describe('#whoAmI', function () {
547+
it('should send the getCurrentUser after call', function () {
548+
var kuzzle;
549+
550+
this.timeout(200);
551+
552+
kuzzle = new Kuzzle('nowhere', {
553+
connect: 'manual'
554+
});
555+
556+
kuzzle.queuing = true;
557+
558+
kuzzle.whoAmI(function (err, res) {});
559+
560+
should(kuzzle.offlineQueue.length).be.exactly(1);
561+
should(kuzzle.offlineQueue[0].query.action).be.exactly('getCurrentUser');
562+
should(kuzzle.offlineQueue[0].query.controller).be.exactly('auth');
563+
});
564+
});
545565
});

0 commit comments

Comments
 (0)