diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml new file mode 100644 index 0000000..0bcdff7 --- /dev/null +++ b/.github/workflows/moodle-ci.yml @@ -0,0 +1,119 @@ +name: Moodle Plugin CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-20.04 + + services: + postgres: + image: postgres:13 + env: + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 + mariadb: + image: mariadb:10.6.7 + env: + MYSQL_USER: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + + strategy: + fail-fast: false + matrix: + include: + - php: '8.1' + moodle-branch: 'master' + database: 'pgsql' + - php: '8.1' + moodle-branch: 'master' + database: 'mariadb' + - php: '8.1' + moodle-branch: 'MOODLE_403_STABLE' + database: 'pgsql' + - php: '8.0' + moodle-branch: 'MOODLE_403_STABLE' + database: 'mariadb' + - php: '8.0' + moodle-branch: 'MOODLE_402_STABLE' + database: 'pgsql' + - php: '8.0' + moodle-branch: 'MOODLE_401_STABLE' + database: 'mariadb' + + steps: + - name: Check out repository code + uses: actions/checkout@v2 + with: + path: plugin + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + ini-values: max_input_vars=6000 + coverage: none + + - name: Initialise moodle-plugin-ci + run: | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + echo $(cd ci/bin; pwd) >> $GITHUB_PATH + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH + sudo locale-gen en_AU.UTF-8 + + - name: Install moodle-plugin-ci + run: | + moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + env: + DB: ${{ matrix.database }} + MOODLE_BRANCH: ${{ matrix.moodle-branch }} + + - name: PHP Lint + if: ${{ always() }} + run: moodle-plugin-ci phplint + + # - name: PHP Copy/Paste Detector + #if: ${{ always() }} + #run: moodle-plugin-ci phpcpd + + - name: PHP Mess Detector + if: ${{ always() }} + run: moodle-plugin-ci phpmd + + - name: Moodle Code Checker + if: ${{ always() }} + run: moodle-plugin-ci codechecker --max-warnings 0 + + - name: Moodle PHPDoc Checker + if: ${{ always() }} + run: moodle-plugin-ci phpdoc + + - name: Validating + if: ${{ always() }} + run: moodle-plugin-ci validate + + - name: Check upgrade savepoints + if: ${{ always() }} + run: moodle-plugin-ci savepoints + + - name: Mustache Lint + if: ${{ always() }} + run: moodle-plugin-ci mustache + + - name: Grunt + if: ${{ matrix.moodle-branch == 'MOODLE_403_STABLE' }} + run: moodle-plugin-ci grunt + + - name: PHPUnit tests + if: ${{ always() }} + run: moodle-plugin-ci phpunit + + - name: Behat features + if: ${{ always() }} + run: moodle-plugin-ci behat --profile chrome diff --git a/classes/form/edit_resource.php b/classes/form/edit_resource.php index e75983d..e95f13f 100644 --- a/classes/form/edit_resource.php +++ b/classes/form/edit_resource.php @@ -24,6 +24,7 @@ namespace tool_mediatime\form; +use context_system; use moodleform; /** @@ -39,6 +40,7 @@ class edit_resource extends moodleform { */ public function definition() { $mform = $this->_form; + require_capability('tool/mediatime:manage', context_system::instance()); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); @@ -50,6 +52,9 @@ public function definition() { $mform->setType('name', PARAM_TEXT); } + /** + * Add tag elements + */ protected function tag_elements() { $mform = $this->_form; diff --git a/classes/form/select_source.php b/classes/form/select_source.php deleted file mode 100644 index 1d7b647..0000000 --- a/classes/form/select_source.php +++ /dev/null @@ -1,51 +0,0 @@ -. - -/** - * Media Time media source selector - * - * @package tool_mediatime - * @copyright 2024 bdecent gmbh - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace tool_mediatime\form; - -use moodleform; -use tool_mediatime\plugininfo\mediatimesrc; - -/** - * Media Time media source selector - * - * @copyright 2024 bdecent gmbh - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class select_source extends moodleform { - - /** - * Definition - */ - public function definition() { - $mform = $this->_form; - - $options = []; - foreach (mediatimesrc::get_enabled_plugins() as $plugin) { - $options[$plugin] = get_string("pluginname", "mediatimesrc_$plugin"); - } - $mform->addElement('select', 'source', get_string('source', 'tool_mediatime'), $options); - $this->add_action_buttons(false); - } -} diff --git a/classes/media_manager.php b/classes/media_manager.php index 6e96613..a6f0bae 100644 --- a/classes/media_manager.php +++ b/classes/media_manager.php @@ -24,6 +24,7 @@ namespace tool_mediatime; +use context_system; use moodle_exception; use moodle_url; use renderable; @@ -61,6 +62,8 @@ public function __construct(string $source, ?stdClass $record = null, int $page $this->page = $page; $this->record = $record; + + require_capability('tool/mediatime:view', context_system::instance()); if ($record) { $source = $record->source; } @@ -100,7 +103,7 @@ public function export_for_template(renderer_base $output): array { 'libraryhome' => (new moodle_url('/admin/tool/mediatime/index.php'))->out(), 'resource' => $output->render($this->source), ]; - if (!empty($this->record)) { + if (!empty($this->record) && empty(optional_param('edit', null, PARAM_INT))) { $resource = new output\media_resource($this->record); $context['tags'] = $resource->tags($output); } @@ -121,19 +124,14 @@ public function export_for_template(renderer_base $output): array { } $plugins = \core_plugin_manager::instance()->get_installed_plugins('mediatimesrc'); - $sources = []; - foreach (array_keys($plugins) as $plugin) { - $sources[] = [ - 'name' => $plugin, - 'title' => get_string('pluginname', "mediatimesrc_$plugin"), - ]; - } $options = []; foreach (plugininfo\mediatimesrc::get_enabled_plugins() as $plugin) { $options[$plugin] = get_string("pluginname", "mediatimesrc_$plugin"); } - if (count($options) == 1) { + if (!has_capability('tool/mediatime:manage', context_system::instance())) { + $action = ''; + } else if (count($options) == 1) { $button = new single_button(new moodle_url('/admin/tool/mediatime/index.php', [ 'source' => array_keys($options)[0], ]), get_string('addnewcontent', 'tool_mediatime')); @@ -146,7 +144,6 @@ public function export_for_template(renderer_base $output): array { } return [ 'media' => array_values($media), - 'sources' => $sources, 'action' => $action, ]; } diff --git a/classes/output/media_resource.php b/classes/output/media_resource.php index 706fe41..c08d773 100644 --- a/classes/output/media_resource.php +++ b/classes/output/media_resource.php @@ -66,7 +66,7 @@ public function export_for_template(renderer_base $output) { $context = \context_system::instance(); return [ - 'canedit' => has_capability('moodle/tag:edit', $context) || $USER->id == $this->record->usermodified, + 'canedit' => has_capability('tool/mediatime:manage', $context) || ($USER->id == $this->record->usermodified), 'id' => $this->record->id, 'libraryhome' => new moodle_url('/admin/tool/mediatime/index.php'), 'resource' => $output->render($this->resource), @@ -74,6 +74,12 @@ public function export_for_template(renderer_base $output) { ]; } + /** + * Return rendered tag elements for template + * + * @param \renderer_base $output + * @return string + */ public function tags($output) { return $output->tag_list( core_tag_tag::get_item_tags( @@ -86,14 +92,32 @@ public function tags($output) { ); } + /** + * Return url for video content + * + * @param \renderer_base $output + * @return string url + */ public function video_url($output) { return $this->resource->video_url($output); } + /** + * Return url for poster image + * + * @param \renderer_base $output + * @return string url + */ public function image_url($output) { return $this->resource->image_url($output); } + /** + * Return video file content + * + * @param \renderer_base $output + * @return string url + */ public function video_file_content($output) { return $this->resource->video_file_content($output); } diff --git a/db/access.php b/db/access.php index d513506..1f1c900 100644 --- a/db/access.php +++ b/db/access.php @@ -37,8 +37,8 @@ 'clonepermissionsfrom' => 'moodle/blog:create', ], - 'tool/mediatime:upload' => [ - 'riskbitmask' => RISK_SPAM | RISK_XSS, + 'tool/mediatime:manage' => [ + 'riskbitmask' => RISK_SPAM | RISK_XSS | RISK_DATALOSS, 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => [ @@ -46,4 +46,13 @@ ], 'clonepermissionsfrom' => 'moodle/blog:manageentries', ], + + 'tool/mediatime:view' => [ + 'captype' => 'read', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => [ + 'coursecreator' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/blog:manageentries', + ], ]; diff --git a/index.php b/index.php index e6c7a30..85d4041 100644 --- a/index.php +++ b/index.php @@ -27,7 +27,7 @@ use tool_mediatime\media_manager; -require_admin(); +require_login(); $source = optional_param('source', '', PARAM_ALPHANUMEXT); $id = optional_param('id', null, PARAM_INT); @@ -35,6 +35,7 @@ admin_externalpage_setup('mediatimelibrary'); +$PAGE->set_heading(get_string('pluginname', 'tool_mediatime')); if ($id) { $record = $DB->get_record('tool_mediatime', ['id' => $id]); } else if ($edit) { diff --git a/lang/en/tool_mediatime.php b/lang/en/tool_mediatime.php index 5812a25..521c2b3 100644 --- a/lang/en/tool_mediatime.php +++ b/lang/en/tool_mediatime.php @@ -28,6 +28,9 @@ $string['pluginname'] = 'Media Time'; $string['addnewcontent'] = 'Add new content'; $string['library'] = 'Library'; +$string['mediatime:create'] = 'Create media in library'; +$string['mediatime:manage'] = 'Manage media in library'; +$string['mediatime:view'] = 'View media in library'; $string['resourcename'] = 'Resource name'; $string['resourcename_help'] = 'The name for a resource is used internally in the library to identify the resource, but not displayed when it is used.'; $string['managemediatimesrcplugins'] = 'Manage source plugins'; diff --git a/lib.php b/lib.php index 0e79539..fc1af86 100644 --- a/lib.php +++ b/lib.php @@ -63,6 +63,16 @@ function tool_mediatime_pluginfile($course, $cm, $context, $filearea, $args, $fo } } +/** + * Return tagged resources + * + * @return array List of file areas + */ +function tool_mediatime_get_tagged_resources() { + return [ + ]; +} + /** * Return file areas for backup * diff --git a/settings.php b/settings.php index 456a6a3..c676857 100644 --- a/settings.php +++ b/settings.php @@ -49,9 +49,12 @@ foreach ($pluginmanager->get_plugins_of_type('mediatimesrc') as $plugin) { $plugin->load_settings($ADMIN, 'mediatimesrcplugins', $hassiteconfig); } - - $ADMIN->add('toolmediatime', new admin_externalpage('mediatimelibrary', get_string('library', 'tool_mediatime'), - $CFG->wwwroot . "/admin/tool/mediatime/index.php", 'report/log:view')); - $settings = null; } + +$ADMIN->add('reports', new admin_externalpage( + 'mediatimelibrary', + get_string('pluginname', 'tool_mediatime'), + $CFG->wwwroot . "/admin/tool/mediatime/index.php", + 'tool/mediatime:view' +)); diff --git a/source/file/classes/output/media_resource.php b/source/file/classes/output/media_resource.php index 3d270c6..aee0a10 100644 --- a/source/file/classes/output/media_resource.php +++ b/source/file/classes/output/media_resource.php @@ -77,6 +77,12 @@ public function export_for_template(renderer_base $output) { ]; } + /** + * Return url for video content + * + * @param \renderer_base $output + * @return string url + */ public function image_url($output) { $fs = get_file_storage(); @@ -97,6 +103,12 @@ public function image_url($output) { return $this->poster; } + /** + * Return url for poster image + * + * @param \renderer_base $output + * @return string url + */ public function video_url($output) { $this->videourl = ''; @@ -117,6 +129,12 @@ public function video_url($output) { return $this->videourl; } + /** + * Return video file content + * + * @param \renderer_base $output + * @return string url + */ public function video_file_content($output) { $this->videourl = ''; diff --git a/source/file/templates/video.mustache b/source/file/templates/video.mustache index 3e39218..bfc546c 100644 --- a/source/file/templates/video.mustache +++ b/source/file/templates/video.mustache @@ -31,6 +31,7 @@

- - -
- {{ content.name }} + {{# content.name }} + {{ content.name }} + {{/ content.name }} + {{^ content.name }} + {{ content.title }} + {{/ content.name }}
+ + +

{{ content.description }}

diff --git a/version.php b/version.php index 78a7831..b0e8cec 100644 --- a/version.php +++ b/version.php @@ -26,6 +26,6 @@ $plugin->component = 'tool_mediatime'; $plugin->release = '1.0'; -$plugin->version = 2024010800; +$plugin->version = 2024010802; $plugin->requires = 2022112800; $plugin->maturity = MATURITY_ALPHA;