My site has certain groups and a book assinged to each group. When users try to create child pages to this book using the link below the page, i.e "Add child page" , it shows access denied. But he can create a child page by clicking on the link "Create book page" in the group navigation box. Is this a bug?

The links are
1. http://mysite/node/add/book/parent/5 ==>gives Access denied for the group user. (group user role is group specific )
2. http://mysite/node/add/book?gids[]=50 ==>works perfect. (here i have to choose the book page under which i have to add the child page)

i have given permissions for "group user role" to access "create/edit/edit own/printer friendly" book pages.
If i assign this role to a user which is normal user not group specific, it works fine.

How to fix this? Any pointers?

mrrijo

Comments

somebodysysop’s picture

Status: Active » Needs review

Here's some code I just created for the relativity module issue. Add it to the end of og_user_roles_init():

  // If this is a group relativity or book module node/add, re-direct to ognodeadd
  if (arg(0) == 'node' && arg(1) == 'add'  && is_numeric(arg(4)) && (!in_array(arg(2), $exempted)) ) {
      
    $type = arg(2);
    $path = 'node/ognodeadd';

    // Get the gid for this parent
    $nid = (int)arg(4);
    $gid = og_user_roles_getgid($nid, $user->uid);

    $query = 'type='. $type .'&gids[]='. $gid;

    // Modification to make it work with module "Relativity"
    // http://drupal.org/node/166253
    // http://drupal.org/node/227978
    if (module_exists('relativity')) {
      if (arg(3) == 'parent') {
        $query .= '&parent_node='.arg(4);
      }
      elseif (!empty($_GET['parent_node'])) {
        $query .= '&parent_node='.$_GET['parent_node'];
      }
    }
    // Book module as per: http://drupal.org/node/228386
    if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
      $path .= '/book/parent/'. arg(4);
    }
     drupal_goto($path, $query);
  }

It appears to work in my case. Let me know if it works in your's.

mrrijo’s picture

thanks, i will give a shot on Monday when i get to office.

mrrijo’s picture

Yes it worked. But i got a warning

warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sites\all\modules\og_user_roles\og_user_roles.module on line 768.

And the line 768 was

" if (arg(0) == 'node' && arg(1) == 'add' && is_numeric(arg(4)) && (!in_array(arg(2), $exempted)) ) { "

Another thing to be noted is, "Viewing printer friendly page" is still not working.

Anything more to edit?

somebodysysop’s picture

warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sites\all\modules\og_user_roles\og_user_roles.module on line 768.

The snippet needs to go inside of this if clause in hook_init:

  if ($user->uid > 0) {
"Viewing printer friendly page" is still not working.

Insert this code into og_user_roles_all_roles():

    // Book module
	// As per: http://drupal.org/node/228386
    // http://doadance.scbbs.com/book/export/html/279
    if (arg(0) == 'book' && arg(1) == 'export' && arg(2) == 'html' && is_numeric(arg(3)) ) {
      $location = 19;
      $nid = (int)arg(3);
      $gid = og_user_roles_getgid($nid, $uid);
    }

Just before:

   // Modification. As per: http://drupal.org/node/176390
   // Present a hook for other modules: hook_og_user_roles_gid()  
   if ($results = module_invoke_all('og_user_roles_gid')) {
     foreach ($results as $result) {
       if ($result) $gid = $result;
     }
   }
mrrijo’s picture

Wow, both worked! excellent. Thanks.

somebodysysop’s picture

Assigned: Unassigned » somebodysysop
Status: Needs review » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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