Hide export button for members

This commit is contained in:
Christian Cueni 2024-10-03 11:46:20 +02:00
parent 720130439b
commit 7dd38182fc
2 changed files with 43 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import {
type DashboardPersonCourseSessionType,
exportPersons,
} from "@/services/dashboard";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useUserStore } from "@/stores/user";
import type { DashboardPersonsPageMode } from "@/types";
import { openDataAsXls } from "@/utils/export";
@ -39,6 +40,7 @@ const userStore = useUserStore();
const { loading, dashboardPersons } = useDashboardPersonsDueDates(props.mode);
const { CHOSEN_PROFILE_TO_NAME } = useChosenProfileMapping();
const { allCourseSessionActions } = useCourseSessionsStore();
const courses = computed(() => {
return [
@ -300,6 +302,25 @@ const filtersVisible = computed(() => {
);
});
const canExport = computed(() => {
// If user is only member, he can't export
// member = has is_member property, but not is_expert or is_supervisor
if (!allCourseSessionActions.has("is_member")) {
// is berufsbildner or expert or supervisor
return true;
}
if (
allCourseSessionActions.has("is_expert") ||
allCourseSessionActions.has("is_supervisor")
) {
// is member
return true;
}
return false;
});
function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessionType) {
if (
[
@ -317,15 +338,9 @@ function personRoleDisplayValue(personCourseSession: DashboardPersonCourseSessio
}
async function exportData() {
const requestData = filteredPersons.value.reduce(
(acc, person) => {
acc.courseSessionUserIds.push(person.csu_id);
return acc;
},
{
courseSessionUserIds: [] as string[],
}
);
const requestData = {
courseSessionUserIds: filteredPersons.value.map((person) => person.csu_id),
};
const data = await exportPersons(requestData, userStore.language);
openDataAsXls(data.encoded_data, data.file_name);
}
@ -358,7 +373,12 @@ watch(selectedRegion, () => {
</router-link>
<div class="mb-10 flex items-center justify-between">
<h2 class="my-4">{{ $t("a.Personen") }}</h2>
<button class="flex" data-cy="export-button" @click="exportData">
<button
v-if="canExport"
class="flex"
data-cy="export-button"
@click="exportData"
>
<it-icon-export></it-icon-export>
<span class="ml inline-block">{{ $t("a.Als Excel exportieren") }}</span>
</button>

View File

@ -129,6 +129,18 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
return Boolean(hasPreview && (inLearningPath() || inCompetenceProfile()));
});
const allCourseSessionActions = computed(() => {
const actionsSet = new Set();
allCourseSessions.value.forEach((item) => {
item.actions.forEach((action) => {
actionsSet.add(action);
});
});
return actionsSet;
});
return {
uniqueCourseSessionsByCourse,
allCurrentCourseSessions,
@ -146,5 +158,6 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
// only used for unit testing
allCourseSessions,
allCourseSessionActions,
};
});