Skip to content

Commit

Permalink
Merge pull request #3929 from novuhq/disable-role-toggle
Browse files Browse the repository at this point in the history
feat: disable role toggle
  • Loading branch information
djabarovgeorge committed Aug 6, 2023
2 parents 9591a21 + aaed410 commit baec93c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('Change member role - /organizations/members/:memberId/role (PUT)', asy
});
});

it('should update admin to member', async () => {
// Currently skipped until we implement role management
it.skip('should update admin to member', async () => {
await memberRepository.addMember(session.organization._id, {
_userId: user2.user._id,
invite: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ export class ChangeMemberRole {
constructor(private organizationRepository: OrganizationRepository, private memberRepository: MemberRepository) {}

async execute(command: ChangeMemberRoleCommand) {
if (![MemberRoleEnum.MEMBER, MemberRoleEnum.ADMIN].includes(command.role)) {
throw new ApiException('Not supported role type');
}

if (command.role !== MemberRoleEnum.ADMIN) {
throw new ApiException(`The change of role to an ${command.role} type is not supported`);
}

const organization = await this.organizationRepository.findById(command.organizationId);
if (!organization) throw new NotFoundException('No organization was found');

const member = await this.memberRepository.findMemberById(organization._id, command.memberId);
if (!member) throw new ApiException('No member was found');

if (![MemberRoleEnum.MEMBER, MemberRoleEnum.ADMIN].includes(command.role)) {
throw new ApiException('Not supported role type');
}
if (!member) throw new NotFoundException('No member was found');

const roles = [command.role];

Expand Down
10 changes: 7 additions & 3 deletions apps/web/src/pages/invites/components/MemberRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from '@emotion/styled';

import { Dropdown, Tag } from '../../../design-system';

export function MemberRole({ member, onChangeMemberRole, isEnableMemberActions }) {
export function MemberRole({ member, onChangeMemberRole, isEnableMemberActions, allowChangeRole = false }) {
const TagElement = () => {
return <>{member.roles.find((role: string) => role === 'admin') ? <Tag>Admin</Tag> : <Tag>Member</Tag>}</>;
};
Expand All @@ -25,9 +25,13 @@ export function MemberRole({ member, onChangeMemberRole, isEnableMemberActions }
<>
<Dropdown
control={
<ClickableTag data-test-id="change-member-role-btn">
allowChangeRole ? (
<ClickableTag data-test-id="change-member-role-btn">
<TagElement />
</ClickableTag>
) : (
<TagElement />
</ClickableTag>
)
}
>
{availableRoles().map((role, index: number) => (
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/pages/invites/components/MembersTable.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe('MembersTable Component', function () {
currentUser={{ _id: 1 }}
onRemoveMember={onRemoveMember}
onChangeMemberRole={onChangeMemberRole}
allowChangeRole={true}
/>
</TestWrapper>
);
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/pages/invites/components/MembersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function MembersTable({
loading = false,
onResendInviteMember,
onChangeMemberRole,
allowChangeRole = false,
}) {
const { classes, theme } = useStyles();
const clipboardInviteLink = useClipboard({ timeout: 1000 });
Expand Down Expand Up @@ -77,6 +78,7 @@ export function MembersTable({
onChangeMemberRole={onChangeMemberRole}
member={member}
isEnableMemberActions={isEnableMemberActions}
allowChangeRole={allowChangeRole}
/>
</div>
</ActionsSider>
Expand Down

0 comments on commit baec93c

Please sign in to comment.