From 7e4a6aa4a13aebee401204869bac9db04b4cdb6e Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Sat, 21 Nov 2009 11:53:08 +0000 Subject: [PATCH] MDL-9251 backup/restore *all* users - is now forbidden for users lacking backup/restore permission at system level. Backported from 19_STABLE --- backup/backup_check.html | 5 +++++ backup/backup_form.html | 4 +++- backup/restore_check.html | 5 +++++ backup/restore_form.html | 4 ++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/backup/backup_check.html b/backup/backup_check.html index 6a5619413bc..e900b3b36d5 100644 --- a/backup/backup_check.html +++ b/backup/backup_check.html @@ -64,6 +64,11 @@ } + // Re-enforce 'moodle/site:backup' at system context to be able to backup all users + if ($backupprefs->backup_users == 0 and !has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) { + $backupprefs->backup_users = 1; // users => course + } + // Re-enforce moodle/backup:userinfo capability if (!$backupuserinfo) { $backupprefs->backup_users = 2; // users => none diff --git a/backup/backup_form.html b/backup/backup_form.html index 0ddee8660a5..3b6a7d44ceb 100644 --- a/backup/backup_form.html +++ b/backup/backup_form.html @@ -224,7 +224,9 @@ function selectItemInCheckboxByName(formId, checkName, checked ) { echo ""; echo get_string("users").":"; echo ""; - $user_options[0] = get_string("all"); + if (has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) { + $user_options[0] = get_string("all"); + } $user_options[1] = get_string("course"); $user_options[2] = get_string("none"); choose_from_menu($user_options, "backup_users", $backup_users, ""); diff --git a/backup/restore_check.html b/backup/restore_check.html index 042756d3ba2..d2d613da851 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -282,6 +282,11 @@ } } + // Re-enforce 'moodle/site:restore' at system context to be able to restore all users + if ($restore->users == 0 and !has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) { + $restore->users = 1; // users => course + } + // Re-enforce moodle/restore:userinfo capability if (!$restoreuserinfo) { $userinfocheck = true; diff --git a/backup/restore_form.html b/backup/restore_form.html index e52c2584c7e..cd1fc656965 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -399,8 +399,8 @@ function selectItemInCheckboxByName(formId, checkName, checked ) { //If some user is present in the backup file if (($info->backup_users == "all" or $info->backup_users == "course") and $restoreuserinfo) { $user_options = array(); - //If all users are in the backup file - if ($info->backup_users == "all") { + //If all users are in the backup file and user has 'moodle/site:restore' at system level + if ($info->backup_users == "all" and has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) { $user_options[0] = get_string("all"); } $user_options[1] = get_string("course");