Using ddev, I installed a fresh site with Drupal 9 and Permissions by Term (pbt). I then created some test users, content, and a vocabulary for use with pbt. Everything worked as expected until I tried removing a role from a user and realized that the user still had permission to view content as before.

The reason is that the user edit form has both the role field and the new permissions fieldset for pbt. If you setup pbt to allow view access to a term for a user role, add that role to a user, and then subsequently edit the user to remove the role, the user edit form will add that user back to the term as a user because the permissions fieldset pre-populated the permissions field based on their role. Submitting the form then assigns that user to the terms.

I think the solution is to add a new tab to the user entity for Permissions by Term instead of having the form in the edit tab where it's currently located. The new tab would show an edit form for adding the user to the available terms, but it could also note the terms the user has access to already by way of their assigned roles. This report of the current permissions for the user could look similar to the allowed users and roles fieldset shown on node edit forms. It could also look something like what Workbench Access does.

Workbench Access manages role and user-based assignment of editors to terms like pbt. The difference is that workbench access adds a "Workbench Access" tab to the user entity where you can only control user-level assignment to terms and there's a note about role-based assignments below the form:

Sections assigned by role are emphasized and marked with an * but not selected unless they are also assigned directly to the user. They need not be selected. Access granted by role cannot be revoked from this form.

I hope this helps. I would be happy to test patches and give feedback.

Thank you for this module.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

thoogend created an issue. See original summary.

andileco’s picture

A couple good examples of unexpected results:

1) If you have some very large taxonomies, for example (as is my case) a list of thousands of organizations associated with your site, then performing any action on a user edit page causes the site to slow to a crawl or even crash. This can potentially be remediated by first going to the PbT settings page and selecting a vocabulary that isn't populated with so many terms. It would be better if PbT can automatically determine which vocabularies I've put permissions on and have those selected by default.

2) The first time a user edits their page after this update, they are taken to a rebuild permissions page. This could be a surprise for people who perform administrative functions on a site but aren't directly involved in module updates.

I would prefer the ability to toggle this section on the user page off, as I don't plan to use it (I don't want to override the default behavior I set on the term pages where I was setting at the Role level).

thoogend’s picture

To disable this new feature on the user edit form, I removed lines 219-300 in permissions_by_term.module, which include the following two functions: permissions_by_term_form_user_form_alter() and permissions_by_term_user_form_submit().

luongosb’s picture

I am having the same problem. When I remove roles, the term permissions are still set on the user because of this issue.

This only happens on my Admin role since that is the role that has permissions to view the term permissions information on the user edit page.

This is a pain since I only want to manage the permission by term using roles. I do not want/need to assign individual users using term permissions. This makes managing users a bit of a pain since the module is automatically assigning users to terms. The issue is that this is automatically extending permissions to users on terms that I do not want to allow them to have access to and also it does not remove permissions when I remove a role from the user.

Deno’s picture

This is indeed a very annoying "feature". I tried to find a way to completely remove the permissions by term entry on users' edit page, but administrator will always see it, no matter what.

The only way to handle this at the moment is to NOT use the administrator role and instead add another role that has all the admin privileges except for this one. I *presume* that this is a good practice anyway, but well...

anybody’s picture

Version: 3.1.0 » 3.1.16

Agree to 101%! Can we please make this form on the user page optional by a setting or move it into a submodule or whatever?

The idea behind permissions_by_term is great, but some concepts (like this and the entity submodule) are a bit confusing to me...

chucksimply’s picture

Exactly the same scenario for me as #4. Only need the permissions based on Role, not per individual user. The fact that removing a role from a user doesn't remove the permissions from that user seems like a major issue.

chucksimply’s picture

StatusFileSize
new3.6 KB

Throwing out a patch for anyone who needs a quick fix to user-specific permissions. As @Anybody mentioned, ideally there will be an option for disabling. But for now, this patch does what #3 mentions... removes permissions_by_term_form_user_form_alter() and permissions_by_term_user_form_submit(). Applies cleanly on 3.1.16

anybody’s picture

@ChuckSimply, we finally created a simpler module: https://www.drupal.org/project/entity_access_by_role_field
Feel free to try and help us to test and in coding. :)
Be careful, it's quite new.

For the given reasons above and the maintainers choice to keep things (which is absolutely ok) like they are in some conceptual points we don't agree with, we made the switch. Anyway Permissions by term is a great module, for more complex cases than ours.

chucksimply’s picture

Thanks @Anybody. Looks great... unfortunately I need that access control to be passed off to specific taxonomy terms (which are related to specific roles). Doesn't look that the new module has that capability correct?

anybody’s picture

Thanks @Anybody. Looks great... unfortunately I need that access control to be passed off to specific taxonomy terms (which are related to specific roles). Doesn't look that the new module has that capability correct?

Well I'm not sure if I got you right, but using the module you'd add a role access field to the taxonomy and in the single terms, select which role should (not) have access. But we shouldn't spam this thread, so try it and otherwise feel free to create a support request in the module... but first try :D

chucksimply’s picture

Will do. Thanks again!

gilbertdelyon’s picture

Patch #8 doesn't apply to last updates of "Permissions By Term".
The content of permissions_by_term.module has changed in the meantime.
So, first I built my own patch and ultimately I prefered building a tiny custom module with 2 hooks, and it works!
I expect this way to be safer against future updates of "Permission By Term"

<?php
/**
 * Implements hook_module_implements_alter() for 'user_form'.
 */
function mytinymodule_module_implements_alter(&$implementations, $hook) {
  if($hook == 'form_alter' && isset($implementations['mytinymodule']) {
    // Move our mytinymodule_form_user_form_alter() implementation to the end of the list.
      $group = $implementations['mytinymodule'];
      unset($implementations['mytinymodule']);
      $implementations['mytinymodule'] = $group;
  }
}

/**
 * Implements hook_form_FORM_ID_alter() for 'user_form'.
 */
function mytinymodule_form_user_form_alter(&$form, &$form_state, $form_id) {
  // remove $form['access'] from "user_form"
   $form['access']['#access']=FALSE;
}
chucksimply’s picture

Version: 3.1.16 » 3.1.29
StatusFileSize
new4 KB

Here's a new patch for 3.1.29. Does the same thing, removes permissions_by_term_form_user_form_alter() and permissions_by_term_user_form_submit().

Would be great to get disabling this as an option.

erutan’s picture

Status: Active » Reviewed & tested by the community

Tested the patch in 14 and it cleanly removes the permissions by taxo area from the user edit page.

I'll set this to RTBC just so people know there's a working patch here that solves the problem, even if building out a UI in the app isn't there. I can't see why we'd really want to tie terms to a specific user vs roles given the scope and functionality of the app.

If someone disagrees with that feel free to set it back to active!

marcoliver made their first commit to this issue’s fork.

marcoliver’s picture

Status: Reviewed & tested by the community » Needs review

Hey everybody! Thanks for the input on this issue! I went ahead and created an issue fork that does two things:

  • In the settings there now is a new option to toggle the display of the terms on the user page on and off. (Defaults to TRUE)
  • If the terms are displayed, they are split up by vocabulary to reduce the potential insanity of having tens of thousands of terms in the same select field

Could someone with a bit more mileage on this issue take a look at that fork and let me know if these changes make sense?

  • marcoliver committed 29881be7 on 3.1.x-dev
    Issue #3162679 by chucksimply, marcoliver, thoogend, Anybody,...
marcoliver’s picture

Status: Needs review » Fixed

Hi everyone, I went ahead and merged the fork with the new setting. It will be released in 3.1.31.

Marking this as fixed. Is this issue persists for anyone on 3.1.31, feel free to reopen it or open a new one.

chucksimply’s picture

Looks good. Thanks!

Status: Fixed » Closed (fixed)

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

dtarc’s picture

Hi, we were setting defaults in the permissions by term field when creating new users and this broke our code.

In the user form, splitting up `$form['access']['terms']` by vocabulary was probably an unnecessary change that didn't need really need to happen.

Just making a comment here so that others might find something when looking. It's a hard problem to find if you don't know what's going on.

Anyway this was a breaking change.