Skip to content

Commit

Permalink
fix room create permission
Browse files Browse the repository at this point in the history
  • Loading branch information
uidp committed Dec 16, 2024
1 parent ad830cd commit 369f3cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/modules/feature/room/roomAuthorization.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export const useRoomAuthorization = (
const permissions = toValue(room)?.permissions ?? [];

canCreateRoom.value =
permissions.includes(Permission.RoomEdit) &&
authModule.getUserRoles.includes(Roles.Teacher);
authModule.getUserPermissions.includes(
Permission.RoomCreate.toLowerCase()
) && authModule.getUserRoles.includes(Roles.Teacher);
canViewRoom.value = permissions.includes(Permission.RoomView);
canEditRoom.value = permissions.includes(Permission.RoomEdit);
canDeleteRoom.value = permissions.includes(Permission.RoomDelete);
Expand Down
10 changes: 8 additions & 2 deletions src/modules/feature/room/roomAuthorization.composable.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ import { createModuleMocks } from "@@/tests/test-utils/mock-store-module";
import { ref } from "vue";
import { useRoomAuthorization } from "./roomAuthorization.composable";

type setupParams = { userRoles?: Roles[]; roomPermissions?: Permission[] };
type setupParams = {
userRoles?: Roles[];
userPermissions?: Permission[];
roomPermissions?: Permission[];
};

describe("roomAuthorization", () => {
const genericSetup = ({
userRoles = [],
userPermissions = [],
roomPermissions = [],
}: setupParams) => {
const room = ref<RoomDetails>(
roomFactory.build({ permissions: roomPermissions })
);
const authModuleMock = createModuleMocks(AuthModule, {
getUserRoles: userRoles,
getUserPermissions: userPermissions,
});
return mountComposable(() => useRoomAuthorization(room), {
global: { provide: { [AUTH_MODULE_KEY]: authModuleMock } },
Expand All @@ -34,7 +40,7 @@ describe("roomAuthorization", () => {
const setup = () => {
return genericSetup({
userRoles: [Roles.Teacher],
roomPermissions: [Permission.RoomEdit],
userPermissions: [Permission.RoomCreate],
});
};

Expand Down

0 comments on commit 369f3cf

Please sign in to comment.