Fix #4643 UI : Support new roles schema (#4704)

This commit is contained in:
Sachin Chaurasiya 2022-05-04 20:34:24 +05:30 committed by GitHub
parent 5d97137039
commit 9f6da055f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 3 deletions

View File

@ -94,6 +94,19 @@ const mockUserData = {
href: 'http://localhost:8585/api/v1/roles/ce4df2a5-aaf5-4580-8556-254f42574aa7',
},
],
inheritedRoles: [
{
id: '3fa30148-72f6-4205-8cab-56696cc23440',
type: 'role',
name: 'DataConsumer',
fullyQualifiedName: 'DataConsumer',
description:
'Users with Data Consumer role use different data assets for their day to day work.',
displayName: 'Data Consumer',
deleted: false,
href: 'http://localhost:8585/api/v1/roles/3fa30148-72f6-4205-8cab-56696cc23440',
},
],
};
jest.mock('../common/avatar/Avatar', () => {
@ -261,4 +274,16 @@ describe('Test User Component', () => {
expect(mockObserve).toHaveBeenCalled();
});
it('Should render inherited roles', async () => {
const { container } = render(
<Users userData={mockUserData} {...mockProp} />,
{
wrapper: MemoryRouter,
}
);
const inheritedRoles = await findByTestId(container, 'inherited-roles');
expect(inheritedRoles).toBeInTheDocument();
});
});

View File

@ -495,6 +495,30 @@ const Users = ({
}
};
const getInheritedRolesComponent = () => {
if (userData.inheritedRoles?.length) {
return (
<Fragment>
<div className="tw-flex">
<h6 className="tw-heading tw-mb-3" data-testid="inherited-roles">
Inherited Roles
</h6>
</div>
<div className="tw-pb-4 tw-mb-4 tw-border-b">
{userData.inheritedRoles?.map((inheritedRole, i) => (
<div className="tw-mb-2 tw-flex tw-items-center tw-gap-2" key={i}>
<SVGIcons alt="icon" className="tw-w-4" icon={Icons.USERS} />
<span>{getEntityName(inheritedRole)}</span>
</div>
))}
</div>
</Fragment>
);
} else {
return null;
}
};
const fetchLeftPanel = () => {
return (
<div className="tw-pt-4" data-testid="left-panel">
@ -520,6 +544,7 @@ const Users = ({
</div>
{getTeamsComponent()}
{getRolesComponent()}
{getInheritedRolesComponent()}
</div>
);
};

View File

@ -157,6 +157,8 @@ const Appbar: React.FC = (): JSX.Element => {
const name = currentUser?.displayName || currentUser?.name || TERM_USER;
const roles = currentUser?.roles?.map((r) => r.displayName) || [];
const inheritedRoles =
currentUser?.inheritedRoles?.map((r) => r.displayName) || [];
currentUser?.isAdmin && roles.unshift(TERM_ADMIN);
@ -180,6 +182,17 @@ const Appbar: React.FC = (): JSX.Element => {
<hr className="tw-my-1.5" />
</div>
) : null}
{inheritedRoles.length > 0 ? (
<div>
<div className="tw-font-medium tw-text-xs">Inherited Roles</div>
{inheritedRoles.map((inheritedRole, i) => (
<p className="tw-text-grey-muted" key={i}>
{inheritedRole}
</p>
))}
<hr className="tw-my-1.5" />
</div>
) : null}
{teams.length > 0 ? (
<div>
<span className="tw-font-medium tw-text-xs">Teams</span>

View File

@ -21,7 +21,7 @@ export interface Role {
*/
changeDescription?: ChangeDescription;
/**
* If `true`, this role is set as default role and will be assigned to all users.
* If `true`, this role is set as default system role and will be inherited by all the users.
*/
defaultRole?: boolean;
/**

View File

@ -22,7 +22,8 @@ export interface Team {
*/
changeDescription?: ChangeDescription;
/**
* Roles to be assigned to all users that are part of this team.
* Default roles of a team. These roles will be inherited by all the users that are part of
* this team.
*/
defaultRoles?: EntityReference[];
/**
@ -124,7 +125,8 @@ export interface FieldChange {
}
/**
* Roles to be assigned to all users that are part of this team.
* Default roles of a team. These roles will be inherited by all the users that are part of
* this team.
*
* This schema defines the EntityReference type used for referencing an entity.
* EntityReference is used for capturing relationships from one entity to another. For

View File

@ -50,6 +50,11 @@ export interface User {
* Unique identifier that identifies a user entity instance.
*/
id: string;
/**
* Roles that a user is inheriting either as part of system default role or through
* membership in teams that have set team default roles.
*/
inheritedRoles?: EntityReference[];
/**
* When true indicates user is an administrator for the system with superuser privileges.
*/