Create role with a certain capability during plugin installation

Re: Create role with a certain capability during plugin installation

by Mark Johnson -
Number of replies: 1
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Capabilities can be assigned to roles in a context. CONTEXT_COURSE is not a context, it is a context level for all course contexts, so you cannot assign a capbility like that.

It would help if you explain exactly what end result you want, rather than how you are trying to achieve it, but the way moodle handles default capabilities is by setting archetypes in the capability definition. Roles that use that archetype will automatically have the capability set. See the Roles documentation here: https://docs.moodle.org/dev/Roles#Programming_Interface

Average of ratings: Useful (1)
In reply to Mark Johnson

Re: Create role with a certain capability during plugin installation

by Евгений Мамаев -
Picture of Plugin developers
Well, I thought about creating a new role with predefined capability on COURSE level. So if an admin will assign this role to a user, he (user) gets this capability by default.
I was trying to use backup_controller class to make a copy of activity in one course and then restore this activity in another course.
You can pass userid in backup_controller constructor and so I found a workaround: I pass admin userid into backup_controller constructor and then I restore this backup passing actual userid into restore_controller constructor. So the initial question about role creation is not relevant now.