Create capabilities for plugin type block

Create capabilities for plugin type block

by Jesus Marquez -
Number of replies: 4

Hi,

I am developing a plugin type block. The role manager only can using it.

Access.php is:

'block/activity_modules:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_PROHIBIT,
'manager' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:manageblocks'
),

But it doesn't work because that still the teacher can add the plugin.

Thanks!

Average of ratings: -
In reply to Jesus Marquez

Re: Create capabilities for plugin type block

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Apologies - removed original suggestion as I hadn't read your requirements properly:

I would say, simply alter your code to clone permissions from another capability that only the manager role does have. Maybe something like moodle/site:configview (Manager and Course Creator) or moodle/site:deleteanymessage (manager only)

In reply to Richard Oelmann

Re: Create capabilities for plugin type block

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

Or, you could completely skip the clone permissions line - just leave the permissions as those explicitly mentioned.

Note that the permissions are set only on initial install (or when you create a new capability), if you want to change the role allocations, you need to either uninstall the plugin via the Manage plugins page and let it reinstall, or manually set the permissions on the Define roles page.

Average of ratings: Useful (2)
In reply to Davo Smith

Re: Create capabilities for plugin type block

by Jesus Marquez -
Hi Davo:

This work! I remove clone permissions line.

Thanks!
In reply to Richard Oelmann

Re: Create capabilities for plugin type block

by Jesus Marquez -
Hi Richard:

I set this:

$capabilities = array(
'block/aulavirtualdoc:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_PROHIBIT,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:configview'
),
'block/aulavirtualdoc:view' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
'student' => CAP_PROHIBIT
)
)
);

But user with role editingteacher (Teacher) can still deleting block from course.

When show the block's capabilities by administration. Show this:
Capabilities aulavirtualdoc
Thank for you help!