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-2119 migration assistant external role #3364

Merged
merged 18 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c39373e
N21-2119 show external role in migration assistant match dialog
GordonNicholasCap Aug 15, 2024
8b4058b
N21-2119 update api.ts
GordonNicholasCap Aug 15, 2024
94a4f35
N21-2119 wip fix tests
GordonNicholasCap Aug 15, 2024
6fe7d12
Merge branch 'main' into N21-2119-migration-assistant-external-roles
GordonNicholasCap Aug 16, 2024
2ac3b9b
N21-2119 adapted external role text
GordonNicholasCap Aug 16, 2024
3e67ad5
N21-2119 new tests & fixed failing test
GordonNicholasCap Aug 16, 2024
05434fb
Merge branch 'main' into N21-2119-migration-assistant-external-roles
GordonNicholasCap Aug 16, 2024
00317f0
N21-2119 added more tests
GordonNicholasCap Aug 16, 2024
b6b6716
N21-2119 changed switch-case -> if
GordonNicholasCap Aug 16, 2024
3e06c6f
N21-2119 revert accidental changes
GordonNicholasCap Aug 16, 2024
5c31ae6
N21-2119 n/a for when there is no external roles
GordonNicholasCap Aug 19, 2024
070ebe2
N21-2119 update api.ts
GordonNicholasCap Aug 19, 2024
46edfc1
Merge branch 'main' into N21-2119-migration-assistant-external-roles
GordonNicholasCap Aug 20, 2024
53d8850
N21-2119 update tests & api.ts for optional external role
GordonNicholasCap Aug 20, 2024
8f26733
N21-2119 use isNbc, record for role name mapping & adjust role label
GordonNicholasCap Aug 20, 2024
687c730
N21-2119 minor adjustments
GordonNicholasCap Aug 20, 2024
8c51721
N21-2119 minor adjustments to mapping
GordonNicholasCap Aug 20, 2024
26630a9
N21-2119 handling when "userFriendlyRoleName" is undefined
GordonNicholasCap Aug 20, 2024
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
248 changes: 242 additions & 6 deletions src/components/molecules/vImportUsersMatchSearch.unit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { importUsersModule } from "@/store";
import ImportUsersModule from "@/store/import-users";
import { ImportUserResponseRoleNamesEnum } from "@/serverApi/v3";
import { THEME_KEY } from "@/utils/inject";
import {
createTestingI18n,
Expand All @@ -24,8 +25,9 @@ const testProps = {
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: ["student"],
roleNames: [ImportUserResponseRoleNamesEnum.Student],
classNames: ["6a"],
externalRoleNames: [],
},
isDialog: true,
ldapSource: "LDAP",
Expand Down Expand Up @@ -93,7 +95,7 @@ describe("@/components/molecules/vImportUsersMatchSearch", () => {
loginName: "[email protected]",
firstName: "Cord",
lastName: "Carl",
roleNames: ["teacher"],
roleNames: [ImportUserResponseRoleNamesEnum.Teacher],
text: "Cord Carl",
};
const wrapper = getWrapper(testProps);
Expand All @@ -115,7 +117,7 @@ describe("@/components/molecules/vImportUsersMatchSearch", () => {
loginName: "[email protected]",
firstName: "Cord",
lastName: "Carl",
roleNames: ["teacher"],
roleNames: [ImportUserResponseRoleNamesEnum.Teacher],
text: "Cord Carl",
};

Expand Down Expand Up @@ -150,15 +152,15 @@ describe("@/components/molecules/vImportUsersMatchSearch", () => {
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: ["student"],
roleNames: [ImportUserResponseRoleNamesEnum.Student],
classNames: ["6a"],
};
const match = {
userId: "0000d213816abba584714c0a",
loginName: "[email protected]",
firstName: "Thorsten",
lastName: "Test",
roleNames: ["admin"],
roleNames: [ImportUserResponseRoleNamesEnum.Admin],
matchedBy: "admin",
};
const wrapper = getWrapper({
Expand Down Expand Up @@ -192,7 +194,7 @@ describe("@/components/molecules/vImportUsersMatchSearch", () => {
expect(deleteMatchButton.props("disabled")).toBe(true);
});

it("should disable save button when no no item was selected", () => {
it("should disable save button when no item was selected", () => {
const wrapper = getWrapper(testProps);

const saveMatchButton = wrapper
Expand All @@ -213,4 +215,238 @@ describe("@/components/molecules/vImportUsersMatchSearch", () => {

expect(editedItemUsername.exists()).toBe(false);
});

describe("when the theme is not NBC", () => {
const setup = () => {
const setupTestProps = {
editedItem: {
flagged: false,
importUserId: "123",
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: [ImportUserResponseRoleNamesEnum.Student],
classNames: ["6a"],
externalRoleNames: ["student-external"],
},
isDialog: true,
ldapSource: "ldap-external",
isNbc: false,
};
return {
setupTestProps,
};
};

it("should not contain any text for external role", () => {
const { setupTestProps } = setup();
const wrapper = getWrapper(setupTestProps);

const editedItemElement = wrapper
.find("[data-testid=edited-item]")
.html();

expect(editedItemElement).not.toContain(
`common.labels.role ${setupTestProps.ldapSource}`
);
});
});

describe("when the theme is NBC", () => {
describe("when the external role is 'Lern' (Student)", () => {
const setup = () => {
const adminTestProps = {
editedItem: {
flagged: false,
importUserId: "123",
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: [ImportUserResponseRoleNamesEnum.Student],
classNames: ["6a"],
externalRoleNames: ["Lern"],
},
isDialog: true,
ldapSource: "moin.schule",
isNbc: true,
};
return {
adminTestProps,
};
};

it("should correctly show the external role of the user", () => {
const { adminTestProps } = setup();
const wrapper = getWrapper(adminTestProps);

const editedItemElement = wrapper
.find("[data-testid=edited-item]")
.html();

expect(editedItemElement).toContain("Max");
expect(editedItemElement).toContain("Mustermann");
expect(editedItemElement).toContain("common.roleName.student");
expect(editedItemElement).toContain(
`common.labels.role ${adminTestProps.ldapSource}: ` +
"components.molecules.importUsersMatch.externalRoleName.schulconnex.student)"
);
});
});
describe("when the external role is 'Lehr' (Teacher)", () => {
const setup = () => {
const adminTestProps = {
editedItem: {
flagged: false,
importUserId: "123",
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: [ImportUserResponseRoleNamesEnum.Teacher],
classNames: ["6a"],
externalRoleNames: ["Lehr"],
},
isDialog: true,
ldapSource: "moin.schule",
isNbc: true,
};
return {
adminTestProps,
};
};

it("should correctly show the external role of the user", () => {
const { adminTestProps } = setup();
const wrapper = getWrapper(adminTestProps);

const editedItemElement = wrapper
.find("[data-testid=edited-item]")
.html();

expect(editedItemElement).toContain("Max");
expect(editedItemElement).toContain("Mustermann");
expect(editedItemElement).toContain("common.roleName.teacher");
expect(editedItemElement).toContain(
`common.labels.role ${adminTestProps.ldapSource}: ` +
"components.molecules.importUsersMatch.externalRoleName.schulconnex.teacher)"
);
});
});
describe("when the external role is 'Leit' (Management)", () => {
const setup = () => {
const adminTestProps = {
editedItem: {
flagged: false,
importUserId: "123",
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: [ImportUserResponseRoleNamesEnum.Admin],
classNames: ["6a"],
externalRoleNames: ["Leit"],
},
isDialog: true,
ldapSource: "moin.schule",
isNbc: true,
};
return {
adminTestProps,
};
};

it("should correctly show the external role of the user", () => {
const { adminTestProps } = setup();
const wrapper = getWrapper(adminTestProps);

const editedItemElement = wrapper
.find("[data-testid=edited-item]")
.html();

expect(editedItemElement).toContain("Max");
expect(editedItemElement).toContain("Mustermann");
expect(editedItemElement).toContain("common.roleName.administrator");
expect(editedItemElement).toContain(
`common.labels.role ${adminTestProps.ldapSource}: ` +
"components.molecules.importUsersMatch.externalRoleName.schulconnex.manager)"
);
});
});
describe("when the external role is 'OrgAdmin' (Admin)", () => {
const setup = () => {
const adminTestProps = {
editedItem: {
flagged: false,
importUserId: "123",
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: [ImportUserResponseRoleNamesEnum.Admin],
classNames: ["6a"],
externalRoleNames: ["OrgAdmin"],
},
isDialog: true,
ldapSource: "moin.schule",
isNbc: true,
};
return {
adminTestProps,
};
};

it("should correctly show the external role of the user", () => {
const { adminTestProps } = setup();
const wrapper = getWrapper(adminTestProps);

const editedItemElement = wrapper
.find("[data-testid=edited-item]")
.html();

expect(editedItemElement).toContain("Max");
expect(editedItemElement).toContain("Mustermann");
expect(editedItemElement).toContain("common.roleName.administrator");
expect(editedItemElement).toContain(
`common.labels.role ${adminTestProps.ldapSource}: ` +
"components.molecules.importUsersMatch.externalRoleName.schulconnex.orgAdmin)"
);
});
});

describe("when externalRoleNames prop is empty", () => {
const setup = () => {
const setupTestProps = {
editedItem: {
flagged: false,
importUserId: "123",
loginName: "max_mus",
firstName: "Max",
lastName: "Mustermann",
roleNames: [ImportUserResponseRoleNamesEnum.Student],
classNames: ["6a"],
externalRoleNames: [],
},
isDialog: true,
ldapSource: "moin.schule",
isNbc: true,
};
return {
setupTestProps,
};
};

it("should show that the role is not available", () => {
const { setupTestProps } = setup();
const wrapper = getWrapper(setupTestProps);

const editedItemElement = wrapper
.find("[data-testid=edited-item]")
.html();

expect(editedItemElement).toContain("Max");
expect(editedItemElement).toContain("Mustermann");
expect(editedItemElement).toContain("common.roleName.student");
expect(editedItemElement).toContain(
"components.molecules.importUsersMatch.externalRoleName.none"
);
});
});
});
});
46 changes: 45 additions & 1 deletion src/components/molecules/vImportUsersMatchSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</VListItemTitle>
<VListItemSubtitle>
{{ mapRoleNames(editedItem.roleNames) }}
{{ isNbc ? externalRoleText : "" }}
</VListItemSubtitle>
<VListItemSubtitle
v-if="editedItem.classNames && editedItem.classNames.length"
Expand Down Expand Up @@ -233,6 +234,7 @@ const props = defineProps({
classNames: [],
match: {},
flagged: false,
externalRoleNames: [],
GordonNicholasCap marked this conversation as resolved.
Show resolved Hide resolved
}),
firstName: {
type: String,
Expand Down Expand Up @@ -298,10 +300,39 @@ const canSave: ComputedRef<boolean> = computed(() => {
return true;
});

const canDelete = computed(() => {
const canDelete: ComputedRef<boolean> = computed(() => {
return props.editedItem.match && selectedItem.value === null;
});

const externalRoleText: ComputedRef<string> = computed(() => {
let role = t("components.molecules.importUsersMatch.externalRoleName.none");
if (props.editedItem.externalRoleNames?.length) {
role = mapExternalRoleNames(props.editedItem.externalRoleNames);
}

const text = `(${t("common.labels.role")} ${props.ldapSource}: ${role})`;
return text;
});

const schulconnexExternalRoleNamesMapping: ComputedRef<Record<string, string>> =
GordonNicholasCap marked this conversation as resolved.
Show resolved Hide resolved
computed(() => {
const roleMapping = {
["Lehr"]: t(
"components.molecules.importUsersMatch.externalRoleName.schulconnex.teacher"
),
["Lern"]: t(
"components.molecules.importUsersMatch.externalRoleName.schulconnex.student"
),
["Leit"]: t(
"components.molecules.importUsersMatch.externalRoleName.schulconnex.manager"
),
["OrgAdmin"]: t(
"components.molecules.importUsersMatch.externalRoleName.schulconnex.orgAdmin"
),
};
return roleMapping;
});

const getDataFromApi = async (append = false) => {
loading.value = true;

Expand Down Expand Up @@ -417,6 +448,19 @@ const mapRoleNames = (roleNames: unknown[]) => {
.join(", ");
};

const mapExternalRoleNames = (externalRoleNames: string[]) => {
return externalRoleNames
.map((role) => {
if (props.isNbc) {
const userFriendlyRoleName =
schulconnexExternalRoleNamesMapping.value[role];
return userFriendlyRoleName;
}
return role;
})
.join(", ");
};

onMounted(async () => {
flagged.value = props.editedItem.flagged;

Expand Down
10 changes: 10 additions & 0 deletions src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,16 @@ export default {
"Keiner. Benutzer wird neu erstellt.",
"components.molecules.importUsersMatch.write":
"Vornamen oder Nachnamen eingeben",
"components.molecules.importUsersMatch.externalRoleName.none":
"Nicht verfügbar",
"components.molecules.importUsersMatch.externalRoleName.schulconnex.teacher":
"Lehrende/r",
"components.molecules.importUsersMatch.externalRoleName.schulconnex.student":
"Lernende/r",
"components.molecules.importUsersMatch.externalRoleName.schulconnex.orgAdmin":
"Organisationsadministrator",
"components.molecules.importUsersMatch.externalRoleName.schulconnex.manager":
"Organisationsleitung",
"components.molecules.MintEcFooter.chapters": "Kapitelübersicht",
"components.molecules.share.columnBoard.options.infoText":
"Mit dem folgenden Link kann der Bereich als Kopie von anderen Lehrkräften importiert werden. Personenbezogene Daten werden dabei nicht importiert.",
Expand Down
Loading
Loading