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

N21-2151 Partial course sync #3430

Merged
merged 8 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,10 @@ export default {
"Die gewählte Nutzendengruppe wird im nächsten Schritt mit dem neu erstellten Kurs synchronisiert.",
"feature-course-sync.StartExistingCourseSyncDialog.text":
"Die gewählte Nutzendengruppe wird im nächsten Schritt mit dem ausgewählten Kurs synchronisiert.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.warning":
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userInGroupWarning":
"Eine Synchronisation mit {systemName} überschreibt die Personen des Kurses (Lehrkräfte und Schüler*innen).",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userNotInGroupWarning":
"Die Synchronisation des Kurses mit der gewählten Gruppe kann die Zuordnung der Schüler*innen verändern.<br/><br/>Die Zuordnung der Lehrkräfte bleibt in diesem Kurs davon unverändert.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.text":
"Soll die Synchronisation der Nutzendengruppe {groupName} im Kurs {courseName} wirklich gestartet werden?",
"feature-course-sync.StartExistingCourseSyncDialog.success":
Expand Down
4 changes: 3 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,10 @@ export default {
"In the next step, the selected user group will be synchronized with the newly created course.",
"feature-course-sync.StartExistingCourseSyncDialog.text":
"The selected user group will be synchronized with the selected course in the next step.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.warning":
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userInGroupWarning":
"A synchronization with {systemName} overwrites the members in the course (teachers and students).",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userNotInGroupWarning":
"The synchronization of the course with the selected group can change the assignment of the students.<br/><br/>The assignment of the teachers remains unchanged in this course.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.text":
"Should the synchronization of the user group {groupName} in the course {courseName} really be started?",
"feature-course-sync.StartExistingCourseSyncDialog.success":
Expand Down
4 changes: 3 additions & 1 deletion src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,10 @@ export default {
"En el siguiente paso, el grupo de usuarios seleccionado se sincronizará con el curso recién creado.",
"feature-course-sync.StartExistingCourseSyncDialog.text":
"El grupo de usuarios seleccionado se sincronizará con el curso seleccionado en el siguiente paso.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.warning":
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userInGroupWarning":
"Una sincronización con {systemName} sobrescribe a las personas del curso (profesores y estudiantes).",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userNotInGroupWarning":
"La sincronización del curso con el grupo seleccionado puede cambiar la asignación de los estudiantes.<br/><br/>La asignación de los profesores permanece sin cambios en este curso.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.text":
"¿Debería realmente iniciarse la sincronización del grupo de usuarios {groupName} en el curso {courseName}?",
"feature-course-sync.StartExistingCourseSyncDialog.success":
Expand Down
4 changes: 3 additions & 1 deletion src/locales/uk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,10 @@ export default {
"На наступному кроці вибрана група користувачів буде синхронізована з новоствореним курсом.",
"feature-course-sync.StartExistingCourseSyncDialog.text":
"Вибрана група користувачів буде синхронізована з вибраним курсом на наступному кроці.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.warning":
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userInGroupWarning":
"Синхронізація з {systemName} перезаписує людей у курсі (викладачі та студенти).",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userNotInGroupWarning":
"Синхронізація курсу з вибраною групою може змінити призначення студентів.<br/><br/>Призначення викладачів у цьому курсі залишається незмінним.",
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.text":
"Чи дійсно слід починати синхронізацію групи користувачів {groupName} у курсі {courseName}?",
"feature-course-sync.StartExistingCourseSyncDialog.success":
Expand Down
28 changes: 24 additions & 4 deletions src/modules/feature/course-sync/StartExistingCourseSyncDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
component="span"
:html="
$t(
'feature-course-sync.StartExistingCourseSyncDialog.confirmation.warning',
isUserInGroup
? 'feature-course-sync.StartExistingCourseSyncDialog.confirmation.userInGroupWarning'
: 'feature-course-sync.StartExistingCourseSyncDialog.confirmation.userNotInGroupWarning',
{
systemName: 'moin.schule',
}
Expand All @@ -49,12 +51,17 @@

<script setup lang="ts">
import VCustomDialog from "@/components/organisms/vCustomDialog.vue";
import { GroupResponse } from "@/serverApi/v3";
import { injectStrict, NOTIFIER_MODULE_KEY } from "@/utils/inject";
import { GroupResponse, GroupUserResponse, MeResponse } from "@/serverApi/v3";
import type AuthModule from "@/store/auth";
import {
AUTH_MODULE_KEY,
injectStrict,
NOTIFIER_MODULE_KEY,
} from "@/utils/inject";
import { useCourseApi } from "@data-room";
import { RenderHTML } from "@feature-render-html";
import { WarningAlert } from "@ui-alert";
import { ModelRef, Ref, ref } from "vue";
import { computed, ModelRef, Ref, ref } from "vue";
import { useI18n } from "vue-i18n";
import GroupSelectionDialog from "./GroupSelectionDialog.vue";

Expand Down Expand Up @@ -88,6 +95,19 @@ const onConfirmGroupSelection = async (group: GroupResponse) => {
};

const { startSynchronization } = useCourseApi();
const authModule: AuthModule = injectStrict(AUTH_MODULE_KEY);

const isUserInGroup = computed(() => {
const me: MeResponse | undefined = authModule.getMe;

if (!me || !selectedGroup.value) {
return false;
}

return selectedGroup.value.users.some(
(user: GroupUserResponse) => user.id === me.user.id
);
});

const onConfirmWarning = async () => {
if (!selectedGroup.value || !props.courseId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import vCustomDialog from "@/components/organisms/vCustomDialog.vue";
import { RoleName } from "@/serverApi/v3";
import AuthModule from "@/store/auth";
import NotifierModule from "@/store/notifier";
import { NOTIFIER_MODULE_KEY } from "@/utils/inject";
import { AUTH_MODULE_KEY, NOTIFIER_MODULE_KEY } from "@/utils/inject";
import { createModuleMocks } from "@/utils/mock-store-module";
import { groupResponseFactory } from "@@/tests/test-utils";
import { groupResponseFactory, meResponseFactory } from "@@/tests/test-utils";
import {
createTestingI18n,
createTestingVuetify,
Expand All @@ -28,7 +30,12 @@ describe("StartExistingCourseSyncDialog", () => {
courseName: "courseName",
}
) => {
const me = meResponseFactory.build();

const notifierModule = createModuleMocks(NotifierModule);
const authModule = createModuleMocks(AuthModule, {
getMe: me,
});

const wrapper = mount(StartExistingCourseSyncDialog, {
global: {
Expand All @@ -39,9 +46,11 @@ describe("StartExistingCourseSyncDialog", () => {
],
stubs: {
GroupSelectionDialog: true,
VDialog: true,
},
provide: {
[NOTIFIER_MODULE_KEY.valueOf()]: notifierModule,
[AUTH_MODULE_KEY.valueOf()]: authModule,
},
},
props,
Expand All @@ -50,6 +59,7 @@ describe("StartExistingCourseSyncDialog", () => {
return {
wrapper,
notifierModule,
me,
};
};

Expand Down Expand Up @@ -252,4 +262,76 @@ describe("StartExistingCourseSyncDialog", () => {
expect(wrapper.emitted("success")).toBeUndefined();
});
});

describe("when the user is part of the selected group", () => {
const setup = async () => {
const { wrapper, notifierModule, me } = getWrapper();

const group = groupResponseFactory.build({
users: [
{
id: me.user.id,
firstName: me.user.firstName,
lastName: me.user.lastName,
role: RoleName.Teacher,
},
],
});

wrapper.getComponent(GroupSelectionDialog).vm.$emit("confirm", group);
await nextTick();

return {
wrapper,
notifierModule,
group,
};
};

it("should display the correct warning in the confirmation dialog", async () => {
const { wrapper } = await setup();

const text = wrapper.find("[data-testid=no-teacher-warning-text]");

expect(text.text()).toEqual(
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userInGroupWarning"
);
});
});

describe("when the user is not part of the selected group", () => {
const setup = async () => {
const { wrapper, notifierModule } = getWrapper();

const group = groupResponseFactory.build({
users: [
{
id: "otherUserId",
firstName: "firstname",
lastName: "lastname",
role: RoleName.Teacher,
},
],
});

wrapper.getComponent(GroupSelectionDialog).vm.$emit("confirm", group);
await nextTick();

return {
wrapper,
notifierModule,
group,
};
};

it("should display the correct warning in the confirmation dialog", async () => {
const { wrapper } = await setup();

const text = wrapper.find("[data-testid=no-teacher-warning-text]");

expect(text.text()).toEqual(
"feature-course-sync.StartExistingCourseSyncDialog.confirmation.userNotInGroupWarning"
);
});
});
});
Loading