Skip to content

Commit a02b5e0

Browse files
author
Travis CI
committed
Travis CI - [ci skip] - automatic dist folder
1 parent 975b7d4 commit a02b5e0

File tree

3 files changed

+144
-16
lines changed

3 files changed

+144
-16
lines changed

dist/kuzzle.js

Lines changed: 140 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ var currentQueue;
88
var queueIndex = -1;
99

1010
function cleanUpNextTick() {
11+
if (!draining || !currentQueue) {
12+
return;
13+
}
1114
draining = false;
1215
if (currentQueue.length) {
1316
queue = currentQueue.concat(queue);
@@ -961,6 +964,29 @@ Kuzzle.prototype.whoAmI = function (callback) {
961964
return self;
962965
};
963966

967+
/**
968+
* Gets the rights array of the currently logged user.
969+
*
970+
* @param {function} cb The callback containing the normalized array of rights.
971+
*/
972+
Kuzzle.prototype.getMyRights = function (options, cb) {
973+
var self = this;
974+
975+
if (!cb && typeof options === 'function') {
976+
cb = options;
977+
options = null;
978+
}
979+
980+
self.callbackRequired('Kuzzle.getMyRights', cb);
981+
982+
self.query({controller: 'auth', action:'getMyRights'}, {}, null, function (err, res) {
983+
if (err) {
984+
return cb(err);
985+
}
986+
987+
cb(null, res.result.hits);
988+
});
989+
};
964990

965991
/**
966992
* Update current user in Kuzzle.
@@ -1242,25 +1268,27 @@ Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
12421268
* Create a new instance of a KuzzleDataCollection object.
12431269
* If no index is specified, takes the default index.
12441270
*
1245-
* @param {string} [index] - The name of the data index containing the data collection
12461271
* @param {string} collection - The name of the data collection you want to manipulate
1272+
* @param {string} [index] - The name of the data index containing the data collection
12471273
* @returns {object} A KuzzleDataCollection instance
12481274
*/
1249-
Kuzzle.prototype.dataCollectionFactory = function(index, collection) {
1275+
Kuzzle.prototype.dataCollectionFactory = function(collection, index) {
12501276
this.isValid();
12511277

1252-
if (arguments.length === 1) {
1253-
collection = arguments[0];
1278+
if (!index) {
1279+
if (!this.defaultIndex) {
1280+
throw new Error('Unable to create a new data collection object: no index specified');
1281+
}
1282+
12541283
index = this.defaultIndex;
12551284
}
1256-
else if (arguments.length === 2 && typeof collection === 'object') {
1257-
headers = collection;
1258-
collection = index;
1259-
index = this.defaultIndex;
1285+
1286+
if (typeof index !== 'string') {
1287+
throw new Error('Invalid "index" argument: string expected, got ' + typeof index);
12601288
}
12611289

1262-
if (!index) {
1263-
throw new Error('Unable to create a new data collection object: no index specified');
1290+
if (typeof collection !== 'string') {
1291+
throw new Error('Invalid "collection" argument: string expected, got ' + typeof collection);
12641292
}
12651293

12661294
if (!this.collections[index]) {
@@ -2134,14 +2162,27 @@ KuzzleDataCollection.prototype.fetchDocument = function (documentId, options, cb
21342162
* @returns {Object} this
21352163
*/
21362164
KuzzleDataCollection.prototype.fetchAllDocuments = function (options, cb) {
2165+
var filters = {};
2166+
21372167
if (!cb && typeof options === 'function') {
21382168
cb = options;
21392169
options = null;
21402170
}
21412171

2172+
// copying pagination options to the search filter
2173+
if (options) {
2174+
if (options.from) {
2175+
filters.from = options.from;
2176+
}
2177+
2178+
if (options.size) {
2179+
filters.size = options.size;
2180+
}
2181+
}
2182+
21422183
this.kuzzle.callbackRequired('KuzzleDataCollection.fetchAll', cb);
21432184

2144-
this.advancedSearch({}, options, cb);
2185+
this.advancedSearch(filters, options, cb);
21452186

21462187
return this;
21472188
};
@@ -3769,7 +3810,7 @@ function KuzzleSecurity(kuzzle) {
37693810
return this.kuzzle.bluebird.promisifyAll(this, {
37703811
suffix: 'Promise',
37713812
filter: function (name, func, target, passes) {
3772-
var blacklist = ['roleFactory', 'profileFactory', 'userFactory'];
3813+
var blacklist = ['roleFactory', 'profileFactory', 'userFactory', 'isActionAllowed'];
37733814

37743815
return passes && blacklist.indexOf(name) === -1;
37753816
}
@@ -4461,8 +4502,95 @@ KuzzleSecurity.prototype.userFactory = function(id, content) {
44614502
return new KuzzleUser(this, id, content);
44624503
};
44634504

4505+
/**
4506+
* Tells whether an action is allowed, denied or conditional based on the rights
4507+
* rights provided as the first argument. An action is defined as a couple of
4508+
* action and controller (mandatory), plus an index and a collection(optional).
4509+
*
4510+
* @param {object} rights - The rights rights associated to a user
4511+
* (see getMyrights and getUserrights).
4512+
* @param {string} controller - The controller to check the action onto.
4513+
* @param {string} action - The action to perform.
4514+
* @param {string} index - (optional) The name of index to perform the action onto.
4515+
* @param {string} collection - (optional) The name of the collection to perform the action onto.
4516+
*
4517+
* @returns {string} ['allowed', 'denied', 'conditional'] where conditional cases
4518+
* correspond to rights containing closures.
4519+
* See also http://kuzzle.io/guide/#roles-definition
4520+
*/
4521+
KuzzleSecurity.prototype.isActionAllowed = function(rights, controller, action, index, collection) {
4522+
var filteredRights;
4523+
4524+
if (!rights || typeof rights !== 'object') {
4525+
throw new Error('rights parameter is mandatory for isActionAllowed function');
4526+
}
4527+
if (!controller || typeof controller !== 'string') {
4528+
throw new Error('controller parameter is mandatory for isActionAllowed function');
4529+
}
4530+
if (!action || typeof action !== 'string') {
4531+
throw new Error('action parameter is mandatory for isActionAllowed function');
4532+
}
4533+
4534+
// We filter in all the rights that match the request (including wildcards).
4535+
filteredRights = rights.filter(function (right) {
4536+
return right.controller === controller || right.controller === '*';
4537+
})
4538+
.filter(function (right) {
4539+
return right.action === action || right.action === '*';
4540+
})
4541+
.filter(function (right) {
4542+
return right.index === index || right.index === '*';
4543+
})
4544+
.filter(function (right) {
4545+
return right.collection === collection || right.collection === '*';
4546+
});
4547+
4548+
// Then, if at least one right allows the action, we return 'allowed'
4549+
if (filteredRights.some(function (item) { return item.value === 'allowed'; })) {
4550+
return 'allowed';
4551+
}
4552+
// If no right allows the action, we check for conditionals.
4553+
if (filteredRights.some(function (item) { return item.value === 'conditional'; })) {
4554+
return 'conditional';
4555+
}
4556+
// Otherwise we return 'denied'.
4557+
return 'denied';
4558+
};
4559+
4560+
4561+
/**
4562+
* Gets the rights array of a given user.
4563+
*
4564+
* @param {string} userId The id of the user.
4565+
* @param {function} cb The callback containing the normalized array of rights.
4566+
*/
4567+
KuzzleSecurity.prototype.getUserRights = function (userId, options, cb) {
4568+
var
4569+
data = {_id: userId},
4570+
self = this;
4571+
4572+
if (!userId || typeof userId !== 'string') {
4573+
throw new Error('userId parameter is mandatory for isActionAllowed function');
4574+
}
4575+
4576+
if (!cb && typeof options === 'function') {
4577+
cb = options;
4578+
options = null;
4579+
}
4580+
4581+
self.kuzzle.callbackRequired('Kuzzle.getUserRights', cb);
4582+
4583+
this.kuzzle.query(this.buildQueryArgs('getUserRights'), data, options, function (err, res) {
4584+
if (err) {
4585+
return cb(err);
4586+
}
4587+
4588+
cb(null, res.result.hits);
4589+
});
4590+
};
44644591

44654592
module.exports = KuzzleSecurity;
4593+
44664594
},{"./kuzzleProfile":9,"./kuzzleRole":10,"./kuzzleUser":13}],12:[function(require,module,exports){
44674595
function KuzzleSecurityDocument(kuzzleSecurity, id, content) {
44684596

0 commit comments

Comments
 (0)