@@ -44,7 +44,7 @@ function KuzzleSecurity(kuzzle) {
4444 * Retrieve a single Role using its unique role ID.
4545 *
4646 * @param {string } id
47- * @param {object } [options] - Optional parameters
47+ * @param {object|responseCallback } [options] - Optional parameters
4848 * @param {responseCallback } [cb] - returns Kuzzle's response
4949 */
5050KuzzleSecurity . prototype . getRole = function ( id , options , cb ) {
@@ -78,7 +78,7 @@ KuzzleSecurity.prototype.getRole = function (id, options, cb) {
7878 * That means that a role that was just been created won’t be returned by this function.
7979 *
8080 * @param {Object } filters - this object can contains an array `indexes` with a list of index id, a integer `from` and a integer `size`
81- * @param {object } [options] - Optional parameters
81+ * @param {object|responseCallback } [options] - Optional parameters
8282 * @param {responseCallback } [cb] - returns Kuzzle's response
8383 *
8484 */
@@ -118,7 +118,7 @@ KuzzleSecurity.prototype.searchRoles = function (filters, options, cb) {
118118 *
119119 * @param {string } id - role identifier
120120 * @param {object } content - a plain javascript object representing the role
121- * @param {object } [options] - (optional) arguments
121+ * @param {object|responseCallback } [options] - (optional) arguments
122122 * @param {responseCallback } [cb] - (optional) Handles the query response
123123 */
124124KuzzleSecurity . prototype . createRole = function ( id , content , options , cb ) {
@@ -154,7 +154,7 @@ KuzzleSecurity.prototype.createRole = function (id, content, options, cb) {
154154 *
155155 * @param {string } id - role identifier
156156 * @param {object } content - a plain javascript object representing the role's modification
157- * @param {object } [options] - (optional) arguments
157+ * @param {object|responseCallback } [options] - (optional) arguments
158158 * @param {responseCallback } [cb] - (optional) Handles the query response
159159 * @returns {KuzzleSecurity } this object
160160 */
@@ -189,7 +189,7 @@ KuzzleSecurity.prototype.updateRole = function (id, content, options, cb) {
189189 *
190190 *
191191 * @param {string } id - Role id to delete
192- * @param {object } [options] - (optional) arguments
192+ * @param {object|responseCallback } [options] - (optional) arguments
193193 * @param {responseCallback } [cb] - Handles the query response
194194 * @returns {KuzzleSecurity } this object
195195 */
@@ -226,7 +226,7 @@ KuzzleSecurity.prototype.roleFactory = function(id, content) {
226226 *
227227 *
228228 * @param {string } id
229- * @param {object } [options] - (optional) arguments
229+ * @param {object|responseCallback } [options] - (optional) arguments
230230 * @param {responseCallback } cb - returns Kuzzle's response
231231 */
232232KuzzleSecurity . prototype . getProfile = function ( id , options , cb ) {
@@ -262,7 +262,7 @@ KuzzleSecurity.prototype.getProfile = function (id, options, cb) {
262262 * That means that a profile that was just been created won’t be returned by this function.
263263 *
264264 * @param {Object } filters - this object can contains an array `roles` with a list of roles id, a integer `from` and a integer `size`
265- * @param {object } [options] - (optional) arguments
265+ * @param {object|responseCallback } [options] - (optional) arguments
266266 * @param {responseCallback } [cb] - returns Kuzzle's response
267267 */
268268KuzzleSecurity . prototype . searchProfiles = function ( filters , options , cb ) {
@@ -301,7 +301,7 @@ KuzzleSecurity.prototype.searchProfiles = function (filters, options, cb) {
301301 *
302302 * @param {string } id - profile identifier
303303 * @param {object } content - attribute `roles` in `content` must only contains an array of role id
304- * @param {object } [options] - (optional) arguments
304+ * @param {object|responseCallback } [options] - (optional) arguments
305305 * @param {responseCallback } [cb] - (optional) Handles the query response
306306 */
307307KuzzleSecurity . prototype . createProfile = function ( id , content , options , cb ) {
@@ -337,7 +337,7 @@ KuzzleSecurity.prototype.createProfile = function (id, content, options, cb) {
337337 *
338338 * @param {string } id - profile identifier
339339 * @param {object } content - a plain javascript object representing the profile's modification
340- * @param {object } [options] - (optional) arguments
340+ * @param {object|responseCallback } [options] - (optional) arguments
341341 * @param {responseCallback } [cb] - (optional) Handles the query response
342342 * @returns {KuzzleSecurity } this object
343343 */
@@ -385,7 +385,7 @@ KuzzleSecurity.prototype.updateProfile = function (id, content, options, cb) {
385385 *
386386 *
387387 * @param {string } id - Profile id to delete
388- * @param {object } [options] - (optional) arguments
388+ * @param {object|responseCallback } [options] - (optional) arguments
389389 * @param {responseCallback } [cb] - Handles the query response
390390 * @returns {KuzzleSecurity } this object
391391 */
@@ -420,7 +420,7 @@ KuzzleSecurity.prototype.profileFactory = function(id, content) {
420420 * Get a specific user from kuzzle using its unique ID
421421 *
422422 * @param {string } id
423- * @param {object } [options] - (optional) arguments
423+ * @param {object|responseCallback } [options] - (optional) arguments
424424 * @param {responseCallback } cb - returns Kuzzle's response
425425 */
426426KuzzleSecurity . prototype . getUser = function ( id , options , cb ) {
@@ -452,7 +452,7 @@ KuzzleSecurity.prototype.getUser = function (id, options, cb) {
452452 * That means that a user that was just been created won’t be returned by this function.
453453 *
454454 * @param {Object } filters - same filters as documents filters
455- * @param {object } [options] - (optional) arguments
455+ * @param {object|responseCallback } [options] - (optional) arguments
456456 * @param {responseCallback } [cb] - returns Kuzzle's response
457457 */
458458KuzzleSecurity . prototype . searchUsers = function ( filters , options , cb ) {
@@ -490,8 +490,8 @@ KuzzleSecurity.prototype.searchUsers = function (filters, options, cb) {
490490 * Replace the existing user otherwise
491491 *
492492 * @param {string } id - user identifier
493- * @param {object } content - attribute `profile ` in `content` must only contains the profile id
494- * @param {object } [options] - (optional) arguments
493+ * @param {object } content - attribute `profileIds ` in `content` must only contain an array of profile ids
494+ * @param {object|responseCallback } [options] - (optional) arguments
495495 * @param {responseCallback } [cb] - (optional) Handles the query response
496496 */
497497KuzzleSecurity . prototype . createUser = function ( id , content , options , cb ) {
@@ -518,13 +518,47 @@ KuzzleSecurity.prototype.createUser = function (id, content, options, cb) {
518518 } ) ;
519519} ;
520520
521+ /**
522+ * Create a new restricted user in Kuzzle.
523+ *
524+ * This function will create a new user. It is not usable to update an existing user.
525+ * This function allows anonymous users to create a "restricted" user with predefined rights.
526+ *
527+ * @param {string } id - user identifier
528+ * @param {object } content - attribute `profile` in `content` must only contains the profile id
529+ * @param {object|responseCallback } [options] - (optional) arguments
530+ * @param {responseCallback } [cb] - (optional) Handles the query response
531+ */
532+ KuzzleSecurity . prototype . createRestrictedUser = function ( id , content , options , cb ) {
533+ var
534+ self = this ,
535+ data = { _id : id , body : content } ;
536+
537+ if ( ! id || typeof id !== 'string' ) {
538+ throw new Error ( 'KuzzleSecurity.createRestrictedUser: cannot create a user without a user ID' ) ;
539+ }
540+
541+ if ( content . profileIds ) {
542+ throw new Error ( 'KuzzleSecurity.createRestrictedUser: cannot provide profileIds' ) ;
543+ }
544+
545+ if ( ! cb && typeof options === 'function' ) {
546+ cb = options ;
547+ options = null ;
548+ }
549+
550+ self . kuzzle . query ( this . buildQueryArgs ( 'createRestrictedUser' ) , data , null , cb && function ( err , res ) {
551+ cb ( err , err ? undefined : new KuzzleUser ( self , res . result . _id , res . result . _source ) ) ;
552+ } ) ;
553+ } ;
554+
521555
522556/**
523557 * Update an user in Kuzzle.
524558 *
525559 * @param {string } id - user identifier
526560 * @param {object } content - a plain javascript object representing the user's modification
527- * @param {object } [options] - (optional) arguments
561+ * @param {object|responseCallback } [options] - (optional) arguments
528562 * @param {responseCallback } [cb] - (optional) Handles the query response
529563 * @returns {KuzzleSecurity } this object
530564 */
@@ -562,7 +596,7 @@ KuzzleSecurity.prototype.updateUser = function (id, content, options, cb) {
562596 *
563597 *
564598 * @param {string } id - Profile id to delete
565- * @param {object } [options] - (optional) arguments
599+ * @param {object|responseCallback } [options] - (optional) arguments
566600 * @param {responseCallback } [cb] - Handles the query response
567601 * @returns {KuzzleSecurity } this object
568602 */
@@ -654,8 +688,8 @@ KuzzleSecurity.prototype.isActionAllowed = function(rights, controller, action,
654688 * Gets the rights array of a given user.
655689 *
656690 * @param {string } userId The id of the user.
657- * @param {object } [options] - (optional) arguments
658- * @param {function } cb The callback containing the normalized array of rights.
691+ * @param {object|responseCallback } [options] - (optional) arguments
692+ * @param {function } cb The callback containing the normalized array of rights.
659693 */
660694KuzzleSecurity . prototype . getUserRights = function ( userId , options , cb ) {
661695 var
0 commit comments