Skip to content

Commit

Permalink
MDL-21666 backup & restore caps - moving to new naming schema. More t…
Browse files Browse the repository at this point in the history
…o come.
  • Loading branch information
stronk7 committed Feb 19, 2010
1 parent a7382d3 commit d294000
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 64 deletions.
2 changes: 1 addition & 1 deletion admin/report/backups/settings.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

$ADMIN->add('reports', new admin_externalpage('reportbackups', get_string('backups', 'admin'), "$CFG->wwwroot/$CFG->admin/report/backups/index.php",'moodle/site:backup'));
$ADMIN->add('reports', new admin_externalpage('reportbackups', get_string('backups', 'admin'), "$CFG->wwwroot/$CFG->admin/report/backups/index.php",'moodle/backup:backupcourse'));
4 changes: 2 additions & 2 deletions admin/settings/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file defines settingpages and externalpages under the "courses" category

if ($hassiteconfig
or has_capability('moodle/site:backup', $systemcontext)
or has_capability('moodle/backup:backupcourse', $systemcontext)
or has_capability('moodle/category:manage', $systemcontext)
or has_capability('moodle/course:create', $systemcontext)
or has_capability('moodle/site:approvecourse', $systemcontext)) { // speedup for non-admins, add all caps used on this page
Expand Down Expand Up @@ -133,7 +133,7 @@
}

/// "backups" settingpage
$temp = new admin_settingpage('backups', get_string('backups','admin'), 'moodle/site:backup');
$temp = new admin_settingpage('backups', get_string('backups','admin'), 'moodle/backup:backupcourse');
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_modules', get_string('includemodules'), get_string('backupincludemoduleshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_withuserdata', get_string('includemoduleuserdata'), get_string('backupincludemoduleuserdatahelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_metacourse', get_string('metacourse'), get_string('backupmetacoursehelp'), 0));
Expand Down
8 changes: 4 additions & 4 deletions admin/settings/frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
if ($hassiteconfig or has_any_capability(array(
'moodle/course:update',
'moodle/role:assign',
'moodle/site:restore',
'moodle/site:backup',
'moodle/restore:restorecourse',
'moodle/backup:backupcourse',
'moodle/course:managefiles',
'moodle/question:add',
'moodle/question:editmine',
Expand Down Expand Up @@ -65,9 +65,9 @@

$ADMIN->add('frontpage', new admin_externalpage('frontpagefilters', get_string('frontpagefilters', 'admin'), "$CFG->wwwroot/filter/manage.php?contextid=" . $frontpagecontext->id, 'moodle/filter:manage', false, $frontpagecontext));

$ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/site:backup', false, $frontpagecontext));
$ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/backup:backupcourse', false, $frontpagecontext));

$ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&amp;wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
$ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&amp;wdir=/backupdata', 'moodle/restore:restorecourse', false, $frontpagecontext));

$questioncapabilites = array(
'moodle/question:add',
Expand Down
8 changes: 4 additions & 4 deletions backup/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@

if (!empty($id)) {
require_login($id);
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $id))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $id))) {
print_error('cannotuseadminadminorteacher', 'error', $loginurl);
}
} else {
require_login();
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error('cannotuseadmin', 'error', $loginurl);
}
}

if (!empty($to)) {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $to))) {
print_error('cannotuseadminadminorteacher', 'error', $loginurl);
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@
}

//Print header
if (has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
if (has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php'));
$PAGE->navbar->add($strcoursebackup, new moodle_url('/backup/backup.php'));
$PAGE->navbar->add("$course->fullname ($course->shortname)");
Expand Down
10 changes: 5 additions & 5 deletions backup/backup_check.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
$backupuserinfo = false;

if (!empty($course->id)) {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
$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))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
$backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_SYSTEM));
Expand Down Expand Up @@ -71,8 +71,8 @@

}

// 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))) {
// Re-enforce 'moodle/backup:backupcourse' at system context to be able to backup all users
if ($backupprefs->backup_users == 0 and !has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
$backupprefs->backup_users = 1; // users => course
}

Expand Down
6 changes: 3 additions & 3 deletions backup/backup_execute.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
$loginurl = get_login_url();

if (!empty($course->id)) {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
}
Expand Down
8 changes: 4 additions & 4 deletions backup/backup_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
$backupuserinfo = false;

if (!empty($course->id)) {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
$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))) {
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
$backupuserinfo = has_capability('moodle/backup:userinfo', get_context_instance(CONTEXT_SYSTEM));
Expand Down Expand Up @@ -223,7 +223,7 @@
echo "<td align=\"right\" colspan=\"2\"><b>";
echo '<label for="menubackup_users">'.get_string ("users").'</label>';
echo "</b></td><td colspan=\"2\">";
if (has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
if (has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) {
$user_options[0] = get_string("all");
}
$user_options[1] = get_string("course");
Expand Down
2 changes: 1 addition & 1 deletion backup/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

require_login();

require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM));
require_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM));

redirect("$CFG->wwwroot/$CFG->admin/report/backups/index.php", '', 'admin', 1);
6 changes: 3 additions & 3 deletions backup/restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@

if (!empty($id)) {
require_login($id);
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $to))
&& !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
}
Expand Down
14 changes: 7 additions & 7 deletions backup/restore_check.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@

//Check admin
if (!empty($id)) {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $id))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
$restoreuserinfo = has_capability('moodle/restore:userinfo', get_context_instance(CONTEXT_COURSE, $id));
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
$restoreuserinfo = has_capability('moodle/restore:userinfo', get_context_instance(CONTEXT_SYSTEM));
Expand All @@ -228,7 +228,7 @@
}

// Get all the courses the user is able to restore to
$mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true, 'c.sortorder ASC', array('id', 'fullname', 'shortname', 'visible'));
$mycourses = get_user_courses_bycap($USER->id, 'moodle/restore:restorecourse', $accessinfo, true, 'c.sortorder ASC', array('id', 'fullname', 'shortname', 'visible'));

// Calculate if the user can create courses
$cancreatecourses = user_can_create_courses();
Expand All @@ -251,7 +251,7 @@
echo $OUTPUT->heading(get_string("choosecourse"));
echo $OUTPUT->box_start();
foreach ($courses as $course) {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $course->id))) {
continue;
}
if (empty($course->visible)) {
Expand All @@ -271,7 +271,7 @@
//Final access control check
if (empty($restore->course_id) and !$cancreatecourses) {
print_error("cannotrestoreadminorcreator");
} else if (!empty($restore->course_id) and !has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $restore->course_id))) {
} else if (!empty($restore->course_id) and !has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $restore->course_id))) {
print_error("cannotrestoreadminoredit");
}
$show_continue_button = true;
Expand Down Expand Up @@ -326,8 +326,8 @@
}
}

// 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))) {
// Re-enforce 'moodle/restore:restorecourse' at system context to be able to restore all users
if ($restore->users == 0 and !has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
$restore->users = 1; // users => course
}

Expand Down
6 changes: 3 additions & 3 deletions backup/restore_execute.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@

//Check admin
if (!empty($id)) {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $to))
&& !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
}
Expand Down
12 changes: 6 additions & 6 deletions backup/restore_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

//Check admin
if (!empty($id)) {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $id))) {
print_error('cannotuseadminadminorteacher', '', $loginurl);
}
$restoreuserinfo = has_capability('moodle/restore:userinfo', get_context_instance(CONTEXT_COURSE, $id));
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error('cannotuseadmin', '', $loginurl);
}
$restoreuserinfo = has_capability('moodle/restore:userinfo', get_context_instance(CONTEXT_SYSTEM));
Expand Down Expand Up @@ -212,10 +212,10 @@
$accessinfo = get_user_access_sitewide($USER->id);
}

$mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true);
$mycourses = get_user_courses_bycap($USER->id, 'moodle/restore:restorecourse', $accessinfo, true);

// if the user can restore to current course, grant the "current" options
if (has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))){
if (has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $id))){
$restore_restoreto_options[RESTORETO_CURRENT_DELETING] = get_string("currentcoursedeleting");
$restore_restoreto_options[RESTORETO_CURRENT_ADDING] = get_string("currentcourseadding");
}
Expand Down Expand Up @@ -446,8 +446,8 @@
//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 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))) {
//If all users are in the backup file and user has 'moodle/restore:restorecourse' at system level
if ($info->backup_users == "all" and has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
$user_options[0] = get_string("all");
}
$user_options[1] = get_string("course");
Expand Down
6 changes: 3 additions & 3 deletions backup/restore_precheck.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

//Check admin
if (!empty($id)) {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_COURSE, $to))
&& !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
} else {
if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
if (!has_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
}
Expand Down
2 changes: 1 addition & 1 deletion backup/try.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require_login();

require_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM));
require_capability('moodle/restore:restorecourse', get_context_instance(CONTEXT_SYSTEM));

$site = get_site();

Expand Down
4 changes: 2 additions & 2 deletions blocks/admin/block_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ function get_content() {
}

/// Backup this course
if ($course->id!==SITEID and has_capability('moodle/site:backup', $this->page->context)) {
if ($course->id!==SITEID and has_capability('moodle/backup:backupcourse', $this->page->context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$course->id.'">'.get_string('backup').'</a>';
$this->content->icons[]='<img src="'.$OUTPUT->pix_url('i/backup') . '" class="icon" alt="" />';
}

/// Restore to this course
if ($course->id !== SITEID and has_capability('moodle/site:restore', $this->page->context)) {
if ($course->id !== SITEID and has_capability('moodle/restore:restorecourse', $this->page->context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$course->id.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
$this->content->icons[]='<img src="'.$OUTPUT->pix_url('i/restore') . '" class="icon" alt="" />';
}
Expand Down
Loading

0 comments on commit d294000

Please sign in to comment.