Skip to content

Commit

Permalink
MDL-74317 output: Remove capability checks in edit mode WS
Browse files Browse the repository at this point in the history
- Removed validation on the change edit mode WS. Permission should
be handled where the edit button is rendered in order to show or not
the button.
  • Loading branch information
dravek committed May 2, 2022
1 parent 1a74403 commit b1a142e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
10 changes: 1 addition & 9 deletions editmode.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@
$context = \context_helper::instance_by_id($contextid);
$PAGE->set_context($context);

if ($context->id === \context_user::instance($USER->id)->id) {
$PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
}

if ($PAGE->user_allowed_editing()) {
$USER->editing = $setmode;
} else {
\core\notification::add(get_string('cannotswitcheditmodeon', 'error'), \core\notification::ERROR);
}
$USER->editing = $setmode;

redirect($pageurl);
1 change: 1 addition & 0 deletions lang/en/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ sendingvia,core_message
sendingviawhen,core_message
close,core_contentbank
notflagged,core_question
cannotswitcheditmodeon,core_error
4 changes: 3 additions & 1 deletion lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
$string['cannotsetupcapformod'] = 'Could not set up the capabilities for {$a}';
$string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for {$a}';
$string['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in category {$a}.';
$string['cannotswitcheditmodeon'] = 'Could not switch edit mode on';
$string['cannotsignup'] = 'You cannot create a new account because you are already logged in as {$a}.';
$string['cannotunassigncap'] = 'Could not unassign deprecated capability {$a->cap} from role {$a->role}';
$string['cannotunassignrolefrom'] = 'Cannot unassign this user from role id: {$a}';
Expand Down Expand Up @@ -631,3 +630,6 @@
$string['alreadyloggedin'] = 'You are already logged in as {$a}, you need to log out before logging in as different user.';
$string['youcannotdeletecategory'] = 'You cannot delete category \'{$a}\' because you can neither delete the contents, nor move them elsewhere.';
$string['protected_cc_not_supported'] = 'Protected cartridges not supported.';

// Deprecated since Moodle 4.1.
$string['cannotswitcheditmodeon'] = 'Could not switch edit mode on';
30 changes: 6 additions & 24 deletions lib/classes/external/editmode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* A web service to load the mapping of moodle pix names to fontawesome icon names.
*
* @package core
* @category external
* @copyright 2021 Bas Brands <bas@sonsbeekmedia.nl>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core\external;

use external_api;
Expand Down Expand Up @@ -54,14 +45,14 @@ public static function change_editmode_parameters(): external_function_parameter
}

/**
* Save the image and return any warnings and the new image url
* Set the given edit mode
*
* @param bool $setmode the current edit mode
* @param bool $setmode the new edit mode
* @param int $contextid the current page context id
* @return array the new edit mode.
* @return array
*/
public static function change_editmode(bool $setmode, int $contextid): array {
global $USER, $PAGE;
global $USER;

$params = self::validate_parameters(
self::change_editmode_parameters(),
Expand All @@ -73,19 +64,10 @@ public static function change_editmode(bool $setmode, int $contextid): array {

$context = \context_helper::instance_by_id($params['context']);
self::validate_context($context);
$PAGE->set_context($context);

if ($context->id === \context_user::instance($USER->id)->id) {
$PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
}

$success = false;
if ($PAGE->user_allowed_editing()) {
$USER->editing = $setmode;
$success = true;
}
$USER->editing = $params['setmode'];

return ['success' => $success];
return ['success' => true];
}

/**
Expand Down

0 comments on commit b1a142e

Please sign in to comment.