@@ -2077,7 +2077,7 @@ function KuzzleDataMapping(kuzzleDataCollection, mapping) {
20772077 //read-only properties
20782078 collection : {
20792079 value : kuzzleDataCollection ,
2080- eunmerable : true
2080+ enumerable : true
20812081 } ,
20822082 kuzzle : {
20832083 value : kuzzleDataCollection . kuzzle ,
@@ -3037,7 +3037,7 @@ KuzzleProfile.prototype.hydrate = function (options, cb) {
30373037 return cb ( error ) ;
30383038 }
30393039
3040- cb ( null , new KuzzleProfile ( self , response . result . _id , response . result . _source ) ) ;
3040+ cb ( null , new KuzzleProfile ( self , self . id , { roles : response . result . hits } ) ) ;
30413041 } ) ;
30423042} ;
30433043
@@ -3764,7 +3764,7 @@ function KuzzleSecurityDocument(kuzzleSecurity, id, content) {
37643764 } ) ;
37653765
37663766 if ( content ) {
3767- this . setContent ( content ) ;
3767+ this . setContent ( content , true ) ;
37683768 }
37693769
37703770 // promisifying
@@ -3781,13 +3781,25 @@ function KuzzleSecurityDocument(kuzzleSecurity, id, content) {
37813781}
37823782
37833783/**
3784+ * Replaces the current content with new data.
3785+ * Changes made by this function won’t be applied until the save method is called.
37843786 *
37853787 * @param {Object } data - New securityDocument content
3788+ * @param {boolean } replace - if true: replace this document content with the provided data.
37863789 *
37873790 * @return {Object } this
37883791 */
3789- KuzzleSecurityDocument . prototype . setContent = function ( data ) {
3790- this . content = data ;
3792+ KuzzleSecurityDocument . prototype . setContent = function ( data , replace ) {
3793+ var self = this ;
3794+
3795+ if ( replace ) {
3796+ this . content = data ;
3797+ }
3798+ else {
3799+ Object . keys ( data ) . forEach ( function ( key ) {
3800+ self . content [ key ] = data [ key ] ;
3801+ } ) ;
3802+ }
37913803
37923804 return this ;
37933805} ;
@@ -3901,11 +3913,16 @@ KuzzleUser.prototype.hydrate = function (options, cb) {
39013913 }
39023914
39033915 self . kuzzle . query ( this . kuzzleSecurity . buildQueryArgs ( 'getProfile' ) , { _id : this . content . profile } , options , function ( error , response ) {
3916+ var hydratedUser ;
3917+
39043918 if ( error ) {
39053919 return cb ( error ) ;
39063920 }
39073921
3908- cb ( null , new KuzzleUser ( self , response . result . _id , response . result . _source ) ) ;
3922+ hydratedUser = new KuzzleUser ( self . kuzzleSecurity , self . id , self . content ) ;
3923+ hydratedUser . setProfile ( new KuzzleProfile ( self . kuzzleSecurity , response . result . _id , response . result . _source ) ) ;
3924+
3925+ cb ( null , hydratedUser ) ;
39093926 } ) ;
39103927} ;
39113928
0 commit comments