Skip to content

Commit

Permalink
Merge branch 'MDL-53566-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Nov 13, 2018
2 parents 50d3763 + bfbd733 commit d27e494
Show file tree
Hide file tree
Showing 26 changed files with 1,120 additions and 70 deletions.
96 changes: 96 additions & 0 deletions admin/lock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file is used to display a categories sub categories, external pages, and settings.
*
* @package admin
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../config.php');
require_once("{$CFG->libdir}/adminlib.php");

$contextid = required_param('id', PARAM_INT);
$confirm = optional_param('confirm', null, PARAM_INT);
$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);

$PAGE->set_url('/admin/lock.php', ['id' => $contextid]);

list($context, $course, $cm) = get_context_info_array($contextid);

$parentcontext = $context->get_parent_context();
if ($parentcontext && !empty($parentcontext->locked)) {
// Can't make changes to a context whose parent is locked.
throw new \coding_exception('Not sure how you got here');
}

if ($course) {
$isfrontpage = ($course->id == SITEID);
} else {
$isfrontpage = false;
$course = $SITE;
}

require_login($course, false, $cm);
require_capability('moodle/site:managecontextlocks', $context);

$PAGE->set_pagelayout('admin');
$PAGE->navigation->clear_cache();

$a = (object) [
'contextname' => $context->get_context_name(),
];

if (null !== $confirm && confirm_sesskey()) {
$context->set_locked(!empty($confirm));

if ($context->locked) {
$lockmessage = get_string('managecontextlocklocked', 'admin', $a);
} else {
$lockmessage = get_string('managecontextlockunlocked', 'admin', $a);
}

if (empty($returnurl)) {
$returnurl = $context->get_url();
} else {
$returnurl = new moodle_url($returnurl);
}
redirect($returnurl, $lockmessage);
}

$heading = get_string('managecontextlock', 'admin');
$PAGE->set_title($heading);
$PAGE->set_heading($heading);

echo $OUTPUT->header();

if ($context->locked) {
$confirmstring = get_string('confirmcontextunlock', 'admin', $a);
$target = 0;
} else {
$confirmstring = get_string('confirmcontextlock', 'admin', $a);
$target = 1;
}

$confirmurl = new \moodle_url($PAGE->url, ['confirm' => $target]);
if (!empty($returnurl)) {
$confirmurl->param('returnurl', $returnurl);
}

echo $OUTPUT->confirm($confirmstring, $confirmurl, $context->get_url());
echo $OUTPUT->footer();
10 changes: 10 additions & 0 deletions admin/settings/development.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

$temp->add(new admin_setting_configexecutable('pathtosassc', new lang_string('pathtosassc', 'admin'), new lang_string('pathtosassc_help', 'admin'), ''));

$temp->add(new admin_setting_configcheckbox('contextlocking', new lang_string('contextlocking', 'core_admin'),
new lang_string('contextlocking_desc', 'core_admin'), 0));

$temp->add(new admin_setting_configcheckbox(
'contextlockappliestoadmin',
new lang_string('contextlockappliestoadmin', 'core_admin'),
new lang_string('contextlockappliestoadmin_desc', 'core_admin'),
1
));

$temp->add(new admin_setting_configcheckbox('forceclean', new lang_string('forceclean', 'core_admin'),
new lang_string('forceclean_desc', 'core_admin'), 0));

Expand Down
10 changes: 9 additions & 1 deletion admin/tool/monitor/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,15 @@ function tool_monitor_get_user_courses() {
$options[0] = get_string('site');
}

$fields = 'fullname, visible, ctxid, ctxpath, ctxdepth, ctxlevel, ctxinstance';
$fieldlist = array_merge(
[
'fullname',
'visible',
],
array_values(context_helper::get_preload_record_columns('c'))
);

$fields = implode(', ', $fieldlist);
if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, $fields, $orderby)) {
foreach ($courses as $course) {
context_helper::preload_from_record($course);
Expand Down
2 changes: 1 addition & 1 deletion cohort/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,4 @@ function cohort_get_list_of_themes() {
}
}
return $themes;
}
}
3 changes: 3 additions & 0 deletions course/classes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public static function get($id, $strictness = MUST_EXIST, $alwaysreturnhidden =
$record->visible = 1;
$record->depth = 0;
$record->path = '';
$record->locked = 0;
self::$coursecat0 = new self($record);
}
return self::$coursecat0;
Expand Down Expand Up @@ -2458,6 +2459,7 @@ public function prepare_to_cache() {
$context = $this->get_context();
$a['xi'] = $context->id;
$a['xp'] = $context->path;
$a['xl'] = $context->locked;
return $a;
}

Expand Down Expand Up @@ -2486,6 +2488,7 @@ public static function wake_from_cache($a) {
$record->ctxdepth = $record->depth + 1;
$record->ctxlevel = CONTEXT_COURSECAT;
$record->ctxinstance = $record->id;
$record->ctxlocked = $a['xl'];
return new self($record, true);
}

Expand Down
24 changes: 24 additions & 0 deletions course/classes/management/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public static function get_course_detail_array(\core_course_list_element $course
* @return array
*/
public static function get_category_listitem_actions(\core_course_category $category) {
global $CFG;

$manageurl = new \moodle_url('/course/management.php', array('categoryid' => $category->id));
$baseurl = new \moodle_url($manageurl, array('sesskey' => \sesskey()));
$actions = array();
Expand Down Expand Up @@ -280,6 +282,28 @@ public static function get_category_listitem_actions(\core_course_category $cate
);
}

// Context locking.
if (!empty($CFG->contextlocking) && has_capability('moodle/site:managecontextlocks', $category->get_context())) {
$parentcontext = $category->get_context()->get_parent_context();
if (empty($parentcontext) || !$parentcontext->locked) {
if ($category->get_context()->locked) {
$lockicon = 'i/unlock';
$lockstring = get_string('managecontextunlock', 'admin');
} else {
$lockicon = 'i/lock';
$lockstring = get_string('managecontextlock', 'admin');
}
$actions['managecontextlock'] = [
'url' => new \moodle_url('/admin/lock.php', [
'id' => $category->get_context()->id,
'returnurl' => $manageurl->out_as_local_url(false),
]),
'icon' => new \pix_icon($lockicon, $lockstring),
'string' => $lockstring,
];
}
}

// Cohorts.
if ($category->can_review_cohorts()) {
$actions['cohorts'] = array(
Expand Down
10 changes: 10 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,14 @@
$string['configwarning'] = 'Be careful modifying these settings - strange values could cause problems.';
$string['configyuicomboloading'] = 'This options enables combined file loading optimisation for YUI libraries. This setting should be enabled on production sites for performance reasons.';
$string['confirmation'] = 'Confirmation';
$string['confirmcontextlock'] = '{$a->contextname} is currently unlocked. Locking it will prevent any further changes. Are you sure you wish to continue?';
$string['confirmcontextunlock'] = '{$a->contextname} is currently locked. Unlocking it will allow users to make changes. Are you sure you wish to continue?';
$string['confirmdeletecomments'] = 'You are about to delete comments, are you sure?';
$string['confirmed'] = 'Confirmed';
$string['contextlocking'] = 'Context locking';
$string['contextlocking_desc'] = 'This setting allows you to lock categories, courses, activites, and blocks within the site by removing all write-access to those locations.';
$string['contextlockappliestoadmin'] = 'Context locking applies to administrators';
$string['contextlockappliestoadmin_desc'] = 'This setting allows administrators to make changes in any context which is locked.';
$string['cookiehttponly'] = 'Only http cookies';
$string['cookiesecure'] = 'Secure cookies only';
$string['country'] = 'Default country';
Expand Down Expand Up @@ -718,6 +724,10 @@
$string['maintenancemodeisscheduledlong'] = 'This site will be switched to maintenance mode in {$a->hour} hours {$a->min} mins {$a->sec} secs';
$string['maintfileopenerror'] = 'Error opening maintenance files!';
$string['maintinprogress'] = 'Maintenance is in progress...';
$string['managecontextlock'] = 'Lock this context';
$string['managecontextlocklocked'] = '{$a->contextname}, and all of its children are now locked.';
$string['managecontextlockunlocked'] = '{$a->contextname}, and all of its children are now unlocked.';
$string['managecontextunlock'] = 'Unlock this context';
$string['manageformats'] = 'Manage course formats';
$string['manageformatsgotosettings'] = 'Default format can be changed in {$a}';
$string['managelang'] = 'Manage';
Expand Down
1 change: 1 addition & 0 deletions lang/en/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
$string['site:manageallmessaging'] = 'Add, remove, block and unblock contacts for any user';
$string['site:manageblocks'] = 'Manage blocks on a page';
$string['site:messageanyuser'] = 'Bypass user privacy preferences for messaging any user';
$string['site:managecontextlocks'] = 'Manage locking of contexts';
$string['site:mnetloginfromremote'] = 'Login from a remote application via MNet';
$string['site:mnetlogintoremote'] = 'Roam to a remote application via MNet';
$string['site:readallmessages'] = 'Read all messages on site';
Expand Down
Loading

0 comments on commit d27e494

Please sign in to comment.