Permalink
Browse files

MDL-20834 new cap moodle/backup:userinfo - controls who can backupuser

related info. Disabled by default to teachers, oh my! :-( Backported from 19_STABLE
  • Loading branch information...
1 parent f05b8d8 commit 5701efe8da4101136f43b732d1d7ff0d792afc27 @stronk7 stronk7 committed Nov 18, 2009
Showing with 47 additions and 17 deletions.
  1. +10 −0 backup/backup_check.html
  2. +25 −16 backup/backup_form.html
  3. +11 −0 lib/db/access.php
  4. +1 −1 version.php
@@ -4,6 +4,9 @@
//Check login
require_login();
+ // Init backupuserinfo
+ $backupuserinfo = false;
+
if (!empty($course->id)) {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (empty($to)) {
@@ -14,10 +17,12 @@
}
}
}
+ $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_COURSE, $course->id));
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
}
+ $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_SYSTEM));
}
@@ -58,6 +63,11 @@
}
+ // Re-enforce moodle/backup:userinfo capability
+ if (!$backupuserinfo) {
+ $backupprefs->backup_users = 2; // users => none
+ }
+
//Here we check if backup_users = None. Then, we switch off every module
//user info, user_files, logs and exercises, workshop and messages backups. A Warning is showed to
//inform the user.
@@ -4,6 +4,9 @@
//Check login
require_login();
+ //Init backupuserinfo
+ $backupuserinfo = false;
+
if (!empty($course->id)) {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (empty($to)) {
@@ -14,10 +17,12 @@
}
}
}
+ $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_COURSE, $course->id));
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
}
+ $backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_SYSTEM));
}
//Check site
@@ -127,12 +132,16 @@
echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', true);\">". get_string("all")."</a>/";
echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', false);\">". get_string("none")."</a>";
echo "</td>";
- echo "<td align=\"right\">";
- echo '<b>&nbsp;</b>';
- echo "</td><td>";
- echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', true);\">". get_string("all")."</a>/";
- echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', false);\">". get_string("none")."</a>";
- echo "</td>";
+ if (empty($to) and $backupuserinfo) {
+ echo "<td align=\"right\">";
+ echo '<b>&nbsp;</b>';
+ echo "</td><td>";
+ echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', true);\">". get_string("all")."</a>/";
+ echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', false);\">". get_string("none")."</a>";
+ echo "</td>";
+ } else {
+ echo "<td colspan=\"2\">&nbsp;</td>";
+ }
echo "</tr>";
echo "<tr><td colspan=\"4\"><hr /></td></tr>";
$currentrow = 0;
@@ -155,8 +164,8 @@
echo "</td><td align=\"right\">&nbsp;";
echo "</td><td>";
$var = "backup_user_info_".$modname;
- if (empty($to)) {
- $backup_user_options[0] = get_string("withoutuserdata");
+ if (empty($to) and $backupuserinfo) {
+ $backup_user_options[0] = get_string("withoutuserdata");
$backup_user_options[1] = get_string("withuserdata");
//choose_from_menu($backup_user_options, $var, $$var, "");
print_checkbox($var, $$var, $$var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'backup_user_info_'.$modname.'\',this.checked)');
@@ -177,7 +186,7 @@
echo '</td><td align="right">&nbsp;';
$var = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
$$var = optional_param($var,1);
- if (empty($to)) {
+ if (empty($to) and $backupuserinfo) {
print_checkbox($var,$$var,$$var,get_string('userdata'),'','this.form.elements[\'backup_user_info_'.$modname.'\'].checked=1;');
} else {
echo '<input type="hidden" name="'.$var.'" value="0" />';
@@ -207,7 +216,7 @@
$hidden_options .= '<input type="hidden" name="backup_metacourse" value="0" />';
}
- if (empty($to)) {
+ if (empty($to) and $backupuserinfo) {
//Now print the Users tr
echo "<tr>";
echo "<td align=\"right\" colspan=\"2\"><b>";
@@ -220,10 +229,10 @@
echo "</td></tr>";
}
else {
- $hidden_options .= '<input type="hidden" name="backup_users" value="0" />';
+ $hidden_options .= '<input type="hidden" name="backup_users" value="2" />';
}
-
- if (empty($to)) {
+
+ if (empty($to) and $backupuserinfo) {
//Now print the Logs tr
echo "<tr>";
echo "<td align=\"right\" colspan=\"2\"><b>";
@@ -237,8 +246,8 @@
else {
$hidden_options .= '<input type="hidden" name="backup_logs" value="0" />';
}
-
- if (empty($to)) {
+
+ if (empty($to) and $backupuserinfo) {
//Now print the User Files tr
echo "<tr>";
echo "<td align=\"right\" colspan=\"2\"><b>";
@@ -262,7 +271,7 @@
choose_from_menu($course_file_options, "backup_course_files", $backup_course_files, "");
echo "</td></tr>";
- if (empty($to) && $course->id == SITEID) {
+ if (empty($to) and $backupuserinfo and $course->id == SITEID) {
//If we are in a SITEID backup print the Messages tr
echo "<tr>";
echo "<td align=\"right\" colspan=\"2\"><b>";
View
@@ -168,6 +168,17 @@
)
),
+ 'moodle/backup:userinfo' => array(
+
+ 'riskbitmask' => RISK_PERSONAL | RISK_CONFIG,
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'legacy' => array(
+ 'admin' => CAP_ALLOW
+ )
+ ),
+
'moodle/site:restore' => array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
View
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007021599.11; // YYYYMMDD = date of the 1.8 branch (don't change)
+ $version = 2007021599.12; // YYYYMMDD = date of the 1.8 branch (don't change)
// 99 = we reached a .10 release! (don't change)
// .XX = release number 1.8.[10,11,12,..]

0 comments on commit 5701efe

Please sign in to comment.