Add a site-wide switch to disable embedded editing (DEC-0066) - #108
Merged
Conversation
Some sites use the plugin as a pure player: teachers upload .elpx packages authored elsewhere and the site does not want to offer in-place editing. Until now the "Edit with eXeLearning" button appeared for anyone with moodle/course:manageactivities whenever the bundled editor was valid, with no supported way to switch it off. Add the exelearning/editorenabled admin setting (checkbox, default on; an unset config counts as on so upgrades keep today's behaviour). exelearning_embedded_editor_enabled() now combines the toggle with bundle validation, so the edit button, editor/static.php and the create-from-scratch CTA all react to it. Because hiding a button is not an access control, the editor endpoints refuse direct requests too: editor/index.php shows an explanatory error page and editor/save.php aborts through the new exelearning_require_embedded_editor_enabled() guard. Uploading and serving packages is unaffected either way. A site-wide setting was chosen over a new capability (ADR DEC-0066): the "who" is already governed by moodle/course:manageactivities, the real use case is binary and site-wide, and feature switches in admin settings are how activity plugins usually disable whole features. A per-role capability can still be added on top later without breaking anything. Strings added to the five language packs (machine translations carry the ~ review marker). Tests cover the default-on behaviour, the toggle disabling the helper, and the endpoint guard throwing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #108 +/- ##
=========================================
Coverage 92.30% 92.31%
Complexity 824 824
=========================================
Files 51 51
Lines 3730 3734 +4
=========================================
+ Hits 3443 3447 +4
Misses 287 287
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The checkbox's own description already explains the switch; repeating a condensed version in the heading added noise without information.
Review caught the classic new-setting confusion: "Enable the embedded editor" rendered UNTICKED next to "Default: Yes", because a positive default only materialises when upgradesettings runs — until then the stored value is unset and the box contradicts the actual behaviour. Replace editorenabled with editordisabled (default 0, unticked): now the unset config and the unticked checkbox both mean "editing on", on every site and at every moment, with no dependency on when settings were saved. Same pattern as the plugin's existing stylesblockimport toggle. Default behaviour is unchanged: the embedded editor stays enabled unless an admin ticks the box.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new admin setting, Disable the embedded editor (
exelearning/editordisabled, unticked by default), lets a site use the plugin as a pure.elpxplayer: uploading and serving packages keeps working exactly as before, but the "Edit with eXeLearning" button is hidden and the editor endpoints refuse requests.Why a negative checkbox
The first iteration used a positive "Enable the embedded editor" with default Yes — and rendered unticked next to "Default: Yes" on any site where
upgradesettingshad not yet materialised the default, contradicting the real behaviour. With the negative toggle, the unset config and the unticked box always mean the same thing: editing on. Same pattern as the plugin's existingstylesblockimportsetting. The default behaviour is unchanged: the editor stays enabled unless an administrator ticks the box.Why a setting and not a capability
Recorded in ADR DEC-0066 (included in this PR). The who of editing is already governed by
moodle/course:manageactivities, consistent with the rest of the plugin; the real use case is binary and site-wide ("this site does not edit in place"), which is what activity plugins normally express as a feature switch in admin settings. A per-role capability would force sites to edit role definitions for a yes/no decision — and can still be added on top later without breaking anything, with the setting remaining the master switch.How
exelearning_embedded_editor_enabled()now combines the toggle with bundle validation (DEC-0065), so everything that already consulted it reacts at once: the edit button inview.php, the asset routereditor/static.php, and the create-from-scratch CTA (which degrades to the "upload a package" hint).editor/index.phpshows an explanatory error page andeditor/save.php— the state-changing half — aborts through the newexelearning_require_embedded_editor_enabled()guard.~review marker, per repo convention); README,docs/EMBEDDED_EDITOR.mdand the user guide document the switch.Tests
Written first and watched failing: with a valid bundle and the toggle ticked, the helper reports false and the endpoint guard throws
moodle_exception; with no config at all, editing stays on and the guard passes. Suite: 7/7 locally on the helper file (Moodle 5.0.7 / PHP 8.3 / MariaDB),phpcs --standard=moodle0/0 on every touched file.