Skip to content

Commit

Permalink
MDL-79709 tiny_premium: Capability to access Tiny Premium features
Browse files Browse the repository at this point in the history
  • Loading branch information
davewoloszyn committed Dec 10, 2023
1 parent a891866 commit 4116a75
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/editor/tiny/plugins/premium/classes/plugininfo.php
Expand Up @@ -30,7 +30,7 @@
class plugininfo extends plugin {

/**
* Determine if the plugin should be enabled by checking if the Tiny Premium API key is set.
* Determine if the plugin should be enabled by checking the capability and if the Tiny Premium API key is set.
*
* @param context $context The context that the editor is used within
* @param array $options The options passed in when requesting the editor
Expand All @@ -44,6 +44,6 @@ public static function is_enabled(
array $fpoptions,
?editor $editor = null
): bool {
return get_config('tiny_premium', 'apikey') != false;
return has_capability('tiny/premium:accesspremium', $context) && (get_config('tiny_premium', 'apikey') != false);
}
}
35 changes: 35 additions & 0 deletions lib/editor/tiny/plugins/premium/db/access.php
@@ -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/>.

/**
* Tiny premium capabilities.
*
* @package tiny_premium
* @copyright 2023 David Woloszyn <david.woloszyn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$capabilities = [
'tiny/premium:accesspremium' => [
'captype' => 'read',
'contextlevel' => CONTEXT_USER,
'archetypes' => [
'user' => CAP_ALLOW,
],
],
];
1 change: 1 addition & 0 deletions lib/editor/tiny/plugins/premium/lang/en/tiny_premium.php
Expand Up @@ -28,4 +28,5 @@
$string['pluginname'] = 'Tiny premium';
$string['apikey'] = 'API key';
$string['apikey_desc'] = 'Your Tiny premium API key requires a paid subscription. You can find your key on your Tiny Cloud account page.';
$string['premium:accesspremium'] = 'Access Tiny Premium features';
$string['privacy:metadata'] = 'The Tiny premium plugin for TinyMCE does not store any personal data.';
2 changes: 1 addition & 1 deletion lib/editor/tiny/plugins/premium/version.php
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023100900;
$plugin->version = 2023111300;
$plugin->requires = 2023100400;
$plugin->component = 'tiny_premium';

0 comments on commit 4116a75

Please sign in to comment.