Skip to content

Commit

Permalink
Merge pull request #96 from permitio/gidi/per-10797-support-create-us…
Browse files Browse the repository at this point in the history
…er-assign-role-in-node-sdk

add create user + roles assignment support
  • Loading branch information
gideonsmila authored Oct 8, 2024
2 parents 6b9962a + 8730af5 commit b690693
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/openapi/types/elements-user-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Do not edit the class manually.
*/

import { UserRoleCreate } from './user-role-create';

/**
*
* @export
Expand Down Expand Up @@ -48,6 +50,12 @@ export interface ElementsUserCreate {
* @memberof ElementsUserCreate
*/
attributes?: object;
/**
* List of roles to assign to the user in the environment.
* @type {UserRoleCreate[]}
* @memberof ElementsUserCreate
*/
role_assignments?: UserRoleCreate[];
/**
*
* @type {string}
Expand Down
8 changes: 8 additions & 0 deletions src/openapi/types/user-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Do not edit the class manually.
*/

import { UserRoleCreate } from './user-role-create';

/**
*
* @export
Expand Down Expand Up @@ -48,4 +50,10 @@ export interface UserCreate {
* @memberof UserCreate
*/
attributes?: object;
/**
* List of roles to assign to the user in the environment.
* @type {UserRoleCreate[]}
* @memberof UserCreate
*/
role_assignments?: UserRoleCreate[];
}
22 changes: 22 additions & 0 deletions src/tests/e2e/rbac.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import anyTest, { TestInterface } from 'ava';
import { UserCreate, UserRead } from '../../openapi';

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

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

// create a user
const newUser: UserRead = await permit.api.users.create({
key: 'auth0|james',
email: 'james@undos.com',
first_name: 'James',
last_name: 'Undos',
attributes: {
age: 50,
favoriteColor: 'red',
},
role_assignments: [
{
role: viewer.key,
tenant: tenant.key,
},
],
});

t.is(newUser.roles![0].role, viewer.key);

logger.info(
`sleeping ${sleepTimeMs} ms before permit.check() to make sure all writes propagated from cloud to PDP`,
);
Expand Down Expand Up @@ -241,6 +262,7 @@ test('Permission check e2e test', async (t) => {
// cleanup
try {
await permit.api.users.delete('auth0|elon');
await permit.api.users.delete('auth0|james');
await permit.api.tenants.delete('tesla');
await permit.api.roles.delete('admin');
await permit.api.roles.delete('viewer');
Expand Down

0 comments on commit b690693

Please sign in to comment.