mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-18124 course creators can not delete any courses in their category any more, only those they created at most one day ago; merged from MOODLE_19_STABLE
This commit is contained in:
parent
382123a06e
commit
8b449a3958
1 changed files with 18 additions and 17 deletions
|
@ -3423,30 +3423,31 @@ function get_section_name($format) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can the current user delete this course?
|
* Can the current user delete this course?
|
||||||
|
* Course creators have exception,
|
||||||
|
* 1 day after the creation they can sill delete the course.
|
||||||
* @param int $courseid
|
* @param int $courseid
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*
|
|
||||||
* Exception here to fix MDL-7796.
|
|
||||||
*
|
|
||||||
* FIXME
|
|
||||||
* Course creators who can manage activities in the course
|
|
||||||
* shoule be allowed to delete the course. We do it this
|
|
||||||
* way because we need a quick fix to bring the functionality
|
|
||||||
* in line with what we had pre-roles. We can't give the
|
|
||||||
* default course creator role moodle/course:delete at
|
|
||||||
* CONTEXT_SYSTEM level because this will allow them to
|
|
||||||
* delete any course in the site. So we hard code this here
|
|
||||||
* for now.
|
|
||||||
*
|
|
||||||
* @author vyshane AT gmail.com
|
|
||||||
*/
|
*/
|
||||||
function can_delete_course($courseid) {
|
function can_delete_course($courseid) {
|
||||||
|
global $USER, $DB;
|
||||||
|
|
||||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||||
|
|
||||||
return ( has_capability('moodle/course:delete', $context)
|
if (has_capability('moodle/course:delete', $context)) {
|
||||||
|| (has_capability('moodle/legacy:coursecreator', $context)
|
return true;
|
||||||
&& has_capability('moodle/course:manageactivities', $context)) );
|
}
|
||||||
|
|
||||||
|
// hack: now try to find out if creator created this course recently (1 day)
|
||||||
|
if (!has_capability('moodle/course:create', $context)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$since = time() - 60*60*24;
|
||||||
|
|
||||||
|
$params = array('userid'=>$USER->id, 'url'=>"view.php?id=$courseid", 'since'=>$since);
|
||||||
|
$select = "module = 'course' AND action = 'new' AND userid = :userid AND url = :url AND time > :since";
|
||||||
|
|
||||||
|
return $DB->record_exists_select('log', $select, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue