|
| 1 | + |
| 2 | +## AccessControl |
| 3 | +#### AccessControl |
| 4 | +**License**: Apache Version 2 |
| 5 | + |
| 6 | +#### new AccessControl() |
| 7 | +The AccessControl object has various methods to control the access for users. |
| 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 | +``` |
| 20 | + |
| 21 | +### getDefaultOrganization |
| 22 | +#### accessControl.getDefaultOrganization(params) ⇒ <code>string</code> \| <code>undefined</code> |
| 23 | +Get a organization from parameters. |
| 24 | + |
| 25 | +**Returns**: <code>string</code> \| <code>undefined</code> - - organization |
| 26 | + |
| 27 | +| Param | Type | Description | |
| 28 | +| --- | --- | --- | |
| 29 | +| params | <code>object</code> | The parameters | |
| 30 | + |
| 31 | + |
| 32 | +### getJwtToken |
| 33 | +#### accessControl.getJwtToken(params) ⇒ <code>string</code> |
| 34 | +Get a API token from parameters. |
| 35 | + |
| 36 | +**Returns**: <code>string</code> - jwt api token |
| 37 | + |
| 38 | +| Param | Type | Description | |
| 39 | +| --- | --- | --- | |
| 40 | +| params | <code>object</code> | The parameters | |
| 41 | + |
| 42 | + |
| 43 | +### setJwtToken |
| 44 | +#### accessControl.setJwtToken(jwt) |
| 45 | +Sets the API token for the object |
| 46 | + |
| 47 | + |
| 48 | +| Param | Type | Description | |
| 49 | +| --- | --- | --- | |
| 50 | +| jwt | <code>string</code> | The jwt api token to use | |
| 51 | + |
| 52 | + |
| 53 | +### getAPIUrl |
| 54 | +#### accessControl.getAPIUrl(cloudAPIUrl) ⇒ <code>string</code> |
| 55 | +Get a API url from cloudAPIUrl |
| 56 | + |
| 57 | +**Returns**: <code>string</code> - apiUrl |
| 58 | + |
| 59 | +| Param | Type | Description | |
| 60 | +| --- | --- | --- | |
| 61 | +| cloudAPIUrl | <code>string</code> | The base url for cloud | |
| 62 | + |
| 63 | + |
| 64 | +### getAccessRoles |
| 65 | +#### accessControl.getAccessRoles() ⇒ <code>Promise</code> |
| 66 | +Get all the system database roles types. |
| 67 | + |
| 68 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 69 | + |
| 70 | +### createOrganization |
| 71 | +#### accessControl.createOrganization(orgName) ⇒ <code>Promise</code> |
| 72 | +Any user can create their own organization. |
| 73 | + |
| 74 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 75 | + |
| 76 | +| Param | Type | Description | |
| 77 | +| --- | --- | --- | |
| 78 | +| orgName | <code>string</code> | The organization name to create | |
| 79 | + |
| 80 | +**Example** |
| 81 | +```js |
| 82 | +accessControl.createOrganization("my_org_name").then(result=>{ |
| 83 | + console.log(result) |
| 84 | +}) |
| 85 | +``` |
| 86 | + |
| 87 | +### ifOrganizationExists |
| 88 | +#### accessControl.ifOrganizationExists(orgName) ⇒ <code>Promise</code> |
| 89 | +Check if the organization exists. it is a Head call . |
| 90 | + |
| 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 |
| 92 | + |
| 93 | +| Param | Type | Description | |
| 94 | +| --- | --- | --- | |
| 95 | +| orgName | <code>string</code> | The organization name to check if exists. | |
| 96 | + |
| 97 | + |
| 98 | +### getPendingOrgInvites |
| 99 | +#### accessControl.getPendingOrgInvites([orgName]) ⇒ <code>Promise</code> |
| 100 | +Get the pending invitations list. |
| 101 | + |
| 102 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 103 | + |
| 104 | +| Param | Type | Description | |
| 105 | +| --- | --- | --- | |
| 106 | +| [orgName] | <code>string</code> | The organization name. | |
| 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 | +``` |
| 123 | + |
| 124 | +### sendOrgInvite |
| 125 | +#### accessControl.sendOrgInvite(userEmail, role, [note], [orgName]) ⇒ <code>Promise</code> |
| 126 | +Send a new invitation |
| 127 | + |
| 128 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 129 | + |
| 130 | +| Param | Type | Description | |
| 131 | +| --- | --- | --- | |
| 132 | +| userEmail | <code>string</code> | The email of user. | |
| 133 | +| role | <code>string</code> | The role for user. (the document @id role like Role/collaborator) | |
| 134 | +| [note] | <code>string</code> | The note to send with the invitation. | |
| 135 | +| [orgName] | <code>string</code> | The organization name. | |
| 136 | + |
| 137 | +**Example** |
| 138 | +```js |
| 139 | +accessControl. sendOrgInvite( "[email protected]", "Role/admin", "please join my team"). then( result=>{ |
| 140 | + console.log(result) |
| 141 | +}) |
| 142 | +``` |
| 143 | + |
| 144 | +### getOrgInvite |
| 145 | +#### accessControl.getOrgInvite(inviteId, [orgName]) ⇒ <code>Promise</code> |
| 146 | +Get the invitation info |
| 147 | + |
| 148 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 149 | + |
| 150 | +| Param | Type | Description | |
| 151 | +| --- | --- | --- | |
| 152 | +| inviteId | <code>string</code> | The invite id to retrieve. | |
| 153 | +| [orgName] | <code>string</code> | The organization name. | |
| 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 | +``` |
| 162 | + |
| 163 | +### deleteOrgInvite |
| 164 | +#### accessControl.deleteOrgInvite(inviteId, [orgName]) ⇒ <code>Promise</code> |
| 165 | +Delete an invitation |
| 166 | + |
| 167 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 168 | + |
| 169 | +| Param | Type | Description | |
| 170 | +| --- | --- | --- | |
| 171 | +| inviteId | <code>string</code> | The invite id to delete. | |
| 172 | +| [orgName] | <code>string</code> | The organization name. | |
| 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 | +``` |
| 181 | + |
| 182 | +### updateOrgInviteStatus |
| 183 | +#### accessControl.updateOrgInviteStatus(inviteId, accepted, [orgName]) ⇒ <code>Promise</code> |
| 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 |
| 188 | + |
| 189 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 190 | + |
| 191 | +| Param | Type | Description | |
| 192 | +| --- | --- | --- | |
| 193 | +| inviteId | <code>string</code> | The invite id to updated. | |
| 194 | +| accepted | <code>boolean</code> | The status of the invitation. | |
| 195 | +| [orgName] | <code>string</code> | The organization name. | |
| 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 | +``` |
| 204 | + |
| 205 | +### getOrgUsers |
| 206 | +#### accessControl.getOrgUsers([orgName]) ⇒ <code>Promise</code> |
| 207 | +Get all the organization's users and roles |
| 208 | + |
| 209 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 210 | + |
| 211 | +| Param | Type | Description | |
| 212 | +| --- | --- | --- | |
| 213 | +| [orgName] | <code>string</code> | The organization name. | |
| 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 | +``` |
| 247 | + |
| 248 | +### getDatabaseRolesOfUser |
| 249 | +#### accessControl.getDatabaseRolesOfUser(userId, [orgName]) ⇒ <code>Promise</code> |
| 250 | +Get the user's role for every databases under the organization |
| 251 | + |
| 252 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 253 | + |
| 254 | +| Param | Type | Description | |
| 255 | +| --- | --- | --- | |
| 256 | +| userId | <code>string</code> | The user's id. | |
| 257 | +| [orgName] | <code>string</code> | The organization name. | |
| 258 | + |
| 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) |
| 284 | + |
| 285 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 286 | + |
| 287 | +| Param | Type | Description | |
| 288 | +| --- | --- | --- | |
| 289 | +| userId | <code>string</code> | The user's id. | |
| 290 | +| scope | <code>string</code> | The resource name/id. | |
| 291 | +| role | <code>string</code> | The user role to be assigned. | |
| 292 | +| [orgName] | <code>string</code> | The organization name. | |
| 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 | +``` |
| 302 | + |
| 303 | +### updateUserRole |
| 304 | +#### accessControl.updateUserRole(userId, capabilityId, scope, role, [orgName]) ⇒ <code>Promise</code> |
| 305 | +Update user's a role for a resource (organization/database) |
| 306 | + |
| 307 | +**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected. |
| 308 | + |
| 309 | +| Param | Type | Description | |
| 310 | +| --- | --- | --- | |
| 311 | +| userId | <code>string</code> | The user's id. | |
| 312 | +| capabilityId | <code>string</code> | The capability id. | |
| 313 | +| scope | <code>string</code> | The resource name/id. | |
| 314 | +| role | <code>string</code> | The user role to be updated. | |
| 315 | +| [orgName] | <code>string</code> | The organization name. | |
| 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