Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capabilities to control the Kaltura button in HTML editors #379

Open
wants to merge 3 commits into
base: MOODLE_311_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/editor/atto/plugins/kalturamedia/db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
// 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/>.

/**
* Kaltura video embedding TinyMCE button accesslib.
*
* @package tinymce_kalturamedia
* @author https://github.com/estevebadia
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2022 switch.ch
*/

$capabilities = array(
'atto/kalturamedia:insert' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
),
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
$string['embedbuttontext'] = 'Embed';
$string['browse_and_embed'] = 'Browse and Embed';
$string['privacy:metadata'] = 'The atto_kalturamedia plugin does not store any personal data.';
$string['kalturamedia:insert'] = 'Insert media from Kaltura in Atto editor';
5 changes: 3 additions & 2 deletions lib/editor/atto/plugins/kalturamedia/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ function atto_kalturamedia_params_for_js($elementid, $options, $fpoptions) {
if (!$context) {
$context = context_system::instance();
}

return array(
'enabled' => has_capability('atto/kalturamedia:insert', $context),
'contextid' => $context->id,
'kafuri' => local_kaltura_get_config()->kaf_uri
);
);
}
4 changes: 2 additions & 2 deletions lib/editor/atto/plugins/kalturamedia/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

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

$plugin->version = 2021051703; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 'Kaltura release 4.3.2';
$plugin->version = 2021051704; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 'Kaltura release 4.3.3';
$plugin->requires = 2018120300; // Requires this Moodle version.
$plugin->component = 'atto_kalturamedia'; // Full name of the plugin (used for diagnostics).
$plugin->dependencies = array(
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a
embedWindow: null,

initializer: function() {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
if (this.get('enabled')) {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
}
},
_kalturamedia: function() {
this._currentSelection = this.get('host').getSelection();
Expand Down Expand Up @@ -132,6 +134,12 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a

} , {
ATTRS: {
/**
* Whether to enable the button.
*/
enabled: {
value: false
},
/**
* The contextid to use when generating this preview.
*
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a
embedWindow: null,

initializer: function() {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
if (this.get('enabled')) {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
}
},
_kalturamedia: function() {
this._currentSelection = this.get('host').getSelection();
Expand Down Expand Up @@ -132,6 +134,12 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a

} , {
ATTRS: {
/**
* Whether to enable the button.
*/
enabled: {
value: false
},
/**
* The contextid to use when generating this preview.
*
Expand Down
18 changes: 13 additions & 5 deletions lib/editor/atto/plugins/kalturamedia/yui/src/button/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a
embedWindow: null,

initializer: function() {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
if (this.get('enabled')) {
this.addButton({
icon: 'icon',
iconComponent: COMPONENTNAME,
callback: this._kalturamedia
});
}
},
_kalturamedia: function() {
this._currentSelection = this.get('host').getSelection();
Expand Down Expand Up @@ -130,6 +132,12 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a

} , {
ATTRS: {
/**
* Whether to enable the button.
*/
enabled: {
value: false
},
/**
* The contextid to use when generating this preview.
*
Expand Down
35 changes: 35 additions & 0 deletions lib/editor/tinymce/plugins/kalturamedia/db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
// 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/>.

/**
* Kaltura video embedding TinyMCE button accesslib.
*
* @package tinymce_kalturamedia
* @author https://github.com/estevebadia
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2022 switch.ch
*/

$capabilities = array(
'tinymce/kalturamedia:insert' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
),
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
$string['kalturamedia:cancelbtn'] = 'Cancel';
$string['kalturamedia:bse'] = 'Browse and Embed';
$string['privacy:metadata'] = 'The TinyMCE Kaltura Media plugin does not store any personal data.';
$string['kalturamedia:insert'] = 'Insert media from Kaltura in TinyMCE editor';
7 changes: 6 additions & 1 deletion lib/editor/tinymce/plugins/kalturamedia/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class tinymce_kalturamedia extends editor_tinymce_plugin {
* @param array $options Options for this editor
*/
protected function update_init_params(array &$params, context $context, array $options = null) {
// Check user has media insert capability.
if (!has_capability('tinymce/kalturamedia:insert', $context)) {
return;
}

$params['lti_launch_context_id'] = $context->id;

// Add button after 'unlink' in Moodlemedia
Expand All @@ -66,4 +71,4 @@ protected function update_init_params(array &$params, context $context, array $o
protected function get_sort_order() {
return 111;
}
}
}
4 changes: 2 additions & 2 deletions lib/editor/tinymce/plugins/kalturamedia/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

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

$plugin->version = 2021051703;
$plugin->release = 'Kaltura release 4.3.2';
$plugin->version = 2021051704;
$plugin->release = 'Kaltura release 4.3.3';
// Required Moodle version.
$plugin->requires = 2018120300;
// Full name of the plugin (used for diagnostics).
Expand Down