Dear Somebodysop,
I am trying to use the relativity module (5.x-2.x-dev) together with og_user_roles and I have been encountering some problems. I have taken into account the issue here but as far as I can tell, two things seem to not be working, and I couldn't figure out whether that issue took care of the same issues I have encountered:
(i have attached a screenshot to make things easier)
a) the "Create new Image" link leads to http://sitename/node/add/image/parent/46 , where I get an access denied because it loses group focus. Now if I try the url
http://sitename/node/add/image/parent/46&gids[]=11
the fix of the previous issue works and redirects me to
http://sitename/node/ognodeadd?type=image&gids[]=11&parent_node=46
which correctly creates the relativity.
b) the same goes for the "Attach existing Image" link which leads me to
http://sitename/relativity/listnodes/image/parent/46
which loses group focus. In this case group focus is useful if I need to create a view for nodes to attach that spits all image nodes that belong to the group, otherwise I get the image nodes of the entire site.
Is there a way to fix this Ron?

CommentFileSizeAuthor
Image2.jpg98.91 KBchrisroditis

Comments

somebodysysop’s picture

Don't know about case b, but:

a) the "Create new Image" link leads to http://sitename/node/add/image/parent/46 , where I get an access denied because it loses group focus.

Theoretically, this should not happen because the og_last session cookie should be set since you are in a group context when this link is clicked.

Here's the code:

    // Modification as per: http://drupal.org/node/174959
    // If this is a non-group node/add, but og_last session cookie is set
    // then re-direct to ognodeadd
	// But, make sure you don't redirect for omitted nodes.
    if (arg(0) == 'node' && arg(1) == 'add' && $_SESSION['og_last'] && (!is_null(arg(2)))  && (!in_array(arg(2), $exempted)) ) {

      $gid = $_SESSION['og_last']->nid;

      $type = arg(2);
      $path = 'node/ognodeadd';

      // Modification as per: http://drupal.org/node/178610
	  // Need to make sure this node $type supports adding a group item
      $og_audience_required = variable_get('og_audience_required', FALSE);
      $og_omitted = variable_get('og_omitted', array());
      if ($og_audience_required && (!in_array($type, $og_omitted)) ) {
        if ($type == 'og_user_roles_subgroup') {
          $type = variable_get('og_user_roles_create_subgroup_value', ''); // change OG Subgroups type to 'group'
        }

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

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

        // Modification for book module - http://drupal.org/node/180243
  	    // this: http://www.scbbs.com/node/add/book/parent/225&gids[]=29
	    // becomes this: http://www.scbbs.com/node/ognodeadd/0/parent/225?type=book&gids[]=29
        if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
          $path .= '/book/parent/'. arg(4);
        }

        drupal_goto($path, $query);
      }
    }

So. Could you turn on og_user_test and let me see what comes back when you click on the a) and b) links? I'd like to see if there is a group context during and/or just before. Thanks.

somebodysysop’s picture

Also, from http://drupal.org/node/166253:

The group membership automatically adds the query parameter: gids[]=$group-nid

Why isn't this happening with the links?

somebodysysop’s picture

OK. The problem is that we need the current group context added to the "create image" link url (i.e., "&gids[]=11").

I repeat my earlier question: "Isn't this supposed to be done by the relativity module itself?"

If not, then the question becomes: How do we do it?

I thought about trying to use the referrer, but perhaps just getting the gid from the parent node would work just as well.

Try adding this to the bottom of og_user_roles_init():

    // If this is a group relativity module node/add, re-direct to ognodeadd
    if (module_exists('relativity')) {
      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
          if (arg(3) == 'parent') {
            $query .= '&parent_node='.arg(4);
          }
          elseif (!empty($_GET['parent_node'])) {
            $query .= '&parent_node='.$_GET['parent_node'];
          }

        drupal_goto($path, $query);
      }
    }
chrisroditis’s picture

Ron, I can confirm that it worked great! Will this be added to the next og_user_roles version?
Also, can this be done in a similar manner for the "attach new image" link to work without losing group context? Or is there something I can report to the relativity module author that can make it work?

somebodysysop’s picture

Also, can this be done in a similar manner for the "attach new image" link to work without losing group

Is it "attach existing image"? If not, what is the link url?

You have to walk me through this because I don't have the "relativity" module installed.

How do you get to this url:

http://sitename/relativity/listnodes/image/parent/46

Once you get there, what do you expect to see?

How is OGR going to do you any good if "relativity" doesn't recognize group content itself? Or, maybe I just don't understand how this works.

chrisroditis’s picture

Ron, I am sorry, it is the "attach existing image" link, with the url you mentioned.
My thought was to create a new feature for the relativity module that would display a "view" of nodes that can be attached when you hit the "attach an existing content-type" link. Right now it does not work with views for that matter, it just provides you with a list of all of the site's nodes.
In my case I would need that "view" to be aware of the group context and display only nodes that belong to the current group.
If the problem lies with the relativity module, then I should point my efforts there, to make it aware of group context.

somebodysysop’s picture

Let me put it this way: If a group user, with a site-wide role which allows him access to the link in question, is only able to see group nodes listed, then this would be an OGR issue. That would mean that the module itself is OG-aware.

If ithe module is not OG-aware, then your issue would be how to get it to recognize the group it's in and only present nodes that belong to that group.

Hope this makes sense.

chrisroditis’s picture

So I guess it's not og aware. Thanks for the explanation Ron, I think this issue can be closed.

somebodysysop’s picture

Status: Active » Closed (fixed)

Even if you make the module goup aware, there is still a discussion as to how that should be done. Should a group user with the permission only be allowed to see nodes in the current group? Or, should he see nodes in all groups in which he is a member? That could get kind of complicated. But, once it's done, I can make the OGR module recogize the group context for it.

Good luck!