Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ template: default
expected:
- "User {"
- "_id: 'jdoe',"
- "content: {"
- "_source: {"
- "profileIds: \\[ \\'default\\' \\],"
21 changes: 11 additions & 10 deletions doc/7/core-classes/user/properties/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ order: 10
# Properties


| Property | Type | Description |
|--- |--- |--- |
| `_id` | <pre>string</pre> | User ID (kuid) |
| `content` | <pre>object</pre> | User internal content |
| Property | Type | Description |
|-----------|-------------------|---------------------------------------------------------------|
| `_id` | <pre>string</pre> | User ID (kuid) |
| `_source` | <pre>object</pre> | User internal content <SinceBadge since="auto-version"/> |
| `content` | <pre>object</pre> | User internal content <DeprecatedBadge since="auto-version"/> |

### content
### _source

The `content` property is an object containing, alongside custom defined values, the following generic properties:
The `_source` property is an object containing, alongside custom defined values, the following generic properties:

| Property | Type | Description |
|--- |--- |--- |
| `profileIds` | <pre>string[]</pre> | Profiles IDs for this user |
| `_kuzzle_info` | <pre>object</pre> | [Kuzzle metadata](/core/2/guides/main-concepts/data-storage#kuzzle-metadata) |
| Property | Type | Description |
|----------------|---------------------|------------------------------------------------------------------------------|
| `profileIds` | <pre>string[]</pre> | Profiles IDs for this user |
| `_kuzzle_info` | <pre>object</pre> | [Kuzzle metadata](/core/2/guides/main-concepts/data-storage#kuzzle-metadata) |
18 changes: 14 additions & 4 deletions src/core/security/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ export class User {
* Kuid (Kuzzle unique ID)
*/
public _id: string;

/**
* User content
*/
public _source: JSONObject;

/**
* Custom content
* User content
*
* @deprecated
*/
public content: JSONObject;
get content (): JSONObject {
return this._source;
}

private _kuzzle: any;

Expand All @@ -24,7 +34,7 @@ export class User {
});

this._id = _id;
this.content = content;
this._source = content;
}

private get kuzzle () {
Expand All @@ -35,7 +45,7 @@ export class User {
* Array of profile IDs
*/
get profileIds (): Array<string> {
return this.content.profileIds || [];
return this._source.profileIds || [];
}

/**
Expand Down
14 changes: 14 additions & 0 deletions test/core/security/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ describe('User', () => {
});
});
});

describe('#_source', () => {
it('should return the user custom content', () => {
user = new User({}, 'foobar', { email: '[email protected]' });

should(user._source).be.eql({ email: '[email protected]' });
});

it('should keep accessors to deprecated "content" getter', () => {
user = new User({}, 'foobar', { email: '[email protected]' });

should(user.content).be.eql({ email: '[email protected]' });
});
});
});