Skip to content

Commit

Permalink
Roles, capabilities and contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
guillogo committed Feb 14, 2021
1 parent 948cbf1 commit 392186b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
43 changes: 43 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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 tool_guillogo.
*
* @package tool_guillogo
* @author Guillermo Gomez Arias <[email protected]>
* @copyright 2020 Guillermo Gomez Arias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$capabilities = [
'tool/guillogo:view' => [
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'student' => CAP_ALLOW,

],
],
'tool/guillogo:edit' => [
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'editingteacher' => CAP_ALLOW,
],
],
];
5 changes: 4 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
use tool_guillogo\local\table\guillogo_table;

require_once(__DIR__ . '/../../../config.php');
require_once('../../../lib/tablelib.php');

$courseid = required_param('id', PARAM_INT );

$url = new moodle_url('/admin/tool/guillogo/index.php');
$title = get_string('pluginname', 'tool_guillogo');
$context = context_system::instance();
$context = context_course::instance($courseid);

require_login($courseid);
require_capability('tool/guillogo:view', $context);

// Set up the page.
$PAGE->set_context($context);
Expand Down
5 changes: 4 additions & 1 deletion lang/en/tool_guillogo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@
$string['completed'] = 'Completed';
$string['priority'] = 'Priority';
$string['timecreated'] = 'Time created';
$string['timemodified'] = 'Time modified';
$string['timemodified'] = 'Time modified';

$string['guillogo:view'] = 'View';
$string['guillogo:edit'] = 'Edit';
23 changes: 13 additions & 10 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@
* This function extends the navigation with the tool items.
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the tool
* @param context $context The context of the course
* @param stdClass $course The course to object for the tool
* @param context $context The context of the course
* @throws coding_exception|moodle_exception
*/
function tool_guillogo_extend_navigation_course($navigation, $course, $context) {

$navigation->add(
get_string('pluginname', 'tool_guillogo'),
new moodle_url('/admin/tool/guillogo/index.php', ['id' => $course->id]),
navigation_node::TYPE_SETTING,
get_string('pluginname', 'tool_guillogo'),
'guillogo',
new pix_icon('icon', '', 'tool_guillogo')
);
if (has_capability('tool/guillogo:view', $context)) {
$navigation->add(
get_string('pluginname', 'tool_guillogo'),
new moodle_url('/admin/tool/guillogo/index.php', ['id' => $course->id]),
navigation_node::TYPE_SETTING,
get_string('pluginname', 'tool_guillogo'),
'guillogo',
new pix_icon('icon', '', 'tool_guillogo')
);
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

$plugin->version = 2020122806;
$plugin->version = 2020122807;
$plugin->requires = 2020060900;
$plugin->component = 'tool_guillogo';
$plugin->release = '1.4';

0 comments on commit 392186b

Please sign in to comment.