From b1a142eab4bf712dbf32fb2f7eb4db5a81e0809a Mon Sep 17 00:00:00 2001 From: David Matamoros Date: Tue, 5 Apr 2022 14:57:03 +0200 Subject: [PATCH] MDL-74317 output: Remove capability checks in edit mode WS - 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. --- editmode.php | 10 +--------- lang/en/deprecated.txt | 1 + lang/en/error.php | 4 +++- lib/classes/external/editmode.php | 30 ++++++------------------------ 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/editmode.php b/editmode.php index 36c340d4f98..4d6f452aa47 100644 --- a/editmode.php +++ b/editmode.php @@ -34,14 +34,6 @@ require_login(); $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); diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index 1b214e0956a..d8bbc611aa8 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -80,3 +80,4 @@ sendingvia,core_message sendingviawhen,core_message close,core_contentbank notflagged,core_question +cannotswitcheditmodeon,core_error diff --git a/lang/en/error.php b/lang/en/error.php index 6b31bda3b47..630ed40252a 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -152,7 +152,6 @@ $string['cannotsetupblock'] = 'Blocks tables could NOT be set up successfully!'; $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}'; @@ -631,3 +630,6 @@ $string['xmldberror'] = 'XMLDB error!'; $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'; diff --git a/lib/classes/external/editmode.php b/lib/classes/external/editmode.php index 06bca19447a..c48ba9d5238 100644 --- a/lib/classes/external/editmode.php +++ b/lib/classes/external/editmode.php @@ -14,15 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * A web service to load the mapping of moodle pix names to fontawesome icon names. - * - * @package core - * @category external - * @copyright 2021 Bas Brands - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace core\external; use external_api; @@ -54,14 +45,14 @@ class editmode extends external_api { } /** - * 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(), @@ -73,19 +64,10 @@ class editmode extends external_api { $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'); - } + $USER->editing = $params['setmode']; - $success = false; - if ($PAGE->user_allowed_editing()) { - $USER->editing = $setmode; - $success = true; - } - - return ['success' => $success]; + return ['success' => true]; } /**