Moodle

load_subcontext duplicates the role assignments at course level in $accessdata['ra']

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: 1.9.3
  • Fix Version/s: None
  • Component/s: Roles / Access
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE

Description

I am looking at line 1313 of accesslib.php, the bit following the comment "// Read in the RAs, preventing duplicates" in load_subcontext. In the case where you are call this with a course context, the the role assignments for this context level are already loaded, but the code does not check for this. Therefore I am seeing things like this:

Array
(
[ra] => Array
(
[/1/3/49] => Array
(
[0] => 3
)

[/1/3/48/20] => Array
(
[0] => 3
[1] => 3
)

[/1] => Array
(
[0] => 7
)

[/1/2] => Array
(
[0] => 5
)

)

This does not hurt, apart from, perhaps, causing wasted effort later - except that some display code I have just written does not like this.

I am thinking of adding a array_unique call to fix this.

Issue Links

Activity

Hide
Tim Hunt added a comment -

This patch seems to fix the problem. Please could you review it. Thanks.

Show
Tim Hunt added a comment - This patch seems to fix the problem. Please could you review it. Thanks.
Hide
Tim Hunt added a comment -

Sorry, typo in that patch in the second changed line, $ra->path should be $context->path.

Show
Tim Hunt added a comment - Sorry, typo in that patch in the second changed line, $ra->path should be $context->path.
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Tim,

your patch looks ok IMO. Anyway, in relation with MDL-14817 it's incomplete, because there are, still, some functions in accesslib causing duplicates.

In that bug I proposed to change, for 2.0, all the current

array_push($accessdata['ra'][$ra->path], $roleid)

by roleid keyed arrays:

$accessdata['ra'][$ra->path][$roleid] = $roleid

That way we'll get "automatic" uniqueness along all acceslib and we'll be able to delete some (partial) checks currently present.

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi Tim, your patch looks ok IMO. Anyway, in relation with MDL-14817 it's incomplete, because there are, still, some functions in accesslib causing duplicates. In that bug I proposed to change, for 2.0, all the current array_push($accessdata['ra'][$ra->path], $roleid) by roleid keyed arrays: $accessdata['ra'][$ra->path][$roleid] = $roleid That way we'll get "automatic" uniqueness along all acceslib and we'll be able to delete some (partial) checks currently present. Ciao
Hide
Tim Hunt added a comment -

Sorry for not searching for the dupe. I thought of that idea too, but then I saw the 31 places where accesslib touches $accessdata['ra'], and decided that trying to implement that fix would be harder. However, it would be great if someone else did it

Show
Tim Hunt added a comment - Sorry for not searching for the dupe. I thought of that idea too, but then I saw the 31 places where accesslib touches $accessdata['ra'], and decided that trying to implement that fix would be harder. However, it would be great if someone else did it
Hide
Eloy Lafuente (stronk7) added a comment -

Aha, oki, work continues in MDL-14817. Thanks!

Just if ML could validate the idea.... I can start working in a patch. I thin we only must care of places adding 'ra' info (using the roleid indexed way). Read access should continue being the same, np there.

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Aha, oki, work continues in MDL-14817. Thanks! Just if ML could validate the idea.... I can start working in a patch. I thin we only must care of places adding 'ra' info (using the roleid indexed way). Read access should continue being the same, np there. Ciao

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: