Moodle
  1. Moodle
  2. MDL-25316

Capabilities created by Sub Plugins do not show on Permissions page for that module

    Details

    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      1136

      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.

        Activity

        Hide
        Petr Škoda added a comment -

        Hmm, this should be relatively easy to fix, reassigning to David, please try to find some suitable solution, thanks.

        Petr

        Show
        Petr Škoda added a comment - Hmm, this should be relatively easy to fix, reassigning to David, please try to find some suitable solution, thanks. Petr
        Hide
        Tim Hunt added a comment -

        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.

        Show
        Tim Hunt added a comment - 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.
        Hide
        David Mudrak added a comment -

        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).

        Show
        David Mudrak added a comment - 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).
        Hide
        Petr Škoda added a comment -

        +1 for commit, please deal with the quiz hacks too

        Show
        Petr Škoda added a comment - +1 for commit, please deal with the quiz hacks too
        Hide
        Tim Hunt added a comment -

        Can I have I quick look at the quiz part of your changes before you commit them. Thanks.

        Show
        Tim Hunt added a comment - Can I have I quick look at the quiz part of your changes before you commit them. Thanks.
        Hide
        David Mudrak added a comment -

        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).

        Show
        David Mudrak added a comment - 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).
        Hide
        Tim Hunt added a comment -

        +1 from me to commit. Nice change.

        Show
        Tim Hunt added a comment - +1 from me to commit. Nice change.
        Hide
        David Mudrak added a comment -

        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).

        Show
        David Mudrak added a comment - 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).
        Hide
        James Rudd added a comment -

        Thanks David, I just tested it with an Assignment type plugin and it now displays correctly.

        Show
        James Rudd added a comment - Thanks David, I just tested it with an Assignment type plugin and it now displays correctly.

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: