mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
MDL-35429 backup: Only show relevant actions for automated backups
- Users without permission to download or restore won't see the respective links. - The 'Manage backup files' button for the 'automated' backup filearea now requires the same permissions as downloading does for this filearea, those being 'restore:userinfo' and 'backup:downloadfile'.
This commit is contained in:
parent
54945fa728
commit
5bbea7338d
4 changed files with 119 additions and 13 deletions
|
@ -4266,3 +4266,32 @@ function course_require_view_participants($context) {
|
|||
throw new required_capability_exception($context, $viewparticipantscap, 'nopermissions', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the user can download from the specified backup file area in the given context.
|
||||
*
|
||||
* @param string $filearea the backup file area. E.g. 'course', 'backup' or 'automated'.
|
||||
* @param \context $context
|
||||
* @param stdClass $user the user object. If not provided, the current user will be checked.
|
||||
* @return bool true if the user is allowed to download in the context, false otherwise.
|
||||
*/
|
||||
function can_download_from_backup_filearea($filearea, \context $context, stdClass $user = null) {
|
||||
$candownload = false;
|
||||
switch ($filearea) {
|
||||
case 'course':
|
||||
case 'backup':
|
||||
$candownload = has_capability('moodle/backup:downloadfile', $context, $user);
|
||||
break;
|
||||
case 'automated':
|
||||
// Given the automated backups may contain userinfo, we restrict access such that only users who are able to
|
||||
// restore with userinfo are able to download the file. Users can't create these backups, so checking 'backup:userinfo'
|
||||
// doesn't make sense here.
|
||||
$candownload = has_capability('moodle/backup:downloadfile', $context, $user) &&
|
||||
has_capability('moodle/restore:userinfo', $context, $user);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
return $candownload;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue