2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file processes AJAX requests and returns JSON
20 * This is a server part of yui permissions manager module
23 * @copyright 2015 Martin Mastny
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 define('AJAX_SCRIPT', true);
28 require(__DIR__
. '/../../config.php');
30 $contextid = required_param('contextid', PARAM_INT
);
31 $getroles = optional_param('getroles', 0, PARAM_BOOL
);
33 list($context, $course, $cm) = get_context_info_array($contextid);
35 $PAGE->set_context($context);
37 require_login($course, false, $cm);
38 require_capability('moodle/role:review', $context);
43 list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context,
47 echo json_encode($overridableroles);
51 $capability = required_param('capability', PARAM_CAPABILITY
);
52 $roleid = required_param('roleid', PARAM_INT
);
53 $action = required_param('action', PARAM_ALPHA
);
55 $capability = $DB->get_record('capabilities', array('name' => $capability), '*', MUST_EXIST
);
57 if (!isset($overridableroles[$roleid])) {
58 throw new moodle_exception('invalidarguments');
61 if (!has_capability('moodle/role:override', $context)) {
62 if (!has_capability('moodle/role:safeoverride', $context) ||
!is_safe_capability($capability)) {
63 require_capability('moodle/role:override', $context);
69 role_change_permission($roleid, $context, $capability->name
, CAP_ALLOW
);
72 role_change_permission($roleid, $context, $capability->name
, CAP_PREVENT
);
75 role_change_permission($roleid, $context, $capability->name
, CAP_PROHIBIT
);
78 role_change_permission($roleid, $context, $capability->name
, CAP_INHERIT
);
81 throw new moodle_exception('invalidarguments');
84 echo json_encode($action);