MDL-84126 tiny_accessibilitychecker: Capability check added

This commit is contained in:
David Woloszyn
2025-03-04 15:02:55 +11:00
parent f6f0f0c5b0
commit 6373da43ed
4 changed files with 73 additions and 1 deletions
@@ -0,0 +1,35 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Capabilities for the tiny_accessibilitychecker plugin.
*
* @package tiny_accessibilitychecker
* @copyright 2025 David Woloszyn <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = [
'tiny/accessibilitychecker:use' => [
'captype' => 'read',
'contextlevel' => CONTEXT_USER,
'archetypes' => [
'user' => CAP_ALLOW,
],
],
];
@@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['accessibilitychecker:use'] = 'Use TinyMCE accessibility checker';
$string['emptytext'] = 'Empty text';
$string['entiredocument'] = 'Entire document';
$string['imagesmissingalt'] = 'Images require alternative text. To fix this warning, add an alt attribute to your img tags. An empty alt attribute may be used, but only when the image is purely decorative and carries no information.';
@@ -52,3 +52,39 @@ Feature: Tiny editor accessibility checker
When I set the field "Description" to "<p>Some plain text</p><img src='/broken-image' width='1' height='1' class='behat-tinymce-placeholder'/><p>Some more text</p>"
And I click on the "Tools > Accessibility checker" menu item for the "Description" TinyMCE editor
Then I should see "Congratulations, no accessibility issues found!" in the "Accessibility checker" "dialogue"
@javascript
Scenario: Permissions can be configured to control access to accessibility checker
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/accessibilitychecker: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 "Tools" menu item for the "Activity instructions" TinyMCE editor
Then I should not see "Accessibility checker"
# 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 "Tools" menu item for the "Activity instructions" TinyMCE editor
And I should see "Accessibility checker"
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024121800;
$plugin->version = 2025012300;
$plugin->requires = 2024100100;
$plugin->component = 'tiny_accessibilitychecker';