Skip to content

Commit 38e5388

Browse files
committed
review access control
1 parent 6ff459d commit 38e5388

File tree

5 files changed

+203
-68
lines changed

5 files changed

+203
-68
lines changed

docs/_sidebar.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@
159159
- [first_commit](api/woqlLibrary.js?id=first_commit)
160160
- [AccessControl](api/accessControl.js?id=AccessControl)
161161
- [getDefaultOrganization](api/accessControl.js?id=getDefaultOrganization)
162-
- [getAPIToken](api/accessControl.js?id=getAPIToken)
163-
- [setAPIToken](api/accessControl.js?id=setAPIToken)
162+
- [getJwtToken](api/accessControl.js?id=getJwtToken)
163+
- [setJwtToken](api/accessControl.js?id=setJwtToken)
164164
- [getAPIUrl](api/accessControl.js?id=getAPIUrl)
165-
- [getUserRoles](api/accessControl.js?id=getUserRoles)
165+
- [getAccessRoles](api/accessControl.js?id=getAccessRoles)
166166
- [createOrganization](api/accessControl.js?id=createOrganization)
167167
- [ifOrganizationExists](api/accessControl.js?id=ifOrganizationExists)
168-
- [removeUserFromOrg](api/accessControl.js?id=removeUserFromOrg)
169168
- [getPendingOrgInvites](api/accessControl.js?id=getPendingOrgInvites)
170169
- [sendOrgInvite](api/accessControl.js?id=sendOrgInvite)
171170
- [getOrgInvite](api/accessControl.js?id=getOrgInvite)
172171
- [deleteOrgInvite](api/accessControl.js?id=deleteOrgInvite)
173172
- [updateOrgInviteStatus](api/accessControl.js?id=updateOrgInviteStatus)
174173
- [getOrgUsers](api/accessControl.js?id=getOrgUsers)
174+
- [removeUserFromOrg](api/accessControl.js?id=removeUserFromOrg)
175175
- [getDatabaseRolesOfUser](api/accessControl.js?id=getDatabaseRolesOfUser)
176-
- [assignUserRole](api/accessControl.js?id=assignUserRole)
176+
- [createUserRole](api/accessControl.js?id=createUserRole)
177177
- [updateUserRole](api/accessControl.js?id=updateUserRole)
178178
- [TypeDef](api/typedef.js?id=TypeDef)
179179
- [DocParamsGet](api/typedef.js?id=DocParamsGet)

docs/api/accessControl.js.md

Lines changed: 148 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
#### new AccessControl()
77
The AccessControl object has various methods to control the access for users.
88

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+
```
920

1021
### getDefaultOrganization
1122
#### accessControl.getDefaultOrganization(params) ⇒ <code>string</code> \| <code>undefined</code>
@@ -18,25 +29,25 @@ Get a organization from parameters.
1829
| params | <code>object</code> | The parameters |
1930

2031

21-
### getAPIToken
22-
#### accessControl.getAPIToken(params) ⇒ <code>string</code>
32+
### getJwtToken
33+
#### accessControl.getJwtToken(params) ⇒ <code>string</code>
2334
Get a API token from parameters.
2435

25-
**Returns**: <code>string</code> - apiToken
36+
**Returns**: <code>string</code> - jwt api token
2637

2738
| Param | Type | Description |
2839
| --- | --- | --- |
2940
| params | <code>object</code> | The parameters |
3041

3142

32-
### setAPIToken
33-
#### accessControl.setAPIToken(token)
43+
### setJwtToken
44+
#### accessControl.setJwtToken(jwt)
3445
Sets the API token for the object
3546

3647

3748
| Param | Type | Description |
3849
| --- | --- | --- |
39-
| token | <code>string</code> | The api token to use |
50+
| jwt | <code>string</code> | The jwt api token to use |
4051

4152

4253
### getAPIUrl
@@ -50,8 +61,8 @@ Get a API url from cloudAPIUrl
5061
| cloudAPIUrl | <code>string</code> | The base url for cloud |
5162

5263

53-
### getUserRoles
54-
#### accessControl.getUserRoles() ⇒ <code>Promise</code>
64+
### getAccessRoles
65+
#### accessControl.getAccessRoles() ⇒ <code>Promise</code>
5566
Get all the system database roles types.
5667

5768
**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.
6677
| --- | --- | --- |
6778
| orgName | <code>string</code> | The organization name to create |
6879

80+
**Example**
81+
```js
82+
accessControl.createOrganization("my_org_name").then(result=>{
83+
console.log(result)
84+
})
85+
```
6986

7087
### ifOrganizationExists
7188
#### accessControl.ifOrganizationExists(orgName) ⇒ <code>Promise</code>
72-
Check if the organization exists.
89+
Check if the organization exists. it is a Head call .
7390

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
7592

7693
| Param | Type | Description |
7794
| --- | --- | --- |
7895
| orgName | <code>string</code> | The organization name to check if exists. |
7996

8097

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-
9398
### getPendingOrgInvites
9499
#### accessControl.getPendingOrgInvites([orgName]) ⇒ <code>Promise</code>
95100
Get the pending invitations list.
@@ -100,6 +105,21 @@ Get the pending invitations list.
100105
| --- | --- | --- |
101106
| [orgName] | <code>string</code> | The organization name. |
102107

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+
// email_to: "[email protected]"
119+
// invited_by: "User/auth0%7C6162f8ab33567406a6bee0c"
120+
// role: "Role/dataReader"
121+
// status: "needs_invite"}]
122+
```
103123

104124
### sendOrgInvite
105125
#### accessControl.sendOrgInvite(userEmail, role, [note], [orgName]) ⇒ <code>Promise</code>
@@ -110,10 +130,16 @@ Send a new invitation
110130
| Param | Type | Description |
111131
| --- | --- | --- |
112132
| 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) |
114134
| [note] | <code>string</code> | The note to send with the invitation. |
115135
| [orgName] | <code>string</code> | The organization name. |
116136

137+
**Example**
138+
```js
139+
accessControl.sendOrgInvite("[email protected]","Role/admin","please join my team").then(result=>{
140+
console.log(result)
141+
})
142+
```
117143

118144
### getOrgInvite
119145
#### accessControl.getOrgInvite(inviteId, [orgName]) ⇒ <code>Promise</code>
@@ -126,6 +152,13 @@ Get the invitation info
126152
| inviteId | <code>string</code> | The invite id to retrieve. |
127153
| [orgName] | <code>string</code> | The organization name. |
128154

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+
```
129162

130163
### deleteOrgInvite
131164
#### accessControl.deleteOrgInvite(inviteId, [orgName]) ⇒ <code>Promise</code>
@@ -138,10 +171,20 @@ Delete an invitation
138171
| inviteId | <code>string</code> | The invite id to delete. |
139172
| [orgName] | <code>string</code> | The organization name. |
140173

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+
```
141181

142182
### updateOrgInviteStatus
143183
#### 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
145188

146189
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
147190

@@ -151,6 +194,13 @@ Accept /Reject invitation
151194
| accepted | <code>boolean</code> | The status of the invitation. |
152195
| [orgName] | <code>string</code> | The organization name. |
153196

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+
```
154204

155205
### getOrgUsers
156206
#### accessControl.getOrgUsers([orgName]) ⇒ <code>Promise</code>
@@ -162,6 +212,38 @@ Get all the organization's users and roles
162212
| --- | --- | --- |
163213
| [orgName] | <code>string</code> | The organization name. |
164214

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+
```
165247

166248
### getDatabaseRolesOfUser
167249
#### accessControl.getDatabaseRolesOfUser(userId, [orgName]) ⇒ <code>Promise</code>
@@ -174,10 +256,31 @@ Get the user's role for every databases under the organization
174256
| userId | <code>string</code> | The user's id. |
175257
| [orgName] | <code>string</code> | The organization name. |
176258

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)
181284

182285
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
183286

@@ -188,6 +291,14 @@ Assign user's a role for a resource (organization/database)
188291
| role | <code>string</code> | The user role to be assigned. |
189292
| [orgName] | <code>string</code> | The organization name. |
190293

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+
```
191302

192303
### updateUserRole
193304
#### accessControl.updateUserRole(userId, capabilityId, scope, role, [orgName]) ⇒ <code>Promise</code>
@@ -203,3 +314,12 @@ Update user's a role for a resource (organization/database)
203314
| role | <code>string</code> | The user role to be updated. |
204315
| [orgName] | <code>string</code> | The organization name. |
205316

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

Comments
 (0)