Hello,

I would like to have the view/list/etc permission be a filter in views.

Our setup is unusual in a sense that there is a double-tier access to each node. All the nodes have general access, and everyone can post comments and read about the node, but they can view the video embedded in the node only if Taxonomy Access gives view permission. This is where it would be extremely helpful if I could set up a filter on TAC's view permission in Views.

Any ideas would be greatly appreciated.

Thanks,
Andrey.

Comments

mr.andrey’s picture

By the way, until now, I've had this working with an argument:

global $user;
return db_result(db_query("SELECT GROUP_CONCAT(CAST(tn.nid AS CHAR) SEPARATOR ',') FROM {term_node} tn INNER JOIN {term_access} ta ON tn.tid = ta.tid WHERE ta.rid IN (SELECT ur.rid FROM {users_roles} ur WHERE ur.uid = %d) AND ta.grant_view = 1", $user->uid));

But unfortunately at around 300 nodes it gets overwhelmed, and just ignores the rest.

I need help translating this into a views filter.

Andrey.

mr.andrey’s picture

Status: Active » Needs review
StatusFileSize
new1.06 KB

OK, here is the "patch" (sorry not sure how to do multi-file patches).

This adds filters for each of the TAC permissions: view, update, delete, create, list (see under Node).

In taxonomy_access.module, add this (to the bottom or anywhere really):

function taxonomy_access_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'taxonomy_access') . '/includes',
  );
}

And unzip the attached "includes" folder file inside the taxonomy_access module folder.

I've tested and it seems to be working just fine.

Tutorial on how to write a Views filter

Best,
Andrey.

mr.andrey’s picture

StatusFileSize
new8.61 KB

Here's the actual patch. And just for reference, here's the command for creating recursive multi-file/folder patches:

diff -uprN folder.orig folder.new > new.patch
xjm’s picture

Interesting. I know there's a patch out for Views itself to filter by whether the user has Edit permission for the node, etc., but that would not cover TAC's create/list.

+1. I'll try to do some more testing with this patch.

lhristov’s picture

/** EDITED
Great idea to add view filters. It is exactly what I need. It seems to not work for me for anything but the TAC grant view.

I get an error for each other filter field:
"Error: handler for node > taxonomy_access_update doesn't exist!"
If I'm trying to add TAC grant delete the error changes to
"Error: handler for node > taxonomy_access_delete doesn't exist!"

Any ideas?

Thanks
*/
Figured it out:

The names of the classes in the includes folder are wrong for each handler
class taxonomy_access_handler_filter_view
should become:
class taxonomy_access_handler_filter_create

mr.andrey’s picture

StatusFileSize
new8.62 KB

Nice catch, thanks!

Here's the updated patch.

egghunter’s picture

Subscribing

xjm’s picture

Status: Needs review » Reviewed & tested by the community

I'm now using this feature on one of my sites. Very nice. I plan on committing this with a few minor changes, unless anyone else reports any trouble with it.

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed after some cleanup:
http://drupal.org/cvs?commit=416050

xjm’s picture

This feature is now available in the dev branch. One thing I notice is that this filter only returns term-specific grants for the node, and excludes grants inherited from vocabulary or global defaults. I have opened a separate issue for this at: #901938: Views filters exclude nodes with grants inherited from global or vocabulary defaults

Status: Fixed » Closed (fixed)

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