I created a local plugin in the local directory of course. I created a db/access.php file and I created a settings.php in the plugin as I want to control who accesses the plugin but also where it shows up on the site admin tree as this is a system context plugin. It shows up in the site admin tree where I want it for site admins only. But not for site admins and the role that I specifically created to allow to use this plugin in addition to site admins. However, the urls are accessible to anyone even students when you know them and put them in the URL directly. So access.php doesn't appear to work either. So I'm confused. I've looked at other plugins but most of them are course local plugins which is a different context and don't really help. I've read and searched the documentation. Nothing appears to speak to this. Thanks for your help, in advance.
settings.php
$context = context_system::instance();
$roles = get_user_roles($context, $USER->id, true);
$has_mytestrole_role = FALSE;
if(in_array('mytestrole',$roles)){
$has_mytestrole_role = TRUE;
}
if (($hassiteconfig)||($has_mytestrole_role==TRUE)) {
$ADMIN->add('root', new admin_category('local_myplugin', get_string('pluginname', 'local_myplugin')));
$index_page = new admin_externalpage('local_myplugin_index',get_string('pluginname', 'local_myplugin'),new moodle_url('/local/myplugin/index.php'));
$ADMIN->add('local_myplugin',$index_page);
$admin_page = new admin_externalpage( 'local_myplugin_admin', get_string('settings','local_myplugin'),new moodle_url('/local/myplugin/mypluginsettings.php'));
$ADMIN->add('local_myplugin',$admin_page);
}
db/access.php
<?php
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'local/myplugin:myplugin' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'mytestrole'=> CAP_ALLOW,
),
),
'local/myplugin:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'mytestrole'=> CAP_ALLOW,
),
),
);