Capabilities in an assign feedback plugin

Capabilities in an assign feedback plugin

by Zabelle Motte -
Number of replies: 2
Picture of Particularly helpful Moodlers

Hello,

I am working on a fork of comments feedback assign plugin that enables a customized editor with specific buttons to tag errors.
This plugin only concern English teachers and I would like to enable it only for a new Moodle role.
I try to add capabilities on this plugin but it seems not to work.

This page gives capabilities examples for activity modules :
https://docs.moodle.org/dev/Activity_modules#DB_Folder

But for a feedbakc assign module the capability can not be "addinstance" ...

I add a look at the capabilities of other assign feedback plugins :
https://github.com/moodle/moodle/tree/master/mod/assign/feedback
But none of them does define capabilities.

Does Moodle actually enable capabilities for feedback assign plugins ?
If it is possible, what are the capabilities on such plugin ?


Thanks in advance for help ;-*


Zabelle

Average of ratings: -
In reply to Zabelle Motte

Re: Capabilities in an assign feedback plugin

by Martin Greenaway -

You should be able to declare any capabilities you wish to use in the yourpluginname/db/access.php file, and then you would be responsible for checking that the user has that capability in that context when you are writing your customised code.

For example, say you have defined a capability called mod/yourpluginname:tagerrors in your db/access.php.

You would then need to check whether the user has this capability, when you are providing the means for them to tag errors.

e.g. something like this (obviously I've not fully implemented this so I can't guarantee this is 100% right)

// Get the context first
$context = context_course::instance($courseid); // Assuming this is a feedback activity viewed from within a course page

// Does the user have this capability in this context?
if(has_capability('mod/yourpluginname:tagerrors', $context)) {
    // Code to display the button to tag errors goes here
    // ....
} else {
    // Code to do something else goes here - you might just not show anything
    // ....
}
Average of ratings: Useful (1)
In reply to Martin Greenaway

Re: Capabilities in an assign feedback plugin

by Zabelle Motte -
Picture of Particularly helpful Moodlers

Thank you for answer Martin, I will investigate your suggestion.

I let you (and the community) know if I succeed (or not).


Kisses


Zabelle