Skip to content

Commit

Permalink
MED-11: Implement more capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Jan 20, 2024
1 parent 51aace4 commit cf5ea7a
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 96 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace tool_mediatime\form;

use context_system;
use moodleform;

/**
Expand All @@ -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);
Expand All @@ -50,6 +52,9 @@ public function definition() {
$mform->setType('name', PARAM_TEXT);
}

/**
* Add tag elements
*/
protected function tag_elements() {
$mform = $this->_form;

Expand Down
51 changes: 0 additions & 51 deletions classes/form/select_source.php

This file was deleted.

17 changes: 7 additions & 10 deletions classes/media_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace tool_mediatime;

use context_system;
use moodle_exception;
use moodle_url;
use renderable;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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'));
Expand All @@ -146,7 +144,6 @@ public function export_for_template(renderer_base $output): array {
}
return [
'media' => array_values($media),
'sources' => $sources,
'action' => $action,
];
}
Expand Down
26 changes: 25 additions & 1 deletion classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ 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),
'tags' => $this->tags($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(
Expand All @@ -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);
}
Expand Down
13 changes: 11 additions & 2 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@
'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' => [
'coursecreator' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/blog:manageentries',
],

'tool/mediatime:view' => [
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => [
'coursecreator' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/blog:manageentries',
],
];
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

use tool_mediatime\media_manager;

require_admin();
require_login();

$source = optional_param('source', '', PARAM_ALPHANUMEXT);
$id = optional_param('id', null, PARAM_INT);
$edit = optional_param('edit', null, PARAM_INT);

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) {
Expand Down
3 changes: 3 additions & 0 deletions lang/en/tool_mediatime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 7 additions & 4 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
));
Loading

0 comments on commit cf5ea7a

Please sign in to comment.