Capability error

Capability error

by Angel Simón -
Number of replies: 3

Hello everyone, I'm having an error when trying to install a plugin that I've developed.

The plugin is located in /report/repo

Then, I have a /version.php with this line and the ones needed for the versioning:

$plugin->component = 'report_repo';

Then, in /db/access.php

defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'report/repo:view' => array(
'riskbitmask' => RISK_CONFIG,
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'manager' => CAP_ALLOW
)
)
);

In /lang/en/report_repo.php

$string['pluginname'] = 'My Log';
$string['repo:view'] = 'Some error message.'; 

In /settings.php

defined('MOODLE_INTERNAL') || die;
// Just a link to course report.
$ADMIN->add('reports', new admin_externalpage('reportrepo', get_string('pluginname', 'report_repo'),
$CFG->wwwroot . "/report/repo/index.php", 'report/repo:view'));
// No report settings.
$settings = null;

And, in /index.php, I have a line with this code:

    require_capability('report/repo:view', context_system::instance());

 

When I try to install the new plugin I'm getting:

Capability "report/repo:view" was not found! This has to be fixed in code.

 

What is wrong? Is there something misplaced or incorrect? I'm using Moodle 2.6.2 but it doesn't work in 2.7 either. I'm using SQL Server 2008 and Windows Server.

 

Thanks in advance

Average of ratings: -
In reply to Angel Simón

Re: Capability error

by Pinky Sharma -

Hello Angel,

You forgot to add clonepermissions in access.php.

Add 'clonepermissionsfrom' => 'coursereport/repo:view', after archetypes in access.php file.

Hope this will work for you.


In reply to Pinky Sharma

Re: Capability error

by Angel Simón -

Hi Pinky, but it didn't work for me. sad

 

It simply cannot "find" report/repo:view in capabilities.php

 

I know the plugin is working, bacause if I let it without access restrictions if works fine. But if I try to add custom capabilities, it doesn't work.

Thanks.

In reply to Angel Simón

Re: Capability error

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Did you bump the version number after adding the capability definition?

If you don't do that, then Moodle doesn't know to look for new capability definitions.