How to make report accessable to managers?

How to make report accessable to managers?

by Adam Nielsen -
Number of replies: 6

I noticed that some reports are visible to managers/teachers and others are only visible to admins.

I know from https://docs.moodle.org/dev/Reports#How_your_report_gets_included_in_the_navigation

that one can include  a report in the navigation in settings.php like this:

ADMIN->add('reports', new admin_externalpage('reportconfiglog', get_string('configlog', 'report_configlog'), "$CFG->wwwroot/report/configlog/index.php"));
$settings = null;


But how do you specifiy who can see it?




Average of ratings: -
In reply to Adam Nielsen

Re: How to make report accessable to managers?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You're not thinking about it the correct way. Moodle uses "capabilities" to control access. So (from the page you quote)...

function report_myreport_extend_navigation_course($navigation, $course, $context) {
    if (has_capability('report/myreport:view', $context)) {
        $url = new moodle_url('/report/myreport/index.php', array('id'=>$course->id));
        $navigation->add(get_string('pluginname', 'report_myreport'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}


You need to add a new view capability for your report (in the example 'report/myreport:view) and then assign that capability to the roles you require. 

In reply to Howard Miller

Re: How to make report accessable to managers?

by Adam Nielsen -

Perfect, that is what I was looking for. Thank you.

In reply to Adam Nielsen

Re: How to make report accessable to managers?

by Adam Nielsen -
So I did the following:

First I added capability at system level:

$ADMIN->add('reports',
new admin_externalpage('reportgnp', get_string('pluginname','report_myreport'),
$url, 'report/myreport:view'));

and then I added capability in `db/access.php`:


$capabilities = array(

'report/myreport:view' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:viewreports',
)
);

But now it does not appear anymore in reports and I get the error:

Capability "repository/myreport:view" was not found! This has to be fixed in code.
line 4376 of /lib/navigationlib.php: call to admin_externalpage->check_access()
line 4408 of /lib/navigationlib.php: call to settings_navigation->load_administration_settings()
line 4359 of /lib/navigationlib.php: call to settings_navigation->load_administration_settings()
line 4214 of /lib/navigationlib.php: call to settings_navigation->load_administration_settings()
line 769 of /lib/pagelib.php: call to settings_navigation->initialise()
line 830 of /lib/pagelib.php: call to moodle_page->magic_get_settingsnav()
line 8498 of /lib/adminlib.php: call to moodle_page->__get()
line 24 of /admin/search.php: call to admin_externalpage_setup()

But why is that? I have created the capability under `/reports/myreport/db/access.php`. I also cleared the cache.
In reply to Adam Nielsen

Re: How to make report accessable to managers?

by Adam Nielsen -
It seems I had to deinstall/install the plugin after adding the capability. Now it works.
In reply to Adam Nielsen

Re: How to make report accessable to managers?

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
For future reference, if you boost the version number in version.php of your plugin being developed, it should reinstall and pick up such changes smile
Average of ratings: Useful (1)