Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rbac): role overview #972

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/rbac-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export type UpdatePolicy = {
oldPolicy: Policy;
newPolicy: Policy;
};

export type PermissionPolicy = {
pluginId?: string;
policies?: Policy[];
};
107 changes: 32 additions & 75 deletions plugins/rbac/dev/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ import {
} from '@backstage/plugin-permission-react';
import { TestApiProvider } from '@backstage/test-utils';

import { Role, RoleBasedPolicy } from '@janus-idp/backstage-plugin-rbac-common';
import {
PermissionPolicy,
Policy,
Role,
RoleBasedPolicy,
} from '@janus-idp/backstage-plugin-rbac-common';

import { mockMembers } from '../src/__fixtures__/mockMembers';
import { mockPermissionPolicies } from '../src/__fixtures__/mockPermissionPolicies';
import { mockPolicies } from '../src/__fixtures__/mockPolicies';
import { RBACAPI, rbacApiRef } from '../src/api/RBACBackendClient';
import { RbacPage, rbacPlugin } from '../src/plugin';
import { MemberEntity } from '../src/types';

class MockPermissionApi implements PermissionApi {
readonly result;
Expand All @@ -34,80 +43,7 @@ class MockRBACApi implements RBACAPI {
return this.resources;
}
async getPolicies(): Promise<RoleBasedPolicy[]> {
return [
{
entityReference: 'role:default/guests',
permission: 'catalog-entity',
policy: 'read',
effect: 'deny',
},
{
entityReference: 'role:default/guests',
permission: 'catalog.entity.create',
policy: 'use',
effect: 'deny',
},
{
entityReference: 'role:default/guests',
permission: 'catalog-entity',
policy: 'read',
effect: 'allow',
},
{
entityReference: 'role:default/guests',
permission: 'catalog.entity.create',
policy: 'use',
effect: 'allow',
},
{
entityReference: 'role:default/guests',
permission: 'policy-entity',
policy: 'create',
effect: 'allow',
},
{
entityReference: 'role:default/guests',
permission: 'policy-entity',
policy: 'read',
effect: 'allow',
},
{
entityReference: 'role:default/guests',
permission: 'policy.entity.read',
policy: 'use',
effect: 'allow',
},
{
entityReference: 'role:default/guests',
permission: 'policy-entity',
policy: 'delete',
effect: 'allow',
},
{
entityReference: 'role:default/rbac_admin',
permission: 'policy-entity',
policy: 'read',
effect: 'allow',
},
{
entityReference: 'role:default/rbac_admin',
permission: 'policy-entity',
policy: 'create',
effect: 'allow',
},
{
entityReference: 'role:default/rbac_admin',
permission: 'policy-entity',
policy: 'delete',
effect: 'allow',
},
{
entityReference: 'role:default/rbac_admin',
permission: 'policy-entity',
policy: 'update',
effect: 'allow',
},
];
return mockPolicies;
}

async getUserAuthorization(): Promise<{ status: string }> {
Expand All @@ -116,9 +52,30 @@ class MockRBACApi implements RBACAPI {
};
}

async getRole(role: string): Promise<Role[]> {
const roleresource = this.resources.find(res => res.name === role);
return roleresource ? [roleresource] : [];
}

async deleteRole(_roleName: string): Promise<any> {
return { status: 204 };
}

async getMembers(): Promise<MemberEntity[]> {
return mockMembers;
}

async listPermissions(): Promise<PermissionPolicy[]> {
return mockPermissionPolicies;
}

async deletePolicy(
_entityRef: string,
_permission: string,
_policies: Policy[],
): Promise<number> {
return 204;
}
}

const mockPermissionApi = new MockPermissionApi({ result: 'ALLOW' });
Expand Down
8 changes: 6 additions & 2 deletions plugins/rbac/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@backstage/catalog-model": "^1.4.3",
"@backstage/core-components": "^0.13.6",
"@backstage/core-plugin-api": "^1.7.0",
"@backstage/plugin-catalog": "^1.15.1",
"@backstage/plugin-permission-react": "^0.4.16",
"@backstage/theme": "^0.4.3",
"@janus-idp/backstage-plugin-rbac-common": "1.1.0",
Expand All @@ -36,10 +37,12 @@
"@material-ui/lab": "^4.0.0-alpha.45",
"@mui/icons-material": "5.14.11",
"@mui/material": "^5.14.18",
"react-use": "^17.4.0"
"react-use": "^17.4.0",
"lodash": "^4.17.21"
},
"peerDependencies": {
"react": "^16.13.1 || ^17.0.0"
"react": "^16.13.1 || ^17.0.0",
"react-router-dom": "^6.20.0"
},
"devDependencies": {
"@backstage/cli": "0.23.0",
Expand All @@ -49,6 +52,7 @@
"@janus-idp/cli": "1.4.6",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "12.1.5",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/user-event": "14.5.1",
"@types/node": "18.18.5",
"msw": "1.3.2"
Expand Down
Loading