From 8b3f8a170060c5614e179d250e4647c4ab5a9dc6 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Wed, 3 Jul 2024 15:43:39 -0500 Subject: [PATCH] Internal: Fix student permission to create events in course agenda - refs BT#21838 --- assets/vue/store/cidReq.js | 2 +- assets/vue/store/courseSettingStore.js | 8 ++++-- .../ccalendarevent/CCalendarEventList.vue | 27 ++++++++++++++++--- .../PlatformConfigurationController.php | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/assets/vue/store/cidReq.js b/assets/vue/store/cidReq.js index fde93cb08a2..094095c20f1 100644 --- a/assets/vue/store/cidReq.js +++ b/assets/vue/store/cidReq.js @@ -67,7 +67,7 @@ export const useCidReqStore = defineStore("cidReq", () => { isCourseLoaded.value = false const coursePromise = courseService.find(courseIri, { sid }) - const courseSettingsPromise = courseSettingsStore.loadCourseSettings(cId) + const courseSettingsPromise = courseSettingsStore.loadCourseSettings(cId, sid) try { await Promise.all([coursePromise, courseSettingsPromise]).then((responses) => (course.value = responses[0])) diff --git a/assets/vue/store/courseSettingStore.js b/assets/vue/store/courseSettingStore.js index a56e585c9ca..b962fc7a68f 100644 --- a/assets/vue/store/courseSettingStore.js +++ b/assets/vue/store/courseSettingStore.js @@ -6,11 +6,15 @@ export const useCourseSettings = defineStore("courseSettings", () => { const isLoading = ref(false) const settings = ref({}) - async function loadCourseSettings(courseId) { + async function loadCourseSettings(courseId, sessionId = null) { isLoading.value = true try { - const { data } = await axios.get(`/platform-config/list/course_settings?cid=${courseId}`) + const params = { cid: courseId } + if (sessionId) { + params.sid = sessionId + } + const { data } = await axios.get(`/platform-config/list/course_settings`, { params }) settings.value = data.settings } catch (e) { console.error("Error loading course settings:", e) diff --git a/assets/vue/views/ccalendarevent/CCalendarEventList.vue b/assets/vue/views/ccalendarevent/CCalendarEventList.vue index 442c9104b58..7bdcf410506 100644 --- a/assets/vue/views/ccalendarevent/CCalendarEventList.vue +++ b/assets/vue/views/ccalendarevent/CCalendarEventList.vue @@ -69,7 +69,7 @@ /> { + if (newCourse && newCourse.id) { + const sessionId = newSession ? newSession.id : null; + await courseSettingsStore.loadCourseSettings(newCourse.id, sessionId); + const setting = courseSettingsStore.getSetting("allow_user_edit_agenda"); + allowUserEditAgenda.value = setting === "1"; + if (allowUserEditAgenda.value) { + showAddButton.value = true; + } + } else { + allowUserEditAgenda.value = false; + } +}, { immediate: true }); + let currentEvent = null const sessionState = reactive({ @@ -265,6 +283,7 @@ const calendarOptions = ref({ let event = eventClickInfo.event.toPlainObject() if (event.extendedProps["@type"] && event.extendedProps["@type"] === "Session") { + allowToEdit.value = allowUserEditAgenda.value && (event.extendedProps.resourceNode.creator.id === securityStore.user.id) sessionState.sessionAsEvent = event sessionState.showSessionDialog = true @@ -278,7 +297,7 @@ const calendarOptions = ref({ item.value["endDate"] = event.end item.value["parentResourceNodeId"] = event.extendedProps.resourceNode.creator.id - allowToEdit.value = isEditableByUser(item.value, securityStore.user.id) + allowToEdit.value = (isEditableByUser(item.value, securityStore.user.id) || allowUserEditAgenda.value) && (event.extendedProps.resourceNode.creator.id === securityStore.user.id) allowToSubscribe.value = !allowToEdit.value && allowSubscribeToEvent(item.value) allowToUnsubscribe.value = !allowToEdit.value && allowUnsubscribeToEvent(item.value, securityStore.user.id) @@ -325,8 +344,8 @@ const allowAction = (eventType) => { return contextRules[currentContext.value].includes(eventType) } -const showEditButton = computed(() => allowAction(item.value.type)) -const showDeleteButton = computed(() => allowAction(item.value.type)) +const showEditButton = computed(() => allowToEdit.value && allowAction(item.value.type)); +const showDeleteButton = computed(() => (isEditableByUser(item.value, securityStore.user.id) || allowUserEditAgenda.value) && allowAction(item.value.type)); const cal = ref(null) diff --git a/src/CoreBundle/Controller/PlatformConfigurationController.php b/src/CoreBundle/Controller/PlatformConfigurationController.php index 947690cec4d..b4194faaa1f 100644 --- a/src/CoreBundle/Controller/PlatformConfigurationController.php +++ b/src/CoreBundle/Controller/PlatformConfigurationController.php @@ -135,6 +135,7 @@ public function courseSettingsList( $courseSettingsManager->setCourse($course); $settings = [ 'show_course_in_user_language' => $courseSettingsManager->getCourseSettingValue('show_course_in_user_language'), + 'allow_user_edit_agenda' => $courseSettingsManager->getCourseSettingValue('allow_user_edit_agenda'), ]; return new JsonResponse(['settings' => $settings]);