Skip to content

Commit b690693

Browse files
authored
Merge pull request #96 from permitio/gidi/per-10797-support-create-user-assign-role-in-node-sdk
add create user + roles assignment support
2 parents 6b9962a + 8730af5 commit b690693

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/openapi/types/elements-user-create.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Do not edit the class manually.
1313
*/
1414

15+
import { UserRoleCreate } from './user-role-create';
16+
1517
/**
1618
*
1719
* @export
@@ -48,6 +50,12 @@ export interface ElementsUserCreate {
4850
* @memberof ElementsUserCreate
4951
*/
5052
attributes?: object;
53+
/**
54+
* List of roles to assign to the user in the environment.
55+
* @type {UserRoleCreate[]}
56+
* @memberof ElementsUserCreate
57+
*/
58+
role_assignments?: UserRoleCreate[];
5159
/**
5260
*
5361
* @type {string}

src/openapi/types/user-create.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Do not edit the class manually.
1313
*/
1414

15+
import { UserRoleCreate } from './user-role-create';
16+
1517
/**
1618
*
1719
* @export
@@ -48,4 +50,10 @@ export interface UserCreate {
4850
* @memberof UserCreate
4951
*/
5052
attributes?: object;
53+
/**
54+
* List of roles to assign to the user in the environment.
55+
* @type {UserRoleCreate[]}
56+
* @memberof UserCreate
57+
*/
58+
role_assignments?: UserRoleCreate[];
5159
}

src/tests/e2e/rbac.e2e.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import anyTest, { TestInterface } from 'ava';
2+
import { UserCreate, UserRead } from '../../openapi';
23

34
import { printBreak, provideTestExecutionContext, TestContext } from '../fixtures';
45

@@ -150,6 +151,26 @@ test('Permission check e2e test', async (t) => {
150151
t.is(ra.role, viewer.key);
151152
t.is(ra.tenant, tenant.key);
152153

154+
// create a user
155+
const newUser: UserRead = await permit.api.users.create({
156+
key: 'auth0|james',
157+
email: 'james@undos.com',
158+
first_name: 'James',
159+
last_name: 'Undos',
160+
attributes: {
161+
age: 50,
162+
favoriteColor: 'red',
163+
},
164+
role_assignments: [
165+
{
166+
role: viewer.key,
167+
tenant: tenant.key,
168+
},
169+
],
170+
});
171+
172+
t.is(newUser.roles![0].role, viewer.key);
173+
153174
logger.info(
154175
`sleeping ${sleepTimeMs} ms before permit.check() to make sure all writes propagated from cloud to PDP`,
155176
);
@@ -241,6 +262,7 @@ test('Permission check e2e test', async (t) => {
241262
// cleanup
242263
try {
243264
await permit.api.users.delete('auth0|elon');
265+
await permit.api.users.delete('auth0|james');
244266
await permit.api.tenants.delete('tesla');
245267
await permit.api.roles.delete('admin');
246268
await permit.api.roles.delete('viewer');

0 commit comments

Comments
 (0)