From 2e26f038e626c90eb66c8943b6f08c4ef330c6e7 Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Tue, 28 Jan 2025 14:30:27 +1100 Subject: [PATCH] MDL-84126 tiny_link: Capability check added --- .../tiny/plugins/link/classes/plugininfo.php | 1 - lib/editor/tiny/plugins/link/db/access.php | 35 ++++++++++++++++++ .../tiny/plugins/link/lang/en/tiny_link.php | 1 + .../plugins/link/tests/behat/link.feature | 36 +++++++++++++++++++ lib/editor/tiny/plugins/link/version.php | 2 +- 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 lib/editor/tiny/plugins/link/db/access.php diff --git a/lib/editor/tiny/plugins/link/classes/plugininfo.php b/lib/editor/tiny/plugins/link/classes/plugininfo.php index 65b5aca9343..4fe999eeb61 100644 --- a/lib/editor/tiny/plugins/link/classes/plugininfo.php +++ b/lib/editor/tiny/plugins/link/classes/plugininfo.php @@ -25,7 +25,6 @@ namespace tiny_link; use context; -use context_system; use editor_tiny\editor; use editor_tiny\plugin; use editor_tiny\plugin_with_buttons; diff --git a/lib/editor/tiny/plugins/link/db/access.php b/lib/editor/tiny/plugins/link/db/access.php new file mode 100644 index 00000000000..63259e1be07 --- /dev/null +++ b/lib/editor/tiny/plugins/link/db/access.php @@ -0,0 +1,35 @@ +. + +/** + * Capabilities for the tiny_link plugin. + * + * @package tiny_link + * @copyright 2025 David Woloszyn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$capabilities = [ + 'tiny/link:use' => [ + 'captype' => 'read', + 'contextlevel' => CONTEXT_USER, + 'archetypes' => [ + 'user' => CAP_ALLOW, + ], + ], +]; diff --git a/lib/editor/tiny/plugins/link/lang/en/tiny_link.php b/lib/editor/tiny/plugins/link/lang/en/tiny_link.php index 53597824876..e1514eb5a34 100644 --- a/lib/editor/tiny/plugins/link/lang/en/tiny_link.php +++ b/lib/editor/tiny/plugins/link/lang/en/tiny_link.php @@ -28,6 +28,7 @@ $string['enterurl'] = 'Enter a URL'; $string['openinnewwindow'] = 'Open in new window'; $string['pluginname'] = 'Link'; $string['link'] = 'Link'; +$string['link:use'] = 'Use TinyMCE link'; $string['unlink'] = 'Unlink'; $string['updatelink'] = 'Update link'; $string['privacy:metadata'] = 'The link plugin for TinyMCE does not store any personal data.'; diff --git a/lib/editor/tiny/plugins/link/tests/behat/link.feature b/lib/editor/tiny/plugins/link/tests/behat/link.feature index a08c529319a..76c1907cc5e 100644 --- a/lib/editor/tiny/plugins/link/tests/behat/link.feature +++ b/lib/editor/tiny/plugins/link/tests/behat/link.feature @@ -153,3 +153,39 @@ Feature: Add links to TinyMCE And I select the "a" element in position "0" of the "Description" TinyMCE editor When I click on the "Unlink" button for the "Description" TinyMCE editor Then the field "Description" matches value "

Moodle - Open-source learning platform

" + + @javascript + Scenario: Permissions can be configured to control access to link + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | teacher2 | Teacher | 2 | teacher2@example.com | + And the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "roles" exist: + | name | shortname | description | archetype | + | Custom teacher | custom1 | Limited permissions | editingteacher | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | teacher2 | C1 | custom1 | + And the following "activity" exists: + | activity | assign | + | course | C1 | + | name | Test assignment | + And the following "permission overrides" exist: + | capability | permission | role | contextlevel | reference | + | tiny/link:use | Prohibit | custom1 | Course | C1 | + # Check plugin access as a role with prohibited permissions. + And I log in as "teacher2" + And I am on the "Test assignment" Activity page + And I navigate to "Settings" in current page administration + When I click on the "Insert" menu item for the "Activity instructions" TinyMCE editor + Then I should not see "Link" + # Check plugin access as a role with allowed permissions. + And I log in as "teacher1" + And I am on the "Test assignment" Activity page + And I navigate to "Settings" in current page administration + And I click on the "Insert" menu item for the "Activity instructions" TinyMCE editor + And I should see "Link" diff --git a/lib/editor/tiny/plugins/link/version.php b/lib/editor/tiny/plugins/link/version.php index 31461bb6b1e..d14249dc7de 100644 --- a/lib/editor/tiny/plugins/link/version.php +++ b/lib/editor/tiny/plugins/link/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024121800; +$plugin->version = 2025012300; $plugin->requires = 2024100100; $plugin->component = 'tiny_link';