I've contributed some code to the OG User Roles module. This module allows for roles to be assigned on a per-group basis. It works fairly simply: we pull in the roles that have been assigned to the current user in the current group in hook_init(). The problem is that the group context is available in hook_init(), so we have to try a load of heuristics to try to grab the gid from the URL. This is flaky and involves lots of hacks to support various modules. The reason we can't do this later is that user_access() statically caches the permissions a user has, and there's no $flush or $reset parameter to ask the function to get rid of its cache and recalculate permissions from $user->roles. Therefore as soon as user_access() is called adding roles to $user->roles becomes pointless.

I attach a patch against 6.0-beta which adds this parameter to user_access(), which would simplify and make more robust the OG User Roles plugin, as well as making user_access() more consistent with other caching functions like node_load().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Zothos’s picture

Version: 6.0-beta1 » 6.x-dev

Hm, wrong patch format i think

catch’s picture

Status: Needs review » Needs work

Yep, marking to needs work for unified diff.

StevenPatz’s picture

Status: Needs work » Needs review
FileSize
896 bytes

Here's an updated patch.

Wim Leers’s picture

FileSize
896 bytes

Replaced question mark with a period. Looks good otherwise.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers

Actually, that patch was crap. It wasn't conform the coding standards, and the $reset parameter wasn't even added to the function's parameter list...

I also tried to improve the explanation of the $reset parameter.

Needs review.

Wim Leers’s picture

FileSize
1.35 KB

Bah, forgot the patch.

Wim Leers’s picture

Title: user_access() needs a $flush parameter » user_access() needs a $reset parameter to support dynamic roles

Better title.

Wim Leers’s picture

FileSize
1.34 KB

Oops, the parameter name in the parameter list was incorrect in this patch. Fixed.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

a useful feature, and code is clean.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

SomebodySysop’s picture

I've found a problem here: http://drupal.org/node/325889

Do you think this mean the patch itself needs to be re-visited?

SomebodySysop’s picture

The patch does function as it was designed. However, something else is causing the $perm variable to be altered *outside* of the user_access function. Still trying to find out how this is possible.

http://drupal.org/node/325889#comment-1084975

SomebodySysop’s picture

Bug in user_access function: http://drupal.org/node/329646

This bug prevents the reset mechanism from working properly. Resolved in 6.x with this patch: http://drupal.org/files/issues/329646-user-module-reset-d6.patch