Hi all,

in Views "basic setting" there is the "access" feature, where I can set access restriction to a view display by user CORE roles.

I'd need the same feature, but configurable for user OGUR roles.

Thank you very much!

MXT
(sorry for my bad english)

Comments

sun’s picture

Status: Active » Closed (won't fix)

There are no "OGUR roles". OGUR dynamically and transparently grants additional, regular user roles depending on the group context of a page.

mxt’s picture

Thank you for your answer Sun,

so, how I can achieve this goal?

I'll try to explain my problem better: I have OG groups with moderators and authors. Those roles has been assigned with OGUR (not core roles, indeed all CORE roles chekboxes are unchecked. This is what OGUR requires to work correctly, because if I assign also CORE roles to users, they would have these roles over all site/groups regardless of their group membership).

Now If I try to restrict access to a View by roles, it doesn't work because Views check the CORE role of a user, and my users doesn't have CORE roles, but only "OGUR roles".

How can resolve this?

Thank you very much

MXT

sun’s picture

Again: Your users only have core roles. There is no such thing like a "ogur role".

OGUR dynamically grants additional core roles to users depending on the current group context. If you want to _list_ those role assignments using Views, then that's not possible (yet) and #729256: Views integration is what you want.

mxt’s picture

StatusFileSize
new480.2 KB

Please Sun: don't hate me ;-)

What I'm asking in "#729256: Views integration" is different to the request in this thread.

Ok, now I understand that there aren't "ogur role": these "run time" roles works correctly only on pages with OG context setted up, so I think a possible solution to this issue is to keep OG context in this particular view.

I've tried to do so setting up Group relationship/arguments but without success...

Please see the image in attachment where I summarize the issue.

Do you think using Context module ( http://drupal.org/project/context ) I'll be able to keep OG context in other pages like the one described above?

In this case I'll resolve other similar issue like:
- Check OGUR roles with Rules
- Views Bulk Operations roles restrictions would finally works correctly with OGUR roles
- Any other situation involving other modules that have to check OGUR roles outside OG context

Please tell me if Context module is the right way to follow

Thank you very much for your patience

MXT

mxt’s picture

Category: feature » bug
Status: Closed (won't fix) » Active

I'm very sorry for reopening this, but after View's maintainer answer (see http://drupal.org/node/759264#comment-2817720 ) I definitively think that this is a OGUR bug.

Thank you

sun’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

I'm still not sure what the actual issue/problem is. Can you post an - as simple as possible - procedure to replicate the issue you are facing?

pgillis’s picture

subscribe

mxt’s picture

StatusFileSize
new242.16 KB
new261.49 KB
STEPS to show the issue:
  1. Make a new Drupal clean installation from scratch
  2. Install and enable the following modules:
  3. Organic Groups
    • Organic Groups access control
    • Organic Groups User roles
    • Organic Group Views integration
  4. Views

 

Core roles configuration ( admin/user/roles ):

  1. Create a new role "Moderators"
  2. Create a new role "Authors"

 

Content types ( admin/content/types/add ):

  1. Create a new content type "Articles" (workflow settings: "published" checked; organic groups settings: "Standard group post" checked)
  2. Create a new content type "Departments" (workflow settings: "published" checked; organic groups settings: "Group node" checked)

 

Organic Groups configuration ( admin/og/og ):

Group details:

  1. check "New groups don't appear in the groups directory. Administrators control the directory exclusively." in Groups directory control.
  2. check "New groups don't appear on the registration form. Administrators control the form exclusively." in Registration form control.
  3. Do NOT CHECK "Audience checkboxes"
  4. check "Required" in "Audience required"
  5. choose "none" in "Group home page view

 

Organic Group ACCESS configuration ( admin/og/og_access ):

  1. check "Visible only within the targeted groups." in Visibility of posts
  2. check "New group home pages and default audience are always private" in Private groups

 

OGUR configuration ( admin/og/og_user_roles ):

  1. check both "authors" and "moderators" in "Roles for Departments groups"

 

Blocks ( admin/build/block ):

  1. Enable the 'Group details' block and place it in your page layout

 

Create contents ( /node/add/departments ):

  1. Create 2 new groups: "Department-A" and "Department-B" (Membership requests: "Closed", and "Private group" checked for both groups)

 

Create users ( admin/user/user/create ):

  1. Create 4 users with the following usernames (Be sure NOT TO CHECK ANY ROLES HERE):
    • Department-A_Moderator
    • Department-B_Moderator
    • Department-A_Author
    • Department-B_Author

 

Assign permissions to users ( admin/user/permissions );

In the "node module" section give the following permission:

  1. "create articles content" only to AUTHORS
  2. "edit any articles content" only to MODERATORS

 

Assign users to groups:

  1. Department-A ( og/users/1/add_user ): write "Department-A_Moderator, Department-A_Author" in the users list and click "add users"
  2. Department-B ( og/users/2/add_user ): write "Department-B_Moderator, Department-B_Author" in the users list and click "add users"

 

Assing OGUR roles to users:

  1. Department-A ( og/users/1/roles ): be sure to chek respective roles to listed users and save
  2. Department-B ( og/users/2/roles ): be sure to chek respective roles to listed users and save

 

Login with different users:

Ok, to do things quickly, if you are now logged in as administrator in Firefox, my advice is to open 4 different browsers (IE, Opera, safari, Chrome) and do login for each user you have created before.

Create articles contents:

  1. Create a new Article with your "Department-A_Author" user ( node/add/articles?gids[]=1 )
  2. Create a new Article with your "Department-B_Author" user ( node/add/articles?gids[]=2 )

Notice that, thanks to OG access restrictions, "Department-A_Moderator" can edit only "Department-A_Author" content, and "Department-B_Moderator" only "Department-B_Author"

 

Ok, now the CRUCIAL POINT:

We are going to do a single View with a default beaviour, but with different VIEW DISPLAY by OGUR Roles, exactly a new display for each OGUR role.
E.g we can create a new View, but to do things quickly we can modify existing default OG Views. Let's choose the "og_tracker" view in the available views in our site ( admin/build/views/edit/og_tracker ):
Do the following modification to the "og_tracker" View:

Modify the existing PAGE display like this:

Basic settings:

  1. change the display name with "Moderator tracker"
  2. change the ACCESS settings to ROLE (do not update default display, but OVERRIDE it) choosing "moderators" in the Access Options roles list.

 

Now add a new PAGE DISPLAY to the "og_tracker" View:

Basic settings:

  1. change the display name with "Authors tracker"
  2. change the ACCESS settings to ROLE (do not update default display, but OVERRIDE it) choosing "authorss" in the Access Options roles list.

Page settings:

  1. give the same path already existing in "Moderators tracker": "group/tracker"
  2. give the same menu already existing in "Moderators tracker": type: "Menu tab", title: "Recent posts", weight: 5

 
Ok we have now 2 different display for the same View by user role, but let's insert any kind of differences to give meaning to this separation:
We can insert a lot of diffrences to these displays as needed, but for our purposes do only this:
In "Authors tracker" > FIELDS options, remove the "Organic groups: Groups Groups" field (PAY ATTENTION: do not update default display here, but OVERRIDE it to have this feature only in this this display!)

 

Final test to show the bug:

In our 4 browsers already opened, with different users logged in, try to view our modified TRACKER view: (or type "/group/tracker" in your browser url bar) and ... TA DA! "Access denied" for ALL USERS!!! Why?!?!?!? it doesn't work because (I think) Views checks the CORE role of a user, and my users doesn't have CORE roles, but only "OGUR roles".
to prove this, let's simply add the right CORE roles to our users ( /admin/user/user ) and respective views display will be shown correctly (obvously we can't keep this settings because OGUR doesn't want this to work correctly)

(See images in attachment)

PLEASE: resolve this!

Thank you very much for your work

MXT

mxt’s picture

I don't know if the following hypothesis can help somehow... by the way:

I think that the issue can be approached in a more "macro" level, in this way: "Find a way to keep optionally OGUR roles outside OG context".

There are several situations and modules that can really need this new feature, for example:

  • Rules module has the same problem like Views: it cannot chek OGUR roles ouside OG context and I cannot setup rules conditions properly.
  • Views Bulk Operations roles restrictions: the same. It cannot check runtime OGUR roles but only CORE roles

I don't know: we can set any kind of variable at the top of pages to automatically set OG context? Can OGUR do that by itself? Is its competency area or this have to be done by another module like OG? Otherwise Context module ( see my comment #4 ) ?

MXT

mxt’s picture

About Views issue:

I think that if one of this feature is setted in a Views:

  • Views Relationships: Organic groups: Group node (post)
  • Views Arguments: Organic groups: Groups

OGUR consequently would offer an option to keep OGUR roles in the view "access restriction - by role" feature.

What do you think about?

Thanks

mxt’s picture

I noticed that DOMAIN module do what I've asked in my previous comment: it offer the option "access restriction - by domain" to Views.

I think OGUR would offer a similar feature to Views.

sun’s picture

Views already contains such an access restriction "by role" feature (and even also "by permission"). Therefore, OGUR does not need to reinvent such an access plugin.

I'm not sure what's left to be done or not yet clear in this issue.

mxt’s picture

Views already contains such an access restriction "by role" feature (and even also "by permission"). Therefore, OGUR does not need to reinvent such an access plugin.

Yes, but these restriction doesn't works with OGUR.

I think there's REALLY need what I've already asked in #10:

if one of this feature is setted in a Views:

  • Views Relationships: Organic groups: Group node (post)
  • Views Arguments: Organic groups: Groups

views access restriction would work with OGUR but actually it doesn't.

Sun, I continue seriously think this is a OGUR lack.

Thank you

MXT

mxt’s picture

Title: Views integration: view access by OGUR role » Views "access restriction" by role doesn't work with OGUR (even if OG context is correctly kept)
Category: support » bug

What I have to do to obtain the right consideration? I think an evasive answer "per month" is not serious.

Please first read my desperation here: http://drupal.org/node/732848#comment-3099766.

NOW: After MONTHS of tests, researches, issues opened everywhere, various alternative explored without success and after Views maintainer response (http://drupal.org/node/759264) I DEFINITIVELY think this issue is a OGUR BUG.


BUG DESCRIPTION:

Views "access restriction" by role doesn't work with OGUR (even if OG context is correctly kept)

I'm working on my project (summarized here: http://drupal.org/node/711246 and here: http://drupal.org/node/742676#comment-2855062 and simplified here: http://drupal.org/node/737292#comment-2846284 ) since 8 months, but the BUG above stopped me to finish.

I made any kind of experiment: but at the end there is always nothing to do. The following is the list of only SOME of the innumerable tests I made:

  1. Tried any kind of combination using OG relationship: "Group node (member)", "Group node (post)". RESULT: when "access restriction by role" is seated up user still cannot access the View.
  2. Tried any kind of combination using OG arguments: "OG group node", "OG groups", "OG member of a group". RESULTS: when "access restriction by role" is seated up user still cannot access the View.
  3. Tried to force OG context using a Views Attachment and custom php script like suggested here: http://drupal.org/node/650178. RESULT: OG context is correctly seated up and printed in page in the attachment, but when "access restriction by role" is seated up user still cannot access the View.
  4. Tried to force OG context using custom php script in the head of the View like suggested here: http://www.opensourcecatholic.com/blog/oscatholic/set-views-context-inside. RESULT: when "access restriction by role" is seated up user still cannot access the View.
  5. Tried to using other modules to try to keep OG context (CONTEXT, SPACES, PURL, FEATURE, SPACES OG). RESULTS: all negative. (only spaces-og with purl seems working, but I cannot accept purl token insertion in all url of my site)
  6. Tried to rebuild the entire site from scratch using the solution described here: http://drupal.org/node/408052 (revisioning module). RESULTS: this solution doesn't work in my case.
  7. Tried to rebuild the entire site from scratch using alternative architecture: DOMAIN ACCESS: yes, resolve some issues, but it create other issues and owever I cannot use a solution based on subdomain for mi site.
  8. Tried to rebuild the entire site from scratch using an OG alternative: node-access-user-reference + node-access-node-reference like described here: http://nodeone.se/blogg/johan-falk/alternative-solution-to-organic-groups. RESULTS: views access restriction works correctly because there isn't OGUR. (roles are seated up in the CORE user profile), but at the moment node-access-node-reference is very bugged and I cannot use this solution (and also this architecture introduce some limititions and other difficulties).

CONCLUSION: the best results I've reached is using OG + OGUR, but this BUG cannot allow me to finish my work.

PLEASE can you seriously consider to resolve it?
(or tell me if I'm doing something wrong or missing something or suggest me an alternative to reach the goal)

Thank you very much.

MXT

michaelfavia’s picture

While i understand your frustration with the problem you are having I don't see any attached patches with your comments and they tend to come off as slightly ungrateful and entitled to help. Daniel has zero requirement to scratch your itch for you or even fix a bug in the module he helps maintain if he chooses not to do so for any reason he likes. A certain amount of frustration could be understood if you demonstrated an actual bug and provided a patch but withstanding that case I'm inclined to think this is your problem if you care to resolve it.

mxt’s picture

Hi Michealfavia, thank you for your answer, I'm not sure if I correctly interpreted your answer due to my poor english: I'm sorry for this.

You talked about patches: if I was a programmer I'll surely bring my contribute with a patch, but I'm not, so I can't do it. All I can do is research everywhere in Internet for issues similar to mine, and try to resolve with these examples/advices. I also know that maintainers need as more information as possible on a issue, so that's why I tried to do in this thread, writing from scratch a step by step to reproduce the issue (see: http://drupal.org/node/737292#comment-2846284 ), experimenting by myself different alternatives and try to help doing supposition, all time (very very lot of) I dedicated to this issue can be inferred reading this thread from top. I really don't know what still I have to do to demonstrate the bug, but I have a question: does someone tried to reproduce it following my step by step? It's not enough that?

We are not talking about a personal and restricted issue I think, we are talking that OGUR doesn't do what it promise to do using it in combination with VIEWS, a TOP module used by everyone here. OGUR under an OG context must grant additional roles to user under that context, but in a page made with Views where OG context is anyhow present OGUR doesn' do his job with Views access restriction by role seated up. This is my conclusion, and this is what I tried to demonstrate in all this thread. I did as much as possible to demonstrate it, there is obviously the possibility that I'm in error due to some lacking/wrong Views or OGUR parameters configuration but at this point is some other task to demonstrate it.

In conclusion I think resolving this can help the entire Drupal Community and not only my need.

Anyway, advices are always appreciated: what can I do now the bring more help to resolve this issue o to put somebody in condition to resolve it?

Thank you very much

MXT

hubarbeit’s picture

Status: Postponed (maintainer needs more info) » Fixed

I need Views to know of OG user roles myself, so I did some "research":

OGUR has to be called before the Views' access plugin, so make sure OGUR has the weight '-1' in the system table. This seems to be included since version 6.x-4.0. Try the latest release and remember to run update.php (as I forgot at first)...

sun’s picture

hum... did we forget a module update at some point to adjust the weight? It should be installed with -1 by default, but I'm not sure whether this is properly adjusted for older versions.

mxt’s picture

Version: 6.x-4.0 » 6.x-4.1
Status: Fixed » Active

I'm using the latest version of OGUR (6.x-4.1) and the weight was already seated to -1 in the system table.

itsnotme’s picture

I feel your pain, I need a better OGUR/Views integration too, but frankly, given the time you obviously spent on the subject, you rather should've tried to hire a programmer for this. This is a free and open-source software, delivered as-is, and it won't help if you demand a solution for your problem once a week.

Speaking of which, I'll try to throw my programming student onto our own OGUR/Views problem...(which is aimed at better administrative filters for users with role x in group).

mxt’s picture

Priority: Normal » Critical

I have no idea about how much it would cost hiring a programmer to specifically resolve this bug.

Does anyone have a suggestion or a bid for ?

Thank you!

j.helmer’s picture

I have a solution for this. I needed OG User Roles access integration with views for a client, and there was no getting around it.

I wrote a views plugin that extends the normal views_plugin_access class. The name of my module is 'm29_organization', so you will have to take this into consideration. I have never written a patch, nor do I have much interest in learning how to do so at this time, so if someone else would like to submit a patch for OGUR, be my guest.

In m29_organization.module:

/**
 * Implement hook_views_api().
 */
function m29_organization_views_api() {
  return array(
    'api' => 2.0,
    'path' => drupal_get_path('module', 'm29_organization') . '/includes'
  );
}

/**
 * Access callback for use with m29_organization_ogur_plugin_access.
 *
 * Determine if the specified user has access to a view on the basis of any of
 * the requested OG user roles. If the $account argument is omitted, the current user
 * is used.
 */
function m29_organization_ogur_access($rids, $gid_arg, $account = NULL) {
  global $user;
  $account = isset($account) ? $account : $user;
  og_user_roles_grant_roles($account, node_load(arg($gid_arg)));

  $roles = array_keys($account->roles);
  $roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;

  return user_access('access all views', $account) || array_intersect(array_filter($rids), $roles);
}

in includes/m29_organization.views.inc:

/**
 * Implement hook_views_plugins().
 */
function m29_organization_views_plugins() {
  $path = drupal_get_path('module', 'm29_organization') .'/includes';
  return array(
    'access' => array(
      'ogur_plugin_access' => array(
        'title' => t('OGUR'),
        'help' => t('Will be available only to the following OG user roles.'),
        'handler' => 'm29_organization_ogur_plugin_access',
        'uses options' => TRUE,
        'path' => $path,
      ),
    ),
  );
}

In includes/m29_organization_ogur_plugin_access.inc:

/**
 * Access plugin that provides role-based access control.
 */
class m29_organization_ogur_plugin_access extends views_plugin_access {
  function access($account) {
    return m29_organization_ogur_access(array_filter($this->options['role']), $this->options['group_arg'], $account);
  }

  function get_access_callback() {
    return array('m29_organization_ogur_access', array(array_filter($this->options['role']), $this->options['group_arg']));
  }

  function summary_title() {
    $count = count($this->options['role']);
    if ($count < 1) {
      return t('No role(s) selected');
    }
    else if ($count > 1) {
      return t('Multiple roles');
    }
    else {
      $rids = views_ui_get_roles();
      $rid = array_shift($this->options['role']);
      return $rids[$rid];
    }
  }

  function option_defaults(&$options) {
    $options['role'] = array();
    $options['group_arg'] = '1';
  }

  function options_form(&$form, &$form_state) {
    $form['role'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Role'),
      '#default_value' => $this->options['role'],
      '#options' => views_ui_get_roles(),
      '#description' => t('Only the checked roles will be able to access this display. Note that users with "access all views" can see any view, regardless of role.'),
    );
    
    $form['group_arg'] = array(
      '#type' => 'textfield',
      '#title' => t('Group Argument'),
      '#default_value' => $this->options['group_arg'],
      '#description' => t('Define which path argument is the group nid.'),
    );
  }

  function options_validate(&$form, &$form_state) {
    if (!array_filter($form_state['values']['access_options']['role'])) {
      form_error($form['role'], t('You must select at least one role if type is "by role"'));
    }
    
    if (empty($form_state['values']['access_options']['group_arg'])) {
      form_error($form['group_arg'], t('You must specify a valid path argument.'));
    }
  }

  function options_submit(&$form, &$form_state) {
    // I hate checkboxes.
    $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);
    $form_state['values']['access_options']['group_arg'] = $form_state['values']['access_options']['group_arg'];
  }
}

Basically to sum everything up, this duplicates the basic role access plugin provided by views, adds a form element to specify which path argument is used as the group id, and calls a custom handler that integrates with OGUR.

The group context does not need to be set anywhere else for this to work. I saw numerous postings regarding setting the group context in the views header, but this is terrible practice. If you need the group context for something other than access, it should not be done in the views header (someone unrelated, but feel it is important to mention it here).

A couple additional notes:

  • In my access callback, I call node_load. If someone has a suggestion on how to improve this for best practice, that would be great.
  • My access callback also calls arg(). If someone would like to improve on this to actually pull in the argument from the context of the view (in the plugin), that would be great.

Hope this helps everyone!

sun’s picture

Version: 6.x-4.1 » 6.x-4.x-dev
Category: bug » task
Priority: Critical » Normal
Status: Active » Needs review
StatusFileSize
new3.52 KB

That would translate into this OGUR patch for me. By all means, I'm no expert in this area. No idea how to make it use a proper Views/Panels context. But if this happens to work, I'm happy to move forward with this already and commit it.

sun’s picture

Also, @j.helmer, you should totally learn how to do patches for Drupal! :) http://drupal.org/patch will help you. Everyone in IRC #drupal on irc.freenode.net will certainly too!

j.helmer’s picture

@sun -

thanks for the pointer. I will definitely learn how to do patches as I get more involved in the drupal community, though I develop for drupal professionally, so I would have to learn it on my own time or when we are not busy and there is time for drupal research.

sun’s picture

@j.helmer: Many (if not even most) people in the Drupal community are doing exactly what you are doing, and they learned it on purpose -- consider that you don't need to apply any hack or workaround next time you need a functionality, and, that you can freely update to newer versions at any time.

Sorry for this off-topic interlude. :)

mxt’s picture

Hi all,

First I want to thank j.helmer for his contribute: thanks a lot!

I've tried to apply the patch provided by Sun in #23: the patch was applied successfully (modifications and new files and folder correctly created in OGUR main folder), then I've cleared the site cache, made a site update, but now I can't see how and where to set the new features.

Can you give me a suggestion? What I have to check/set and where? (In my Views "basic Settings", at the "access" item, I can't see any new option)

Thank you very much!!!

j.helmer’s picture

@sun - Thank you for your input. I look forward to contributing more to the Drupal community.

@MXT - Just use role-based access as you normally would. It just "works."

j.helmer’s picture

I attached a screen shot in case my previous explanation lacked.

@sun - Not sure how this works, but should we change the status of this issue to "Patch" so we can get it ported into the next stable release?

j.helmer’s picture

@MXT - I spoke too soon. This morning, I removed the code from my module and tried applying the patch sun made. It didn't work. Looking through the code, I found a few problems:

  • My code points to an includes/ directory, so og_user_roles.views.inc and og_user_roles_plugin_access_role.inc should lie in a subdirectory called includes.
  • The plugin should use its own namespace (I just switched it to ogur_role), but sun changed it to 'role'.. this can cause a lot of bad things to happen:

Note that unlike handler registration, where parentage is referred to by object name, with plugins it is referred to by the unique plugin identifier. Please be sure to prefix your plugin identifiers with your module name to ensure namespace safety; after all, two different modules could try to implement the 'grid2' plugin, and that would cause one plugin to completely fail.

                                                                                                                                                                                                                                                                ~merlinofchaos

  • For some reason, even after all those changes are made, views is not happy. When trying to choose the access role, views AJAX complains: "Class views_plugin_access_role not found"
  • It works when extending views_plugin_access as I had originally done, except that sun has modified the code to rely on the parent plugin, so we need it to work with views_plugin_access_role.

@sun - Any input here? To start out, the patch should drop those .inc files into an includes/ directory. Next, we need to figure out how to properly extend views_plugin_access_role.

Does anyone else have any pointers about how to accomplish this? I created a new forum topic about it: http://drupal.org/node/873710

sun’s picture

Sounds like a bug in Views' plugin autoloading.

j.helmer’s picture

Not quite there:

  • The actual access doesn't work. I am not sure what access callback is being run, but I'm not getting any devel output from function access() at all.
  • Maybe get_access_callback is necessary? It was working perfectly before your improvements, and I had that defined.
  • hook_views_api() no longer points to /includes, but hook_views_plugin() does. The patch should probably force the views.inc and plugin include to reside in an includes directory (from http://drupal.org/patch/create):


Adding directories

It is also possible to use cvs patches to add a directory. For example, to add an add-on module to an existing module.

1. Within a directory that cvs knows about, add a new file to cvs shown above. With contributed modules, this would be in the root directory of that module.
2. Create the patch file by modifying CVS/Entries and using the -N switch shown above.
3. Edit the patch file adding the directory path that the files should reside in.
4. Example shown below, the first part shows the first few lines of the patch file created in the module root, after editing, I manually add 'contrib/exhibit_apachesolr' in front of any reference to the new file.
5. After running the patch file, on a cvs checked out module, it creates both the file exhibit_apachesolr.info inside the created directory exhibit_apachesolr (that resides under contrib).

Index: exhibit_apachesolr.info
==============================================================
RCS file: exhibit_apachesolr.info
diff -N exhibit_apachesolr.info
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ exhibit_apachesolr.info 8 Nov 2008 16:18:41 -0000
Index: contrib/exhibit_apachesolr/exhibit_apachesolr.info
==============================================================
RCS file: contrib/exhibit_apachesolr/exhibit_apachesolr.info
diff -N contrib/exhibit_apachesolr/exhibit_apachesolr.info
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/exhibit_apachesolr/exhibit_apachesolr.info 8 Nov 2008 16:18:41 -0000
sun’s picture

Note that I have no use-case for this feature/patch myself, just trying to get you guys getting along.

The actual access doesn't work. I am not sure what access callback is being run, but I'm not getting any devel output from function access() at all.

I would have tested it, but I'm not sure how to use this access plugin, effectively.

Maybe get_access_callback is necessary? It was working perfectly before your improvements, and I had that defined.

Can you try? I've seen you had that in your code, but upon looking up what Views actually does in that logic/code, it didn't look like it would be necessary.

hook_views_api() no longer points to /includes, but hook_views_plugin() does.

Ok, looks like my preference breaks some expected standard file layout. ;) Fixed. Shouldn't have an impact on the functionality though.

However, s/includes/views/. Views is not the only API that allows other modules implement plugins.

Hope this helps.

mxt’s picture

Thank you Sun, I've just tried patch #33 and it creates a new "views" folder and puts "og_user_roles.views.inc" and "og_user_roles_plugin_access_role.inc" inside.

I've cleared all caches (views cache also) but unfortunately the patch doesn't work: users with specific OGUR roles can't access to their specific Views display (access denied).

mxt’s picture

I'll try to describe the problem better:

With this patch I can now see a new "OG role" radio option in Views "basic-settings -> access" admin panel (YEAH!!! ;-).

So I choose this option, click "update", but I have no feedback: the GUI seems to "reset" and no modification are seated at the "access" row. I think it have to lead to a second GUI panel where I'd can choose the OGUR role instead.

mxt’s picture

In the meantime I tried the module in http://drupal.org/node/729256#comment-3288276 but "views access restrictions by OGUR roles" still doesn't work for me.

@j.helmer, I have a question for you: under "access options" form, where OGUR roles are listed to choose from, there is a "Group Argument: Define which path argument is the group nid." input form. What is this supposed to do? How it works? I have no arguments in my path and no views arguments defined: I retrieve group context using "Organic groups: Group node (post)" RELATIONSHIP and filter Views results with "(Group) Organic groups: Group member" filter (so a user can view only his group items).
What can I do in this case? any suggestion?

Thanks

MXT

khad’s picture

StatusFileSize
new82.07 KB
new62.48 KB

Hey MXT,
I can feel your pain - being not a programmer, I had to give up on a project to build a drupal site because I couldn't get the permissions system to work properly (didn't hurt as much, though, since it was just for my own needs). The problem was probably the same as you suffer from:
- on a group node (e.g. ?q=node/61), the OGUR permissions are clearly there, as the the group detail block shows (see group-node.jpg)
- navigating to a viewtab on the node (e.g ?q=node/61/documents), the group context is still there (otherwise the detail block wouldn't display), but the OGUR permissions are clearly missing (see group-node-view-tab.jpg).
If money can fix this (hiring a programmer) I might throw in some of my meager resources.

gmclelland’s picture

subscribing

j.helmer’s picture

Hey, guys. Sorry I haven't been available for a while.

@MXT: in response to the following:
@j.helmer, I have a question for you: under "access options" form, where OGUR roles are listed to choose from, there is a "Group Argument: Define which path argument is the group nid." input form. What is this supposed to do? How it works? I have no arguments in my path and no views arguments defined: I retrieve group context using "Organic groups: Group node (post)" RELATIONSHIP and filter Views results with "(Group) Organic groups: Group member" filter (so a user can view only his group items).
What can I do in this case? any suggestion?

I built the access plugin for a particular case, where the argument is available in the url. My only suggestion (other than writing a new plugin, or re-writing this one) is to change up the way your view works to grab an argument from the url (if possible). Sorry; I don't have the resources right now to develop this more.

@khad: Be sure to set the ACCESS RESTRICTION on the /documents view to OGUR and select "1" as the OGUR context argument. You should be good to go, assuming MXT's patch works (I never tried his revised version of my code).

szantog’s picture

I'm not a views guru, but I needed this function in views3. I've made it - I think - compatible with views2, based on patch #33.
I've just downloaded the http://drupal.org/project/og_views_extra, and merge some useful thing.

The goal was the next: I wan't use an independent callback function, when ogur settings active in views.

I've changed the numbering of argument, if it's zero, there aren't argument validation, just use a default group context.

In plugin I don't use anything from parent in access and get_acces_plugin functions, just set callback to

  function get_access_callback() {
    return array('og_user_roles_view_access', array(array_filter($this->options['role']), $this->options['arg_group']));
  }

And the access callback:

/**
 * User role views access helper function.
 *
 * @return Has the current user access on current view.
 */
function og_user_roles_view_access($rids, $arg) {
  global $user;

  if ($arg == 0) {
    $group = og_get_group_context();
  }
  else {
    $group = node_load(arg($arg-1));
  }

  //Now we can use the normal arg() mapping in views settings page??
  if ($user_roles = og_user_roles_grant_roles($user, $group)) {
    foreach($rids as $rid) {
      if (array_key_exists($rid, $user_roles)) {
        return TRUE;
      }
    }
  }
}
szantog’s picture

Hmm.. The previous doesn't respect 'access all views' role..

timefor’s picture

... n/m

Dave Cohen’s picture

I'm debugging the same issue on one of my sites. I haven't tried the patches in this thread, and I'm pretty skeptical whether they are taking the right approach.

As far as I can tell, there are two problems. Again, this is without applying patches, and using the regular views access by role.

First problem, the main problem here, is Drupal's menu code is calling views_access() before OGUR has a chance to add roles. I'm not sure if there's going to be any easy way to get OGUR to act first.

Second problem, is og_user_roles_grant_roles() fails to learn the group context. It has fancy-pants code that inspects the menu items. But that slick stuff works on menu paths like node/%menu/edit, but not node/%/members (i.e., the kind of menu path that views adds - note the %node versus just plain %). See #940462: OGUR permissions lost while in OG context for a possible fix for this problem.

Dave Cohen’s picture

Update with a correction... the first problem is not that drupal's menu is calling access hooks too soon. Rather, it is og_user_roles_init that is causing the access hooks to be called.

There's a comment above og_user_roles_determine_context() which clearly states this is undesirable:

 * The only difference to the original og_determine_context() is that we are
 * intentionally using our own menu system functions, so we can determine
 * the group context without setting access for the current menu path (which
 * is statically cached in menu_get_item()).
 *

... despite the comment, og_user_roles_menu_translate() later calls _menu_load_objects(), which I think because of i18.module causes menu to call the access hooks and cache results. It's a long convoluted stack trace. I think this problem only occurs when i18n.module enabled. I also think I've encountered it before and worked around it with a custom hook_init(). I need to search for that thread...

Dave Cohen’s picture

Ok, hopefully the last time I have to correct myself in this thread.

It's not becasuse og_user_roles calls _menu_load_objects. Rather, it's all baked into i18n.module. Anything that calls node_load() will cause i18n to cause drupal to call the access hooks.

I put a terrible hack into my custom module's hook_init to work around this. Feel free to use it. You'll need to change my test for node type 'group' to whatever is appropriate for your site. And you'll need to adjust your custom module's weight to come before og_user_roles or any module that might call node_load in hook_init.


/**
 * Implements hook_init().
 *
 */
function CUSTOM_init() {
  // For complex reasons, when i18n enabled, we need to do this BEFORE og_user_roles_init() is called.
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    i18n_selection_mode('off'); // i18n will screw up og_user_roles.
    $node = node_load(arg(1));
    i18n_selection_mode('reset'); // return i18n to it's original mode.
    node_load(0, 0, TRUE); // reset node_load cache

    if ($node && $node->type == 'group') { // Is there a better test for group?
      global $user;
      og_user_roles_grant_roles($user, $node);
    }
  }
}

I don't know whether it makes sense to put something directly into og_user_roles, for those cases when i18n is enabled. All you'd have to do is i18n_selection_mode('off') at the start of og_user_roles_init(), and reset that mode, and the node_load cache at the end. I leave that up to you.

sun’s picture

@Dave Cohen: Thanks for the analysis. So after all the debugging, it looks like your issue is actually a separate one and not related to this here about Views? If so, we might want to create a separate for i18n compatibility/integration? (and link to it from here)

hosais’s picture

scribe

fxarte’s picture

I believe that the cause of this issue is related to how the module, and og, determine the group context: og_user_roles_determine_context(), and og_determine_context().

Essentially both modules, group context calculation depends on the path of the request, and that it must contains the information needed to determine the OG, either a nodeID or the the query parameter: gids . But in the case of a views page, it is not included, resulting in that the group value will be NULL, see both: og_determine_context(), and og_user_roles_determine_context(), and then og_user_roles_grant_roles() will not assign the proper roles to the user.

This situation may happen on any defined path in the site that does not contain the OG information, such as AJAX callbacks (filefield, realname_userreference), views, hook_menu implementations, etc.
In my case, the issue was that when a user was editing a node, they would get a filefield access denied popup. The site uses Content Permissions.

To solve this I had to add in my implementation of hook_init, this code:

  // Only if it is not possible to determine the og context
  if (!($og = og_get_group_context())) {
    //the path may be a view with a URL pattern as: node/%/edit/extra-operations-etc
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $current_node = node_load(arg(1));
      $og = og_determine_context_get_group($current_node);
      og_set_group_context($og);
      $_SESSION['gid'] = $og->nid;
    }
    else {
      if (isset($_SESSION['gid']) && is_numeric($_SESSION['gid'])) {
        $og = node_load($_SESSION['gid']);
        og_set_group_context($og);
      }
    }
  }

This is assuming that the user already have access to edit the node. Also I needed to reset the custom module weight to be lighter then og and og_user_roles.
You may include other conditions particular to your case.
Also adding ?gids[]=### to the URL should fix this issue without any programming.

I know is not specifically for your case, but I hope it helps.