Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.7.2
-
Fix Version/s: None
-
Component/s: Calendar
-
Labels:None
-
Affected Branches:MOODLE_17_STABLE
Description
After migrating to 1.7, events that were created by one teacher, can't be edited by another. I found someting in calendar/lib.php that corrected this, but it would be great if someone double checked it...
function: calendar_edit_event_allowed
1183 if ($event->userid) {
1184 if ($event->userid == $USER->id) {
1185 return (has_capability('moodle/calendar:manageownentries', $sitecontext));
+ 1186 } else {
+ 1187 return has_capability( 'moodle/calendar:manageentries', get_context_instance( CONTEXT_COURSE, $event->courseid));
+ 1188 }
1189 } else if ($event->groupid) {
1190 $group = get_record('groups', 'id', $event->groupid);
1191 if($group === false) {
1192 return false;
1193 }
It worked for me, but I can't understand why this "else" didn't exist... maybe event->userid should get there empty?
Issue Links
| This issue duplicates: | ||||
| MDL-9186 | adding "moodle/calendar:manageentries" does not allow a teacher to edit calendar events created by other users |
|
|
|
I confirm it still does not work with group events in Moodle 1.7.2 patched with anonymous CVS until
anonymous access broke down ( mid April). .
I noticed that the code of calendar_edit_event_allowed is quite different of the code given in the above comment
AND line 1189 gives a FATAL error for a non existing function groups_group_exists . as shown in apache's logs
[Tue May 01 11:15:29 2007] [error] [client 134.214.162.224] PHP Fatal error: Call to undefined function groups_group_exists() in /var/www/html/moodle172/calendar/lib.php on line 1185, referer: http://cipcnet.insa-lyon.fr/moodle/course/view.php?id=5&cal_m=6&cal_y=2007
revision and code of calendar/lib.php is given below :
$Id: lib.php,v 1.151.2.8 2007/04/05 08:00:40 toyomoyo Exp $
function calendar_edit_event_allowed($event) {
global $USER;
// can not be using guest account
if ($USER->username == "guest") { return false; }
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
// if user has manageentries at site level, return true
if (has_capability('moodle/calendar:manageentries', $sitecontext)) { return true; }
// if groupid is set, it's definitely a group event
if ($event->groupid) {
//TODO:check.
if (! groups_group_exists($event->groupid)) { <---- HERE UNKOWN FUNCTION CALL return false; }
// this is ok because if you have this capability at course level, you should be able
// to edit group calendar too
// there is no need to check membership, because if you have this capability
// you will have a role in this group context
return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_GROUP, $event->groupid));
} else if ($event->courseid) { // if groupid is not set, but course is set, // it's definiely a course event return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $event->courseid)); } else if ($event->userid && $event->userid == $USER->id) { // if course is not set, but userid id set, it's a user event return (has_capability('moodle/calendar:manageownentries', $sitecontext)); }
return false;
}
I got rid of the error log by changing lines to something simlar to the code given in the previous comment :
if ($event->groupid) { if (! get_record('groups', 'id', $event->groupid)) return false; }
the same call to unkown function is still there in the latest CVS at
http://moodle.cvs.sourceforge.net/moodle/moodle/calendar/lib.php?revision=1.174&view=markup
$Id: lib.php,v 1.174 2007/04/27 06:30:21 moodler Exp $