Description

Modules support defining subplugins which have their own capabilities in db/access.php
If a sub plugin creates capabilities they get added to the capabilities table and appears in the site permission editing, but the new permissions do not appear as permissions on their parent modules permission page.

I have tested this with Assignment Type and with Workshop Form and behaviour occurs for both. It will create the capabilities but not show them for the module they apply to.

E.g.
To create a test sub-plugin permission I added a capability to the workshop rubric plugin. Code below, and also step increased the version.php to process update.

mod/workshop/form/rubric/db/access.php

<?php

$capabilities = array(

'workshopform/rubric:test' => array(

'captype' => 'write',

'contextlevel' => CONTEXT_MODULE,

'legacy' => array(

'student' => CAP_ALLOW,

'teacher' => CAP_ALLOW,

'editingteacher' => CAP_ALLOW,

)

),

);

mod/workshop/form/rubric/lang/en/workshopform_rubric.php

//Added to lang

$string['rubric:test'] = 'Rubric Test Capability';

After adding this capability, when I brought up the Site Define Roles -> Edit Role the new capability appeared, however if I create a workshop activity and click Permissions these new capabilities do not appear, even though the context is CONTEXT_MODULE.

Note that the quiz has code to handle this. Look at quiz_get_extra_capabilities in mod/quiz/lib.php. All modules can use this callback as a short-term fix. Probably all you need to do David is to implement a get_subplugin_capabilities() function that people can use when implementing callbacks like this.

Tim Hunt
added a comment - 21/Nov/10 9:23 PM Note that the quiz has code to handle this. Look at quiz_get_extra_capabilities in mod/quiz/lib.php. All modules can use this callback as a short-term fix. Probably all you need to do David is to implement a get_subplugin_capabilities() function that people can use when implementing callbacks like this.

Please see the attached patch that adds support for subplugins to fetch_context_capabilities() function. If the patch is approved, the Quiz module should remove quiz reports capabilities from quiz_get_extra_capabilities() and keep just question capabilities there (because the quiz reports capabilities would be fetched automatically).

David Mudrak
added a comment - 30/Nov/10 1:16 AM Please see the attached patch that adds support for subplugins to fetch_context_capabilities() function. If the patch is approved, the Quiz module should remove quiz reports capabilities from quiz_get_extra_capabilities() and keep just question capabilities there (because the quiz reports capabilities would be fetched automatically).

David Mudrak
added a comment - 02/Dec/10 11:43 PM Hi Tim,
please see the proposed patch set at
https://github.com/mudrd8mz/moodle/compare/cvshead...MDL-25316_subplugins_capability
Tested at the 'Permissions in Quiz' page and the quizreport capability is still displayed as expected because the core now loads all subcapabilities automatically.
I am prepare to commit if you agree (I would create a pull request if we switched to git already).

Fixed in CVS HEAD. Thanks James for spotting this and thanks Petr and Tim for the reviews.

Summary of change: if fetch_context_capabilities() function in lib/accesslib.php is asked to get capabilities for CONTEXT_MODULE, it checks the module's db/subplugins.php file and loads all capabilities defined by the module subplugins (if there are any). This made the current quiz solution redundant (quiz needed do this originally because there was no such support for subplugins).

David Mudrak
added a comment - 03/Dec/10 12:57 AM Fixed in CVS HEAD. Thanks James for spotting this and thanks Petr and Tim for the reviews.
Summary of change: if fetch_context_capabilities() function in lib/accesslib.php is asked to get capabilities for CONTEXT_MODULE, it checks the module's db/subplugins.php file and loads all capabilities defined by the module subplugins (if there are any). This made the current quiz solution redundant (quiz needed do this originally because there was no such support for subplugins).