Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-62065

Deprecate dupe get_roles_[on_exact_context|with_assignment_on_context]() function

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.5
    • Fix Version/s: 3.6
    • Component/s: Roles / Access
    • Labels:
    • Testing Instructions:
      Hide

      Pre-requisites

      Data Protection Officer (DPO) role creation

      1. Login as an admin
      2. Go to "Site administration / Users / Define roles"
      3. Create a Data Protection Officer role with the following settings:
        Short name dpo
        Custom full name Data Protection Officer
        Role archetype Guest
        Context types where this role may be assigned System
        Capability "moodle/site:configview" (Allow)
        Capability "tool/dataprivacy:managedatarequests" (Allow)
        Capability "tool/dataprivacy:managedataregistry" (Allow)
        Capability "moodle/category:viewhiddencategories" (Allow)
        Capability "moodle/course:viewhiddencourses" (Allow)
        Capability "moodle/course:view" (Allow)
        Capability "moodle/course:viewhiddenactivities" (Allow)
        Capability "tool/dataprivacy:makedatarequestsforchildren" (Allow)
      1. Save changes.
        • Confirm that the role is successfully created.
      2. Go to "Site administration / Users / Permissions / Assign system roles"
      3. Assign at least one user to the DPO role.

      You can check this configuration if you want in https://docs.moodle.org/35/en/Privacy_officer_role

      Site course and users

      1. Create a course with this shortname: testrole with some activities in it.
      2. Enrol some users as student role.

      You can use Make test course to create the course in "Site administration / Development / Make test course".

      Test 

      Test get_roles_on_exact_context() and get_roles_with_assignment_on_context().
      1. Make sure you have the course with the shortname 'testrole' created.
      2. Make sure you have the Developer debug mode enable.
        1. If not, you can do that in "Site administration / Development / Debugging "
        2. Select the option "Developer: extra Moodle debug messages for developers" on Debug messages selector.
      3. Put into your local directory the attached test file test_deprecating.php
      4. Login in your Moodle as admin user.
      5. Go to this URL in your browser: http://MOODLESITE/local/test_deprecating.php
      6. Expected result: Check you can see the debugging messages:

        get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.
         
            line 6417 of /lib/deprecatedlib.php: call to debugging()
            line 11 of /local/test_deprecating.php: call to get_roles_on_exact_context()
         
        Array
        (
            [5] => stdClass Object
                (
                    [id] => 5
                    [name] => 
                    [shortname] => student
                    [sortorder] => 5
                    [coursealias] => 
                )
         
        )
         
        get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.
         
            line 6432 of /lib/deprecatedlib.php: call to debugging()
            line 14 of /local/test_deprecating.php: call to get_roles_with_assignment_on_context()
         
        Array
        (
            [5] => stdClass Object
                (
                    [id] => 5
                    [name] => 
                    [shortname] => student
                    [sortorder] => 5
                    [coursealias] => 
                )
         
        )
        
        

       

      Data registry.
      1. Login in your Moodle as admin user.
      2. Go to "Site administration / Users / Privacy and policies / Data registry"
      3. You should see the amazing tree with Course categories and courses.
      4. Expected result: When you select Miscellaneous category and you should see on the right in Subject scope the dpo name role. 
      5. Expected result: When you select the new course created 'testrole' you should see on the right in Subject scope the student name role.
      6. Expected result: Browse for the activities of the new course created 'testrole' you should see in Subject scope the student name role.

       

      Show
      Pre-requisites Data Protection Officer (DPO) role creation Login as an admin Go to " Site administration / Users / Define roles " Create a Data Protection Officer role with the following settings: Short name dpo Custom full name Data Protection Officer Role archetype Guest Context types where this role may be assigned System Capability "moodle/site:configview" (Allow) Capability "tool/dataprivacy:managedatarequests" (Allow) Capability "tool/dataprivacy:managedataregistry" (Allow) Capability "moodle/category:viewhiddencategories" (Allow) Capability "moodle/course:viewhiddencourses" (Allow) Capability "moodle/course:view" (Allow) Capability "moodle/course:viewhiddenactivities" (Allow) Capability "tool/dataprivacy:makedatarequestsforchildren" (Allow) Save changes. Confirm  that the role is successfully created. Go to " Site administration / Users / Permissions / Assign system roles " Assign at least one user to the DPO role. You can check this configuration if you want in  https://docs.moodle.org/35/en/Privacy_officer_role Site course and users Create a course  with this shortname: testrole  with some activities in it. Enrol some users as student role. You can use Make test course to create the course in " Site administration / Development / Make test course ". Test  Test get_roles_on_exact_context() and get_roles_with_assignment_on_context(). Make sure you have the course with the shortname 'testrole' created. Make sure you have the Developer debug mode enable. If not, you can do that in " Site administration / Development / Debugging " Select the option "Developer: extra Moodle debug messages for developers" on Debug messages selector. Put into your local directory the attached test file  test_deprecating.php .  Login in your Moodle as admin user. Go to this URL in your browser:  http://MOODLESITE/local/test_deprecating.php Expected result:  Check you can see the debugging messages: get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.   line 6417 of /lib/deprecatedlib.php: call to debugging() line 11 of /local/test_deprecating.php: call to get_roles_on_exact_context()   Array ( [5] => stdClass Object ( [id] => 5 [name] => [shortname] => student [sortorder] => 5 [coursealias] => )   )   get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.   line 6432 of /lib/deprecatedlib.php: call to debugging() line 14 of /local/test_deprecating.php: call to get_roles_with_assignment_on_context()   Array ( [5] => stdClass Object ( [id] => 5 [name] => [shortname] => student [sortorder] => 5 [coursealias] => )   )   Data registry. Login in your Moodle as admin user. Go to " Site administration / Users / Privacy and policies / Data registry " You should see the amazing tree with Course categories and courses. Expected result:  When you select Miscellaneous category and you should see on the right in Subject scope the dpo  name role.  Expected result:  When you select the new course created 'testrole' you should see on the right in Subject scope the  student name role. Expected result:  Browse for the activities of the new course created 'testrole' you should see in Subject scope the  student name role.  
    • Affected Branches:
      MOODLE_35_STABLE
    • Fixed Branches:
      MOODLE_36_STABLE
    • Pull Master Branch:
      MDL-62065-master

      Description

      While working on MDL-61899 we detected that, actually, there are 2 accesslib methods to fetch the roles used at an exact context:

      • get_roles_on_exact_context()
      • get_roles_with_assignment_on_context()

      In the other side, for fetch all the roles used in a context (including parents) is:

      • get_roles_used_in_context()

      Right now there isn't any use in core of any of the "exact" functions.

      This is about to decide what to do:

      1) Deprecate the 2 "exact context" functions and add the "including parents" one to also support "exact context"
      2) Deprecate one of the 2 "exact context", leaving the other. If so, I'd propose to deprecate the get_roles_with_assignment_on_context() because it's less clear.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  3/Dec/18

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour
                  1h