- 
                Notifications
    You must be signed in to change notification settings 
- Fork 17
Kuz 490 repositories refactor #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            13 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      eff4e88
              
                first sight
              
              
                 52169ab
              
                user tests
              
              
                 8ca72ba
              
                profile tests
              
              
                 3f8c672
              
                actual tests adaptation
              
              
                 64a18f7
              
                lint
              
              
                 ceb1450
              
                coverage and cleanup
              
              
                 3125143
              
                all done
              
              
                 47e48ab
              
                adds methos addProfile to user
              
              
                 58d2f20
              
                finalize
              
              
                 4213e73
              
                changes following @scottinet's remarks
              
              
                 6085f57
              
                changes following @scottinet's remarks (bis)
              
              
                 f17874b
              
                restore jsdoc
              
              
                 638ff41
              
                nitpick following @ballinette's advice
              
              
                 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -252,9 +252,6 @@ KuzzleSecurity.prototype.roleFactory = function(id, content) { | |
| /** | ||
| * Get a specific profile from kuzzle | ||
| * | ||
| * Takes an optional argument object with the following property: | ||
| * - hydrate (boolean, default: true): | ||
| * if is set to false, return a list id in role instead of KuzzleRole. | ||
| * | ||
| * @param {string} id | ||
| * @param {object} [options] - (optional) arguments | ||
|  | @@ -263,21 +260,18 @@ KuzzleSecurity.prototype.roleFactory = function(id, content) { | |
| KuzzleSecurity.prototype.getProfile = function (id, options, cb) { | ||
| var | ||
| data, | ||
| self = this, | ||
| hydrate = true; | ||
|  | ||
| if (!id || typeof id !== 'string') { | ||
| throw new Error('Id parameter is mandatory for getProfile function'); | ||
| } | ||
| self = this; | ||
|  | ||
| if (!cb && typeof options === 'function') { | ||
| cb = options; | ||
| options = null; | ||
| } | ||
| else if (options.hydrate !== undefined) { | ||
| hydrate = options.hydrate; | ||
|  | ||
| if (!id || typeof id !== 'string') { | ||
| throw new Error('Id parameter is mandatory for getProfile function'); | ||
| } | ||
|  | ||
|  | ||
| data = {_id: id}; | ||
|  | ||
| self.kuzzle.callbackRequired('KuzzleSecurity.getProfile', cb); | ||
|  | @@ -287,31 +281,13 @@ KuzzleSecurity.prototype.getProfile = function (id, options, cb) { | |
| return cb(error); | ||
| } | ||
|  | ||
| if (!hydrate) { | ||
| response.result._source.roles = response.result._source.roles.map(function (role) { | ||
| var formattedRole = {_id: role._id}; | ||
| if (role._source.restrictedTo !== undefined) { | ||
| formattedRole.restrictedTo = role._source.restrictedTo; | ||
| } | ||
| if (role._source.allowInternalIndex !== undefined) { | ||
| formattedRole.allowInternalIndex = role._source.allowInternalIndex; | ||
| } | ||
|  | ||
| return formattedRole; | ||
| }); | ||
| } | ||
|  | ||
| cb(null, new KuzzleProfile(self, response.result._id, response.result._source)); | ||
| }); | ||
| }; | ||
|  | ||
| /** | ||
| * Executes a search on profiles according to a filter | ||
| * | ||
| * Takes an optional argument object with the following property: | ||
| * - hydrate (boolean, default: true): | ||
| * if is set to false, return a list id in role instead of KuzzleRole. | ||
| * Because hydrate need to fetch all related KuzzleRole object, leave hydrate to true will have a performance cost | ||
| * | ||
| * /!\ There is a small delay between profile creation and their existence in our persistent search layer, | ||
| * usually a couple of seconds. | ||
|  | @@ -325,15 +301,10 @@ KuzzleSecurity.prototype.searchProfiles = function (filters, options, cb) { | |
| var | ||
| self = this; | ||
|  | ||
| filters.hydrate = true; | ||
|  | ||
| if (!cb && typeof options === 'function') { | ||
| cb = options; | ||
| options = null; | ||
| } | ||
| else if (options.hydrate !== undefined) { | ||
| filters.hydrate = options.hydrate; | ||
| } | ||
|  | ||
| self.kuzzle.callbackRequired('KuzzleSecurity.searchProfiles', cb); | ||
|  | ||
|  | @@ -439,13 +410,7 @@ KuzzleSecurity.prototype.updateProfile = function (id, content, options, cb) { | |
| } | ||
|  | ||
| Object.keys(res.result._source).forEach(function (property) { | ||
| if (property !== 'roles') { | ||
| updatedContent[property] = res.result._source[property]; | ||
| } | ||
| }); | ||
|  | ||
| updatedContent.roles = res.result._source.roles.map(function (role) { | ||
| return role._id; | ||
| updatedContent[property] = res.result._source[property]; | ||
| }); | ||
|  | ||
| cb(null, new KuzzleProfile(self, res.result._id, updatedContent)); | ||
|  | @@ -503,19 +468,14 @@ KuzzleSecurity.prototype.profileFactory = function(id, content) { | |
| /** | ||
| * Get a specific user from kuzzle using its unique ID | ||
| * | ||
| * Takes an optional argument object with the following property: | ||
| * - hydrate (boolean, default: true): | ||
| * if is set to false, return a list id in role instead of KuzzleRole. | ||
| * | ||
| * @param {string} id | ||
| * @param {object} [options] - (optional) arguments | ||
| * @param {responseCallback} cb - returns Kuzzle's response | ||
| */ | ||
| KuzzleSecurity.prototype.getUser = function (id, options, cb) { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The jsdoc must also be restored. | ||
| var | ||
| data, | ||
| self = this, | ||
| hydrate = true; | ||
| self = this; | ||
|  | ||
| if (!id || typeof id !== 'string') { | ||
| throw new Error('Id parameter is mandatory for getUser function'); | ||
|  | @@ -525,9 +485,6 @@ KuzzleSecurity.prototype.getUser = function (id, options, cb) { | |
| cb = options; | ||
| options = null; | ||
| } | ||
| else if (options.hydrate !== undefined) { | ||
| hydrate = options.hydrate; | ||
| } | ||
|  | ||
| data = {_id: id}; | ||
|  | ||
|  | @@ -538,22 +495,13 @@ KuzzleSecurity.prototype.getUser = function (id, options, cb) { | |
| return cb(err); | ||
| } | ||
|  | ||
| if (!hydrate) { | ||
| response.result._source.profile = response.result._source.profile._id; | ||
| } | ||
|  | ||
| cb(null, new KuzzleUser(self, response.result._id, response.result._source)); | ||
| }); | ||
| }; | ||
|  | ||
| /** | ||
| * Executes a search on user according to a filter | ||
| * | ||
| * Takes an optional argument object with the following property: | ||
| * - hydrate (boolean, default: true): | ||
| * if is set to false, return a list id in role instead of KuzzleRole. | ||
| * Because hydrate need to fetch all related KuzzleRole object, leave hydrate to true will have a performance cost | ||
| * | ||
| * /!\ There is a small delay between user creation and their existence in our persistent search layer, | ||
| * usually a couple of seconds. | ||
| * That means that a user that was just been created won’t be returned by this function. | ||
|  | @@ -566,15 +514,10 @@ KuzzleSecurity.prototype.searchUsers = function (filters, options, cb) { | |
| var | ||
| self = this; | ||
|  | ||
| filters.hydrate = true; | ||
|  | ||
| if (!cb && typeof options === 'function') { | ||
| cb = options; | ||
| options = null; | ||
| } | ||
| else if (options.hydrate !== undefined) { | ||
| filters.hydrate = options.hydrate; | ||
| } | ||
|  | ||
| self.kuzzle.callbackRequired('KuzzleSecurity.searchUsers', cb); | ||
|  | ||
|  | @@ -788,16 +731,17 @@ KuzzleSecurity.prototype.isActionAllowed = function(rights, controller, action, | |
| /** | ||
| * Gets the rights array of a given user. | ||
| * | ||
| * @param {string} userId The id of the user. | ||
| * @param {function} cb The callback containing the normalized array of rights. | ||
| * @param {string} userId The id of the user. | ||
| * @param {object} [options] - (optional) arguments | ||
| * @param {function} cb The callback containing the normalized array of rights. | ||
| */ | ||
| KuzzleSecurity.prototype.getUserRights = function (userId, options, cb) { | ||
| var | ||
| data = {_id: userId}, | ||
| self = this; | ||
|  | ||
| if (!userId || typeof userId !== 'string') { | ||
| throw new Error('userId parameter is mandatory for isActionAllowed function'); | ||
| throw new Error('userId parameter is mandatory for getUserRights function'); | ||
| } | ||
|  | ||
| if (!cb && typeof options === 'function') { | ||
|  | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The jsdoc must also be restored.