I'd like to present a use for db_rewrite_sql: taxonomy rewrites. If this goes through, it will be possible to create an access mechanism, languages and whatever for taxonomy.

This is a very small change, I think, much smaller than the node_rewrite_sql megpatch was 'cos at the moment nothing changes. There are no DISTINCTs deleted. But this opens a door for future things.

Also, this only affects taxonomy.module, 'cos no other module deals with term_data and vocabulary tables (well, forum.module does, but those queries does not need a rewrite).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

please, let's identify some use cases before we run more queries through the regex and hooks implied by db_qeury_sql. There might be a good reason to do this, but you have to convince us.

chx’s picture

In my latest version of db_rewrite_sql, which Dries has not yet commited, regexs are not executed if not necessary. That version was created well before Moshe's post, and I'm pretty sure it will pass, 'cos it is not a feature but a bugfix patch actually.

Until there are no implementations of hook_db_rewrite_sql which cares for primary_field=='vid' or 'tid' , the performance hit is minimal, no regexps.

Jose Reyero’s picture

Use cases:

- Permissions for taxonomy terms/vocabs, some tables and conditions must be joined for taxonomy queries
- Multilanguage pages/taxonomy (i18n), additional conditions needed also for taxonomy

robertDouglass’s picture

+1 for being able to put user/role based permissions on vocabularies. I see this as extremely important (can we do menus too?)

chx’s picture

Yes, we can do menus too. Good idea.

tangent’s picture

This patch has no effect on term/node access.

1. All roles have been given the "access content" permission.
2. I have removed the "all" grant from the node_access table.
3. I have the "Categories" block visible and it is showing the terms and number of nodes which are created.
4. Browsing as an anonymous user I can see the same terms and node count in the categories block that I see as admin.
5. Clicking on a term (/taxonomy/term/2) shows all nodes (and their content) associated with that term. For example, an image node is displayed as a thumbnail and a page node is displayed with the teaser.
6. Clicking on the node title (/node/2) displays a "access denied" message.

Node access is restricted when accessed via node.module but not via taxonomy.module.

Printing out the sql that is generated after the rewrite in taxonomy_term_page(), for example, I don't see any joins added so I guessed that a db_rewrite_sql hook was required for this to be added since the primary in your patch is "tid".

chx’s picture

tangent, this is not that easy. If you rewrite taxonomy queries, you get a chance to make a hook_db_rewrite_sql implementation which fires on $primary_key=='tid'. The only current implementation being node_db_rewrite_sql fires on 'nid'.

tangent’s picture

I don't understand if you are saying that this is hard to implement or should be handled in another module. Are you saying that taxonomy_db_rewrite_sql() is required and needs to fire for 'tid' in order to restrict access as I thought?

chx’s picture

I have made some documentation on hook_db_rewrite_sql though it does not showed up yet.

moshe weitzman’s picture

I'd like to see this patch in core. By running taxonomy queries through db_rewrite_sql() we can achieve two key enhancements:

- access modules can filter out terms to which the current user has no access. this would complete our implemetnation of private forums. jose mentioned this earlier.
- taxonomy node listings and feeds could be filtered by node type using an upcoming simple module which recognizes '&type=event,story' style querystrings as a filter. this will work on taxo lists, home page list, tracker, etc.

there are likely more uses.

tangent’s picture

+1 for me too. The access functionality that this patch enabled is essential in my opinion and should be in 4.6. Without it, the currently implemented node access functionality is worthless.

I think the final patch should include a db_rewrite_sql hook to complete the functionality though.

Bèr Kessels’s picture

+1 from me too. But I would like to see some benchmarking with a database with loads of terms. If someone volunteers I have a DB with approx 300 terms and the same amount of nodes in them. Just give me a private call (berkessels curlythingy gmx dot net) and I might forward it (if i know you ;).

Stefan Nagtegaal’s picture

Is this considered for 4.6 or 4.7??

I like it!

chx’s picture

Do not commit this patch, it is buggy, term_page needs a few more lines (see the privateterms taxonomy patch in my sandbox for code). Will reroll soon.

chx’s picture

FileSize
1.41 KB

This time I think I'd go with small steps. This patch is -- I think -- might be enough for tid rewrites.

moshe weitzman’s picture

this simple change should help us fix the remaining issue with private forums; the dropdown where you pick which forum to post into still shows inaccessible forums.

Dries’s picture

Committed to HEAD.

Anonymous’s picture

Jose Reyero’s picture

Version: » 4.6.0
Status: Closed (fixed) » Active
FileSize
4.04 KB

I think there are a few more queries that should be rewritten. Patch updated for HEAD.

chx’s picture

Version: 4.6.0 » x.y.z
Status: Active » Reviewed & tested by the community
FileSize
4.31 KB

This is long overdue.

moshe weitzman’s picture

jose - it would be nice if we had an example of the new rewrites might be used.

chx’s picture

This is assigned to me, so I'll be the one who answers: if we want to a proper taxonomy access rights module -- taxonomy_access is popular -- then these are needed. The small was enough for forums but not full taxonomy.

Jose Reyero’s picture

Hi,

This is already used by i18n module, and this patch was included as a part of v4.6 of the module. Also, I've just updated i18n-HEAD and you can give it a try.

chx’s picture

Priority: Normal » Critical

I asked moshe aboutwhat's a 'critical feature request' and he says: "i guess if it a feature that many people want or that will enable developers to build many features that people want". To quote a well-respected developer "From what I have seen, a taxonomy-based permission scheme is more popular than one using node types" in http://lists.drupal.org/archives/drupal-devel/2005-04/msg00490.html so I think the second half of the above sentence is in effect.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks.

Anonymous’s picture

slee’s picture

Version: x.y.z » 4.6.0

Can we use this patch on the 4.6 release of taxonomy_access also? Or is this restricted to HEAD versions of the module only?

I am running 4.6.3 stable (not CVS) and would like the features introduced with this patch. If upgrading my site to CVS is the only way to get this functionality (forum restrictions are very important) I will do so. Please advise. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)