Skip to content

Commit

Permalink
Merge branch 'main' into EW-1060
Browse files Browse the repository at this point in the history
  • Loading branch information
Fshmit committed Dec 11, 2024
2 parents 878ed26 + e152727 commit 5969f04
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/modules/data/board/BoardPermissions.composable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSharedComposable } from "@vueuse/core";
import { authModule } from "@/store";
import { BoardPermissionChecks } from "@/types/board/Permissions";
import { createSharedComposable } from "@vueuse/core";

const boardPermissions = (): BoardPermissionChecks => {
const permissions = authModule?.getUserPermissions || [];
Expand All @@ -10,6 +10,7 @@ const boardPermissions = (): BoardPermissionChecks => {
hasMovePermission: permissions.includes("course_create"),
hasCreateCardPermission: permissions.includes("course_create"),
hasCreateColumnPermission: permissions.includes("course_create"),
hasCreateToolPermission: permissions.includes("context_tool_admin"),
hasEditPermission: permissions.includes("course_edit"),
hasDeletePermission: permissions.includes("course_remove"),
isTeacher: userRoles.includes("teacher"),
Expand Down
34 changes: 23 additions & 11 deletions src/modules/feature/board/board/Board.unit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import CopyResultModal from "@/components/copy-result-modal/CopyResultModal.vue";
import { useApplicationError } from "@/composables/application-error.composable";
import { useCopy } from "@/composables/copy";
import {
ConfigResponse,
CopyApiResponse,
CopyApiResponseTypeEnum,
ShareTokenBodyParamsParentTypeEnum,
} from "@/serverApi/v3";
import { envConfigModule, applicationErrorModule } from "@/store";
import { applicationErrorModule, envConfigModule } from "@/store";
import ApplicationErrorModule from "@/store/application-error";
import CopyModule from "@/store/copy";
import CourseRoomDetailsModule from "@/store/course-room-details";
Expand All @@ -15,11 +16,13 @@ import LoadingStateModule from "@/store/loading-state";
import NotifierModule from "@/store/notifier";
import SchoolExternalToolsModule from "@/store/school-external-tools";
import ShareModule from "@/store/share";
import { HttpStatusCode } from "@/store/types/http-status-code.enum";
import { Board } from "@/types/board/Board";
import {
BoardPermissionChecks,
defaultPermissions,
} from "@/types/board/Permissions";
import { createApplicationError } from "@/utils/create-application-error.factory";
import {
COPY_MODULE_KEY,
COURSE_ROOM_DETAILS_MODULE_KEY,
Expand All @@ -28,14 +31,14 @@ import {
SCHOOL_EXTERNAL_TOOLS_MODULE_KEY,
SHARE_MODULE_KEY,
} from "@/utils/inject";
import { createModuleMocks } from "@@/tests/test-utils/mock-store-module";
import { mockedPiniaStoreTyping } from "@@/tests/test-utils";
import {
boardResponseFactory,
cardSkeletonResponseFactory,
columnResponseFactory,
envsFactory,
} from "@@/tests/test-utils/factory";
import { createModuleMocks } from "@@/tests/test-utils/mock-store-module";
import {
createTestingI18n,
createTestingVuetify,
Expand Down Expand Up @@ -63,9 +66,6 @@ import { Router, useRoute, useRouter } from "vue-router";
import BoardVue from "./Board.vue";
import BoardColumnVue from "./BoardColumn.vue";
import BoardHeaderVue from "./BoardHeader.vue";
import { useApplicationError } from "@/composables/application-error.composable";
import { HttpStatusCode } from "@/store/types/http-status-code.enum";
import { createApplicationError } from "@/utils/create-application-error.factory";

jest.mock("@util-board/BoardNotifier.composable");
const mockedUseBoardNotifier = jest.mocked(useBoardNotifier);
Expand Down Expand Up @@ -344,12 +344,6 @@ describe("Board", () => {
expect(wrapperVM.board).toStrictEqual(board);
});

it("should call cardStore loadPreferredTools action", () => {
const { cardStore } = setup();

expect(cardStore.loadPreferredTools).toHaveBeenCalled();
});

it("should be found in the dom", () => {
const { wrapper } = setup();

Expand Down Expand Up @@ -377,6 +371,24 @@ describe("Board", () => {
expect(boardHeaderComponent.props("title")).toBe(board.title);
});
});

describe("when the user has tool create permissions", () => {
it("should call cardStore loadPreferredTools action", () => {
mockedBoardPermissions.hasCreateToolPermission = true;
const { cardStore } = setup();

expect(cardStore.loadPreferredTools).toHaveBeenCalled();
});
});

describe("when the user does not have tool create permissions", () => {
it("should call cardStore loadPreferredTools action", () => {
mockedBoardPermissions.hasCreateToolPermission = false;
const { cardStore } = setup();

expect(cardStore.loadPreferredTools).not.toHaveBeenCalled();
});
});
});

describe("when component is unMounted", () => {
Expand Down
14 changes: 9 additions & 5 deletions src/modules/feature/board/board/Board.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@
<script setup lang="ts">
import CopyResultModal from "@/components/copy-result-modal/CopyResultModal.vue";
import ShareModal from "@/components/share/ShareModal.vue";
import { Breadcrumb } from "@/components/templates/default-wireframe.types";
import DefaultWireframe from "@/components/templates/DefaultWireframe.vue";
import { useApplicationError } from "@/composables/application-error.composable";
import { useCopy } from "@/composables/copy";
import { useLoadingState } from "@/composables/loadingState";
import {
BoardLayout,
ShareTokenBodyParamsParentTypeEnum,
ToolContextType,
} from "@/serverApi/v3";
import { applicationErrorModule } from "@/store";
import { CopyParamsTypeEnum } from "@/store/copy";
import { HttpStatusCode } from "@/store/types/http-status-code.enum";
import { ColumnMove } from "@/types/board/DragAndDrop";
import {
COPY_MODULE_KEY,
Expand Down Expand Up @@ -144,10 +148,6 @@ import { useBodyScrolling } from "../shared/BodyScrolling.composable";
import BoardColumn from "./BoardColumn.vue";
import BoardColumnGhost from "./BoardColumnGhost.vue";
import BoardHeader from "./BoardHeader.vue";
import { useApplicationError } from "@/composables/application-error.composable";
import { applicationErrorModule } from "@/store";
import { HttpStatusCode } from "@/store/types/http-status-code.enum";
import { Breadcrumb } from "@/components/templates/default-wireframe.types";
const props = defineProps({
boardId: { type: String, required: true },
Expand Down Expand Up @@ -189,6 +189,7 @@ const {
hasMovePermission,
hasCreateCardPermission,
hasCreateColumnPermission,
hasCreateToolPermission,
hasDeletePermission,
hasEditPermission,
isTeacher,
Expand Down Expand Up @@ -288,7 +289,10 @@ onMounted(() => {
setAlert();
useBoardInactivity();
boardStore.fetchBoardRequest({ boardId: props.boardId });
cardStore.loadPreferredTools(ToolContextType.BoardElement);
if (hasCreateToolPermission) {
cardStore.loadPreferredTools(ToolContextType.BoardElement);
}
});
onUnmounted(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/types/board/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type BoardPermissionChecks = {
hasMovePermission: boolean;
hasCreateCardPermission: boolean;
hasCreateColumnPermission: boolean;
hasCreateToolPermission: boolean;
hasEditPermission: boolean;
hasDeletePermission: boolean;
isTeacher: boolean;
Expand All @@ -12,6 +13,7 @@ export const defaultPermissions: BoardPermissionChecks = {
hasMovePermission: true,
hasCreateCardPermission: true,
hasCreateColumnPermission: true,
hasCreateToolPermission: true,
hasDeletePermission: true,
hasEditPermission: true,
isTeacher: true,
Expand Down

0 comments on commit 5969f04

Please sign in to comment.