- Drupal 6.17, MySQL
- In addition, we are using private upload

I have a role called "VIP user". In Taxonomy Access Permissions screen, VIP users are not allowed to "list" or "create" for "VIP users only" term.

If VIP user edits a page, which has "VIP users only" term, after saving the page its permissions are wrong. I've noticed that $node object's $taxonomy is empty, if user does not have list and create permissions. This may be the reason.

Discussion of this issue and examples of the consequences can be found on the forum:

http://drupal.org/node/878790

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Title: No list or create permissions on any terms may result in incorrect use of vocabulary default on save » Node object's taxonomy is empty if user's role does not have list and create permissions
Category: bug » support
Status: Postponed (maintainer needs more info) » Closed (works as designed)

Be sure you are using the latest version, as there were major bugs in 6.x-1.0.

Edit: I re-read the earlier posts in your forum thread; the part about anonymous users getting view does seem bugged. If you can provide screenshots of your TAC configuration and steps to reproduce the behavior (ideally, from a clean drupal install) using 6.x-1.2, then please set the issue to "active" with that information. The results of devel's node access review would also be appreciated. See the troubleshooting documentation for instructions on using devel.

Regarding the absence of terms in the node object, that is a design behavior. Review the documentation for the List and Create permissions. The user does not have access to the terms without Create; therefore, they are not present in the node object at that time. They are cached internally in TAC and restored in hook_nodeapi() when the node is saved.

xjm’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)
xjm’s picture

Title: Node object's taxonomy is empty if user's role does not have list and create permissions » No list or create permissions on any terms may result in incorrect use of vocabulary default on save
putkonen’s picture

Title: Node object's taxonomy is empty if user's role does not have list and create permissions » No list or create permissions on any terms may result in incorrect use of vocabulary default on save
Category: support » bug
Status: Closed (works as designed) » Active
FileSize
68.66 KB
47.8 KB
62.99 KB
83.44 KB
60.31 KB

Unfortunately I don't have enough spare time to install Drupal from scratch, but I'd be happy to provide you with more information. The screenshots are partially in Finnish but I don't think that's going to be an obstacle for you.

tac_settings.jpg: relevant settings for role "valokuvaaja".

valokuvaaja_before_saving.jpg: view a page, which has "Vain valokuvaajat, toimihenkilöt ja hallitus" (="only photographers, ...") term of category Yksityisyys ("privacy") set. User I'm using is "pasitestaa", only role he has set is "valokuvaaja".

After saving the node: valokuvaaja_after_saving.jpg
(And now also anonymous users have access to this page, so this is where the issue occurs.)

webmaster_before_saving.jpg: logged in as webmaster, before "valokuvaaja" has saved the page.

webmaster_after_saving.jpg: logged in as webmaster, after "valokuvaaja" has saved the page.

If I enable "list" and "create" for role "valokuvaaja", then the information would be similar to that shown for webmaster, and the permissions work as intended.

xjm’s picture

Thanks very much for your quick followup. Just one more thing: what is your TAC configuration for anonymous and authenticated user roles? If you have time to add screenshots for those roles as well, I can hopefully duplicate your setup to debug.

putkonen’s picture

FileSize
78.53 KB
77.2 KB

Sure thing - there you go!

Foorumit stands for - as you might have guessed - Forums :-)

xjm’s picture

I confirmed this bug from a clean install. Steps to reproduce:

  1. Create a role.
  2. Create a user and grant the user the role from #1.
  3. Create a vocabulary.
  4. Add a term to the vocabulary from #3.
  5. Configure TAC as follows for Anonymous:
    Global Default: A/I/I/no/yes
    #3 Vocab Default: D/D/D/no/no
  6. Configure TAC as follows for Authenticated:
    Global Default: A/I/I/no/yes
    #3 Vocab Default: D/D/D/no/no
  7. Configure TAC as follows for the role from #1:
    Global Default: A/I/I/no/no
    Term from #4: A/A/I/no/no
  8. As user 1, create a node tagged with the term from #4.
  9. Log in as the user from #2, edit the node, and save.

The node access records will now be corrupted and the node will be viewable by anonymous users.

xjm’s picture

I believe this bug will require the following changes to fix:

  1. hook_db_rewrite_sql(): Remove create op. Return if on a node edit page.
  2. hook_form_alter(): Set #access to false for terms with no create privs. Replace with optgroup if it is a parent term?
  3. hook_nodeapi()
    Validate op: Notify user that the term cannot be added/removed.
    Update op: Do not allow addition or removal of terms for which the user does not have create.
xjm’s picture

Title: No list or create permissions on any terms may result in incorrect use of vocabulary default on save » Move control of create into hook_form_alter() and hook_nodeapi() to prevent numerous problems.
Version: 6.x-1.2 » 6.x-1.x-dev
Status: Active » Needs review
FileSize
16.88 KB

Attached patch implements the changes in #8 (more or less) and fixes the original issue. I'd appreciate any reviews or testing, because this is a pretty major change.

I did some testing with various sorts of vocabularies and different combinations of create and list in the term hierarchy, and both create and list seemed to behave properly in each case I tried.

This also fixes #112307: Cannot create node in taxonomy term without create permission for parent term and should fix any lingering issues like #660668: TAC + revisioning: Empty taxonomy term select list on node/add for regular users. It's worth noting that, because of #112307: Cannot create node in taxonomy term without create permission for parent term, we will need to provide a hook_update_N() to go with this patch for users who for whatever reason have create checked for a parent term but not its children.

xjm’s picture

Status: Needs work » Needs review

I realized a weakness of this patch: I don't think it will work with Content Taxonomy or any other module that alters the taxonomy form, modules that TAC currently supports. There are definite advantages to using hook_db_rewrite_sql(), despite the problems it also causes. We'd definitely need at least a check of the user's allowed terms in the presave case (instead of the current method).

It's unfortunate that there is no way to set #access on a per-option basis, otherwise we could provide a very simple method to use with other modules. Instead, however, the whole form element has to be overridden. This is a problem with FAPI that persists in D7.

In any case, I think any solution along these lines might need to go in a separate branch. I will look into an alternate way of patching this particular bug in the current branch.

xjm’s picture

Status: Needs review » Needs work
xjm’s picture

Status: Needs review » Needs work

I think I found the root problem for this particular issue:


function taxonomy_access_node_access_records($node) {
  $grants = array();

  if (is_array($node->taxonomy) AND count($node->taxonomy)) {
    /**                                                                         
     * @todo                                                                    
     *    How does deny/ignore work with this?                                  
     */

    // ....
  }
  else {
    // Use the default for nodes with no category 

This uses $node->taxonomy, but _preserve_terms() and _restore_terms() modify the db records directly. So, their alterations are not in $node->taxonomy. The queries don't actually use the data from $node->taxonomy, so as long as the records in the DB are correct by this point, the query will work properly. Just need to actually use the right query.

I wonder if it is possible to use one query regardless of whether the node has terms or not? The current difference is that we use an inner join to {term_node} and then a left join to {term_access_defaults} in the first query, but only an inner join to {term_access_defaults} when the taxonomy is empty.

A workaround might be a simple query to check {term_node} directly. The only other option is to not use hook_db_rewrite_sql() for create, as in #9.

xjm’s picture

Discovered a related bug in the course of troubleshooting #12: #902858: Node records sometimes corrupted after removing all terms from the node

xjm’s picture

I've confirmed that the patch in #902858: Node records sometimes corrupted after removing all terms from the node is another way of resolving this issue.

xjm’s picture

Title: Move control of create into hook_form_alter() and hook_nodeapi() to prevent numerous problems. » No list or create permissions on any terms may result in incorrect use of default on save
Status: Needs work » Fixed

Reverting the scope of this issue because the original problem has been fixed in #902858: Node records sometimes corrupted after removing all terms from the node.

A new issue for changing the implementation of create, as suggested both in the forum thread from the OP and in various @todo in TAC's codebase, is here:
#903522: Move control of create into hook_form_alter() and hook_nodeapi() to prevent numerous problems

Status: Fixed » Closed (fixed)

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