og_user_roles_grant_roles static caches roles based on the original group and user passed in, so if user changes behind scenes or want to use it on a different user or group (other than the current) it doesn't work.

Patch does
1) Moves determining group context into the function and saves current group there for later so doesn't have to be redetermined (unless reset).
2) Caches roles based on user and rid so can be pass any account/group
3) moved og_get_group_context in front of og_user_roles_determine_context as og_get_group_context requires a lot less work so for modules using that, it should provide a performance boost.
4) Moved around some of the quering stuff as it was just strange. It was acting like it could have multiple group ids, but would never provide more than 1 group ids, so was needlessly complicated.
5) Saves the current roles in a site_roles variable so modules can see what the original roles were.

I wanted to use og_user_roles_get_roles_by_group instead of a query there, but that doesn't return the name so didn't want to needlessly slow that query and change what it returns.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hefox’s picture

Title: Make og_user_roles_grant_roles more re-usable by custom modules » Make og_user_roles_grant_roles more re-usable
FileSize
4.75 KB

Previous patch caused an eternal loop when a user_load called via loading the menu objects.

hefox’s picture

New Patch updated due to #837134

hefox’s picture

hefox’s picture

This patch is a feature request if the main patch gets in, to only call og determine group context when configured. Right now with spaces, the context is always set so it's doing extra logic on non-group pages :(

Ignore this patch for now or test it with above if in similair situation. Just needed to put it somewhere and as it depends on this patch, didn't want to open a new feature request.

hefox’s picture

Here's a patch that updates so user_access is not refreshed when there's no new roles added ( :( )

5_1 patch has comment #4's patch combined into it.