I came across a situation where OGUR wasn't behaving as I thought it should. this was because user_access() was caching the perms of the user before OGUR had the change to add the roles in.
so when roles are assigned to a user, the user_access cache needs to be flushed.

CommentFileSizeAuthor
flush-perms.patch1.02 KBjosh waihi

Comments

somebodysysop’s picture

Submitted code change to dev release. Should be available in about 12 hours. Please report back if it works. Thanks for the post and patch.

josh waihi’s picture

Status: Needs review » Reviewed & tested by the community

I have applied this patch and it worked for me.

scs_calleros’s picture

This patch solved problem of Access denied in "Configure member roles" tab

More info:
http://drupal.org/node/672302

Thank you.

spacereactor’s picture

doesn't seem to work for me

jvieille’s picture

I seem to have this issue. I cannot create any node with roles assigned through OGUR.
The code as much changed since this patch was suggested. The current function looks like this:

function og_user_roles_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'load':
// In case the global user object is reloaded from scratch, re-assign
// our additional roles.
if ($account->uid == $GLOBALS['user']->uid) {
og_user_roles_grant_roles($account);
}
break;

the function og_user_roles_list_users_sql does not exist anymore

Dave Cohen’s picture

Status: Reviewed & tested by the community » Needs work

An updated patch is something like this. But, it does not work for me. It seems my hook_access is being called and sometimes the user's roles are correct (OGUR roles set) and sometimes not.


Index: og_user_roles.module                                                                                                                                                                                                           
===================================================================
--- og_user_roles.module        (revision 3137)                                                                                                                                                                                       
+++ og_user_roles.module        (working copy)                                                                                                                                                                                        
@@ -313,6 +313,8 @@
       // our additional roles.                                                                                                                                                                                                       
       if ($account->uid == $GLOBALS['user']->uid) {                                                                                                                                                                                  
         og_user_roles_grant_roles($account);                                                                                                                                                                                         
+        // Flush cached perms.                                                                                                                                                                                                       
+        user_access('', $account, TRUE);                                                                                                                                                                                             
       }                                                                                                                                                                                                                              
       break;                                                                                                                                                                                                                         
                                                                                                                                                                                                                                      

(sorry for the patch format, didn't cut and paste properly, and I'm working remotely so its a hassle to get the patch file)

Dave Cohen’s picture

trying to track this down, I noticed that my hook_access is called from a long and convoluted stack trace. It seems during some module's hook_init somehow i18n_selection_mode() gets called, which calls menu_get_object() which eventually leads to the hook_access call. So maybe this issue only happens when i18n modules are enabled?

Dave Cohen’s picture

There is an unpleasant chicken and egg problem here. In that og expects a node (and not an nid) for its context. Meanwhile, loading that node causes some modules to call into the menu system, causing it to check access to the current menu item (before the og context is set).

So as a hacky workaround, I grant the og_user_roles before setting og context. This is in my hook_init(), where I already have some code to learn the og $nid...


    // $nid is already known.


     // Before we set OG context, get perms right.  See drupal.org/node/471882.
      $og = new stdClass();
      $og->nid = $nid;
      og_user_roles_grant_roles($GLOBALS['user'], $og); 

      $og = node_load($nid);
      og_set_group_context($og);
fuzzy76’s picture

Can we get any feedback from the maintainers on this? I am hitting a similar problem.

hefox’s picture

I believe the 4.x version of this module handles this