Skip to content

Commit 44f022d

Browse files
authored
Add _source property to user objects (#606)
Add a _source property containing the user custom content to match the API.
1 parent fce607b commit 44f022d

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

doc/7/controllers/security/create-user/snippets/create-user.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ template: default
66
expected:
77
- "User {"
88
- "_id: 'jdoe',"
9-
- "content: {"
9+
- "_source: {"
1010
- "profileIds: \\[ \\'default\\' \\],"

doc/7/core-classes/user/properties/index.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ order: 10
99
# Properties
1010

1111

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

17-
### content
18+
### _source
1819

19-
The `content` property is an object containing, alongside custom defined values, the following generic properties:
20+
The `_source` property is an object containing, alongside custom defined values, the following generic properties:
2021

21-
| Property | Type | Description |
22-
|--- |--- |--- |
23-
| `profileIds` | <pre>string[]</pre> | Profiles IDs for this user |
24-
| `_kuzzle_info` | <pre>object</pre> | [Kuzzle metadata](/core/2/guides/main-concepts/data-storage#kuzzle-metadata) |
22+
| Property | Type | Description |
23+
|----------------|---------------------|------------------------------------------------------------------------------|
24+
| `profileIds` | <pre>string[]</pre> | Profiles IDs for this user |
25+
| `_kuzzle_info` | <pre>object</pre> | [Kuzzle metadata](/core/2/guides/main-concepts/data-storage#kuzzle-metadata) |

src/core/security/User.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ export class User {
66
* Kuid (Kuzzle unique ID)
77
*/
88
public _id: string;
9+
10+
/**
11+
* User content
12+
*/
13+
public _source: JSONObject;
14+
915
/**
10-
* Custom content
16+
* User content
17+
*
18+
* @deprecated
1119
*/
12-
public content: JSONObject;
20+
get content (): JSONObject {
21+
return this._source;
22+
}
1323

1424
private _kuzzle: any;
1525

@@ -24,7 +34,7 @@ export class User {
2434
});
2535

2636
this._id = _id;
27-
this.content = content;
37+
this._source = content;
2838
}
2939

3040
private get kuzzle () {
@@ -35,7 +45,7 @@ export class User {
3545
* Array of profile IDs
3646
*/
3747
get profileIds (): Array<string> {
38-
return this.content.profileIds || [];
48+
return this._source.profileIds || [];
3949
}
4050

4151
/**

test/core/security/user.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,18 @@ describe('User', () => {
4141
});
4242
});
4343
});
44+
45+
describe('#_source', () => {
46+
it('should return the user custom content', () => {
47+
user = new User({}, 'foobar', { email: 'foobar@goo.com' });
48+
49+
should(user._source).be.eql({ email: 'foobar@goo.com' });
50+
});
51+
52+
it('should keep accessors to deprecated "content" getter', () => {
53+
user = new User({}, 'foobar', { email: 'foobar@goo.com' });
54+
55+
should(user.content).be.eql({ email: 'foobar@goo.com' });
56+
});
57+
});
4458
});

0 commit comments

Comments
 (0)