Skip to content

Commit

Permalink
Merge pull request chamilo#5628 from christianbeeznest/ofaj-21838-2
Browse files Browse the repository at this point in the history
Internal: Fix student permission to create events in course agenda - refs BT#21838
  • Loading branch information
NicoDucou authored Jul 4, 2024
2 parents 865dcbf + 8b3f8a1 commit 7af9e81
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion assets/vue/store/cidReq.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
8 changes: 6 additions & 2 deletions assets/vue/store/courseSettingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 23 additions & 4 deletions assets/vue/views/ccalendarevent/CCalendarEventList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
/>

<BaseButton
v-if="showDeleteButton"
v-if="allowToEdit && showDeleteButton"
:label="t('Delete')"
icon="delete"
type="danger"
Expand Down Expand Up @@ -149,6 +149,7 @@ import { useCalendarActionButtons } from "../../composables/calendar/calendarAct
import { useCalendarEvent } from "../../composables/calendar/calendarEvent"
import resourceLinkService from "../../services/resourceLinkService"
import { useSecurityStore } from "../../store/securityStore"
import { useCourseSettings } from "../../store/courseSettingStore"
const store = useStore()
const securityStore = useSecurityStore()
Expand All @@ -175,6 +176,23 @@ const { appLocale } = useLocale()
const route = useRoute()
const isGlobal = ref(route.query.type === "global")
const courseSettingsStore = useCourseSettings()
const allowUserEditAgenda = ref(false);
watch([course, session], async ([newCourse, newSession]) => {
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({
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 7af9e81

Please sign in to comment.