From 656837d65fa38fd175ca224239194dbe808f2f9f Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Fri, 24 Aug 2018 10:06:11 +0100 Subject: [PATCH] MDL-62944 calendar: Clarify the intended use of $checkcapability --- calendar/lib.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index 3d8be5841a8..2a0bc58977f 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -426,11 +426,20 @@ class calendar_event { * Pass in a object containing the event properties and this function will * insert it into the database and deal with any associated files * + * Capability checking should be performed if the user is directly manipulating the event + * and no other capability has been tested. However if the event is not being manipulated + * directly by the user and another capability has been checked for them to do this then + * capabilites should not be checked. + * + * For example if a user is editing an event in the calendar the check should be true, + * but if you are updating an event in an activities settings are changed then the calendar + * capabilites should not be checked. + * * @see self::create() * @see self::update() * * @param \stdClass $data object of event - * @param bool $checkcapability if moodle should check calendar managing capability or not + * @param bool $checkcapability If Moodle should check the user can manage the calendar events for this call or not. * @return bool event updated */ public function update($data, $checkcapability=true) { @@ -914,10 +923,19 @@ class calendar_event { } /** - * Creates a new event and returns an event object + * Creates a new event and returns an event object. + * + * Capability checking should be performed if the user is directly creating the event + * and no other capability has been tested. However if the event is not being created + * directly by the user and another capability has been checked for them to do this then + * capabilites should not be checked. + * + * For example if a user is creating an event in the calendar the check should be true, + * but if you are creating an event in an activity when it is created then the calendar + * capabilites should not be checked. * * @param \stdClass|array $properties An object containing event properties - * @param bool $checkcapability Check caps or not + * @param bool $checkcapability If Moodle should check the user can manage the calendar events for this call or not. * @throws \coding_exception * * @return calendar_event|bool The event object or false if it failed