@@ -2077,7 +2077,7 @@ function KuzzleDataMapping(kuzzleDataCollection, mapping) {
2077
2077
//read-only properties
2078
2078
collection : {
2079
2079
value : kuzzleDataCollection ,
2080
- eunmerable : true
2080
+ enumerable : true
2081
2081
} ,
2082
2082
kuzzle : {
2083
2083
value : kuzzleDataCollection . kuzzle ,
@@ -3037,7 +3037,7 @@ KuzzleProfile.prototype.hydrate = function (options, cb) {
3037
3037
return cb ( error ) ;
3038
3038
}
3039
3039
3040
- cb ( null , new KuzzleProfile ( self , response . result . _id , response . result . _source ) ) ;
3040
+ cb ( null , new KuzzleProfile ( self , self . id , { roles : response . result . hits } ) ) ;
3041
3041
} ) ;
3042
3042
} ;
3043
3043
@@ -3764,7 +3764,7 @@ function KuzzleSecurityDocument(kuzzleSecurity, id, content) {
3764
3764
} ) ;
3765
3765
3766
3766
if ( content ) {
3767
- this . setContent ( content ) ;
3767
+ this . setContent ( content , true ) ;
3768
3768
}
3769
3769
3770
3770
// promisifying
@@ -3781,13 +3781,25 @@ function KuzzleSecurityDocument(kuzzleSecurity, id, content) {
3781
3781
}
3782
3782
3783
3783
/**
3784
+ * Replaces the current content with new data.
3785
+ * Changes made by this function won’t be applied until the save method is called.
3784
3786
*
3785
3787
* @param {Object } data - New securityDocument content
3788
+ * @param {boolean } replace - if true: replace this document content with the provided data.
3786
3789
*
3787
3790
* @return {Object } this
3788
3791
*/
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
+ }
3791
3803
3792
3804
return this ;
3793
3805
} ;
@@ -3901,11 +3913,16 @@ KuzzleUser.prototype.hydrate = function (options, cb) {
3901
3913
}
3902
3914
3903
3915
self . kuzzle . query ( this . kuzzleSecurity . buildQueryArgs ( 'getProfile' ) , { _id : this . content . profile } , options , function ( error , response ) {
3916
+ var hydratedUser ;
3917
+
3904
3918
if ( error ) {
3905
3919
return cb ( error ) ;
3906
3920
}
3907
3921
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 ) ;
3909
3926
} ) ;
3910
3927
} ;
3911
3928
0 commit comments