6
6
#### new AccessControl()
7
7
The AccessControl object has various methods to control the access for users.
8
8
9
+ ** Example**
10
+ ``` js
11
+ const accessContol = new AccessControl (" https://servername.com" ,
12
+ {organization: " my_team_name" ,
13
+ jwt: " eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkpXUjBIOXYyeTFORUd........" })
14
+ accessControl .getOrgUsers ().then (result => {
15
+ console .log (result)
16
+ })
17
+ // if the jwt is expired you can change it with
18
+ accessControl .setJwtToken (" eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkpXUjBIOXYyeTFORUd......." )
19
+ ```
9
20
10
21
### getDefaultOrganization
11
22
#### accessControl.getDefaultOrganization(params) ⇒ <code >string</code > \| <code >undefined</code >
@@ -18,25 +29,25 @@ Get a organization from parameters.
18
29
| params | <code >object</code > | The parameters |
19
30
20
31
21
- ### getAPIToken
22
- #### accessControl.getAPIToken (params) ⇒ <code >string</code >
32
+ ### getJwtToken
33
+ #### accessControl.getJwtToken (params) ⇒ <code >string</code >
23
34
Get a API token from parameters.
24
35
25
- ** Returns** : <code >string</code > - apiToken
36
+ ** Returns** : <code >string</code > - jwt api token
26
37
27
38
| Param | Type | Description |
28
39
| --- | --- | --- |
29
40
| params | <code >object</code > | The parameters |
30
41
31
42
32
- ### setAPIToken
33
- #### accessControl.setAPIToken(token )
43
+ ### setJwtToken
44
+ #### accessControl.setJwtToken(jwt )
34
45
Sets the API token for the object
35
46
36
47
37
48
| Param | Type | Description |
38
49
| --- | --- | --- |
39
- | token | <code >string</code > | The api token to use |
50
+ | jwt | <code >string</code > | The jwt api token to use |
40
51
41
52
42
53
### getAPIUrl
@@ -50,8 +61,8 @@ Get a API url from cloudAPIUrl
50
61
| cloudAPIUrl | <code >string</code > | The base url for cloud |
51
62
52
63
53
- ### getUserRoles
54
- #### accessControl.getUserRoles () ⇒ <code >Promise</code >
64
+ ### getAccessRoles
65
+ #### accessControl.getAccessRoles () ⇒ <code >Promise</code >
55
66
Get all the system database roles types.
56
67
57
68
** Returns** : <code >Promise</code > - A promise that returns the call response object, or an Error if rejected.
@@ -66,30 +77,24 @@ Any user can create their own organization.
66
77
| --- | --- | --- |
67
78
| orgName | <code >string</code > | The organization name to create |
68
79
80
+ ** Example**
81
+ ``` js
82
+ accessControl .createOrganization (" my_org_name" ).then (result => {
83
+ console .log (result)
84
+ })
85
+ ```
69
86
70
87
### ifOrganizationExists
71
88
#### accessControl.ifOrganizationExists(orgName) ⇒ <code >Promise</code >
72
- Check if the organization exists.
89
+ Check if the organization exists. it is a Head call .
73
90
74
- ** Returns** : <code >Promise</code > - A promise that returns the call response object, or an Error if rejected.
91
+ ** Returns** : <code >Promise</code > - A promise that returns the call status object, 200: if the organization exists and 404: if the organization does not exist
75
92
76
93
| Param | Type | Description |
77
94
| --- | --- | --- |
78
95
| orgName | <code >string</code > | The organization name to check if exists. |
79
96
80
97
81
- ### removeUserFromOrg
82
- #### accessControl.removeUserFromOrg(userId, [ orgName] ) ⇒ <code >Promise</code >
83
- Remove an user from an organization, only an admin user can remove an user from an organization
84
-
85
- ** Returns** : <code >Promise</code > - A promise that returns the call response object, or an Error if rejected.
86
-
87
- | Param | Type | Description |
88
- | --- | --- | --- |
89
- | userId | <code >string</code > | The if of the user to be removed. |
90
- | [ orgName] | <code >string</code > | The organization name in which the user is to be removed. |
91
-
92
-
93
98
### getPendingOrgInvites
94
99
#### accessControl.getPendingOrgInvites([ orgName] ) ⇒ <code >Promise</code >
95
100
Get the pending invitations list.
@@ -100,6 +105,21 @@ Get the pending invitations list.
100
105
| --- | --- | --- |
101
106
| [ orgName] | <code >string</code > | The organization name. |
102
107
108
+ ** Example**
109
+ ``` js
110
+ const invitationList = accessControl .getPendingOrgInvites ().then (result => {
111
+ console .log (invitationList)
112
+
113
+ })
114
+ // this will return an array of invitations object like this
115
+ // [{@id: "Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9c0dfc2ac51161ef5ba7cb0988d992c4bce82b3fa5d25"
116
+ // @type: "Invitation"
117
+ // creation_date: "2021-10-22T11:13:28.762Z"
118
+
119
+ // invited_by: "User/auth0%7C6162f8ab33567406a6bee0c"
120
+ // role: "Role/dataReader"
121
+ // status: "needs_invite"}]
122
+ ```
103
123
104
124
### sendOrgInvite
105
125
#### accessControl.sendOrgInvite(userEmail, role, [ note] , [ orgName] ) ⇒ <code >Promise</code >
@@ -110,10 +130,16 @@ Send a new invitation
110
130
| Param | Type | Description |
111
131
| --- | --- | --- |
112
132
| userEmail | <code >string</code > | The email of user. |
113
- | role | <code >string</code > | The role for user. |
133
+ | role | <code >string</code > | The role for user. (the document @ id role like Role/collaborator) |
114
134
| [ note] | <code >string</code > | The note to send with the invitation. |
115
135
| [ orgName] | <code >string</code > | The organization name. |
116
136
137
+ ** Example**
138
+ ``` js
139
+ accessControl .
sendOrgInvite (
" [email protected] " ,
" Role/admin" ,
" please join my team" ).
then (
result => {
140
+ console .log (result)
141
+ })
142
+ ```
117
143
118
144
### getOrgInvite
119
145
#### accessControl.getOrgInvite(inviteId, [ orgName] ) ⇒ <code >Promise</code >
@@ -126,6 +152,13 @@ Get the invitation info
126
152
| inviteId | <code >string</code > | The invite id to retrieve. |
127
153
| [ orgName] | <code >string</code > | The organization name. |
128
154
155
+ ** Example**
156
+ ``` js
157
+ const fullInviteId = " Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9c0dfc2ac51161ef5ba7cb0988d992c4bce82b3fa5d25"
158
+ accessControl .getOrgInvite (fullInviteId).then (result => {
159
+ console .log (result)
160
+ })
161
+ ```
129
162
130
163
### deleteOrgInvite
131
164
#### accessControl.deleteOrgInvite(inviteId, [ orgName] ) ⇒ <code >Promise</code >
@@ -138,10 +171,20 @@ Delete an invitation
138
171
| inviteId | <code >string</code > | The invite id to delete. |
139
172
| [ orgName] | <code >string</code > | The organization name. |
140
173
174
+ ** Example**
175
+ ``` js
176
+ const fullInviteId = " Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9c0dfc2ac51161ef5ba7cb0988d992c4bce82b3fa5d25"
177
+ accessControl .deleteOrgInvite (fullInviteId).then (result => {
178
+ console .log (result)
179
+ })
180
+ ```
141
181
142
182
### updateOrgInviteStatus
143
183
#### accessControl.updateOrgInviteStatus(inviteId, accepted, [ orgName] ) ⇒ <code >Promise</code >
144
- Accept /Reject invitation
184
+ Accept /Reject invitation. if the invitation has been accepted we add the current user to the organization.
185
+
186
+ the only user that can accept this invitation is the user registered with the invitation email,
187
+ we indentify the user with the jwt token
145
188
146
189
** Returns** : <code >Promise</code > - A promise that returns the call response object, or an Error if rejected.
147
190
@@ -151,6 +194,13 @@ Accept /Reject invitation
151
194
| accepted | <code >boolean</code > | The status of the invitation. |
152
195
| [ orgName] | <code >string</code > | The organization name. |
153
196
197
+ ** Example**
198
+ ``` js
199
+ const fullInviteId = " Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9c0dfc2ac51161ef5ba7cb0988d992c4bce82b3fa5d25"
200
+ accessControl .updateOrgInviteStatus (fullInviteId,true ).then (result => {
201
+ console .log (result)
202
+ })
203
+ ```
154
204
155
205
### getOrgUsers
156
206
#### accessControl.getOrgUsers([ orgName] ) ⇒ <code >Promise</code >
@@ -162,6 +212,38 @@ Get all the organization's users and roles
162
212
| --- | --- | --- |
163
213
| [ orgName] | <code >string</code > | The organization name. |
164
214
215
+ ** Example**
216
+ ``` js
217
+ accessControl .getOrgUsers ().then (result => {
218
+ console .log (result)
219
+ })
220
+
221
+ // this function will return an array of capabilities with users and roles
222
+ // [{capability: "Capability/3ea26e1d698821c570afe9cb4fe81a3......"
223
+ // email: {@type: "xsd:string", @value: "[email protected] "}
224
+ // picture: {@type: "xsd:string",…}
225
+ // role: "Role/dataReader"
226
+ // scope: "Organization/my_org_name"
227
+ // user: "User/auth0%7C613f5dnndjdjkTTT"}]
228
+ ```
229
+
230
+ ### removeUserFromOrg
231
+ #### accessControl.removeUserFromOrg(userId, [ orgName] ) ⇒ <code >Promise</code >
232
+ Remove an user from an organization, only an admin user can remove an user from an organization
233
+
234
+ ** Returns** : <code >Promise</code > - A promise that returns the call response object, or an Error if rejected.
235
+
236
+ | Param | Type | Description |
237
+ | --- | --- | --- |
238
+ | userId | <code >string</code > | The id of the user to be removed. (this is the document user's @id ) |
239
+ | [ orgName] | <code >string</code > | The organization name in which the user is to be removed. |
240
+
241
+ ** Example**
242
+ ``` js
243
+ accessControl .removeUserFromOrg (" User/auth0%7C613f5dnndjdjkTTT" ," my_org_name" ).then (result => {
244
+ console .log (result)
245
+ })
246
+ ```
165
247
166
248
### getDatabaseRolesOfUser
167
249
#### accessControl.getDatabaseRolesOfUser(userId, [ orgName] ) ⇒ <code >Promise</code >
@@ -174,10 +256,31 @@ Get the user's role for every databases under the organization
174
256
| userId | <code >string</code > | The user's id. |
175
257
| [ orgName] | <code >string</code > | The organization name. |
176
258
177
-
178
- ### assignUserRole
179
- #### accessControl.assignUserRole(userId, scope, role, [ orgName] ) ⇒ <code >Promise</code >
180
- Assign user's a role for a resource (organization/database)
259
+ ** Example**
260
+ ``` js
261
+ accessControl .getDatabaseRolesOfUser (' User/auth0%7C61790e366377Yu6596a' ).then (result => {
262
+ console .log (result)
263
+ })
264
+
265
+ // this is a capabilities list of databases and roles
266
+ // [ {capability: "Capability/b395e8523d509dec6b33aefc9baed3b2e2bfadbd4c79d4ff9b20dce2b14e2edc"
267
+ // if there is an id we have a user specific capabality for this database
268
+ // name: {@type: "xsd:string", @value: "profiles_test"}
269
+ // role: "Role/dataUpdater"
270
+ // scope: "UserDatabase/7ebdfae5a02bc7e8f6d79sjjjsa4e179b1df9d4576a3b1d2e5ff3b4859"
271
+ // user: "User/auth0%7C61790e11a3966d006906596a"},
272
+
273
+ // { capability: null
274
+ // if the capability id is null the user level of access for this database is the same of the team
275
+ // name: {@type: "xsd:string", @value: "Collab002"}
276
+ // role: "Role/dataReader"
277
+ // scope: "UserDatabase/acfcc2db02b83792sssb15239ccdf586fc5b176846ffe4878b1aea6a36c8f"
278
+ // user: "User/auth0%7C61790e11a3966d006906596a"}]
279
+ ```
280
+
281
+ ### createUserRole
282
+ #### accessControl.createUserRole(userId, scope, role, [ orgName] ) ⇒ <code >Promise</code >
283
+ Create a user's a role for a resource (organization/database)
181
284
182
285
** Returns** : <code >Promise</code > - A promise that returns the call response object, or an Error if rejected.
183
286
@@ -188,6 +291,14 @@ Assign user's a role for a resource (organization/database)
188
291
| role | <code >string</code > | The user role to be assigned. |
189
292
| [ orgName] | <code >string</code > | The organization name. |
190
293
294
+ ** Example**
295
+ ``` js
296
+ const dbId = " UserDatabase/acfcc2db02b83792sssb15239ccdf586fc5b176846ffe4878b1aea6a36c8f"
297
+ accessControl .assignUserRole (' User/auth0%7C61790e11a3966d006906596a' ,dbId," Role/collaborator" ).then (result => {
298
+ console .log (result)
299
+
300
+ })
301
+ ```
191
302
192
303
### updateUserRole
193
304
#### accessControl.updateUserRole(userId, capabilityId, scope, role, [ orgName] ) ⇒ <code >Promise</code >
@@ -203,3 +314,12 @@ Update user's a role for a resource (organization/database)
203
314
| role | <code >string</code > | The user role to be updated. |
204
315
| [ orgName] | <code >string</code > | The organization name. |
205
316
317
+ ** Example**
318
+ ``` js
319
+ const dbId = " UserDatabase/acfcc2db02b83792sssb15239ccdf586fc5b176846ffe4878b1aea6a36c8f"
320
+ const capId = " Capability/b395e8523d509dec6b33aefc9baed3b2e2bfadbd4c79d4ff9b20dce2b14e2edc"
321
+ accessControl .updateUserRole (' User/auth0%7C61790e11a3966d006906596a' ,capId,dbId," Role/dataUpdater" ).then (result => {
322
+ console .log (result)
323
+
324
+ })
325
+ ```
0 commit comments