0

Let's say that I have a user role called ARTICLE_VIEW_EDIT which has permissions to view and edit own articles nodes. I have the following 2 cases.

  • I want to give extra permission, delete own articles permission to a user - user101 who has the user role ARTICLE_VIEW_EDIT and this modification must not affect the user role.
  • I would like to remove edit permission from a user - user102 who has the user role ARTICLE_VIEW_EDIT and this modification must not affect the user role.

After doing some research I have found out that I could use the Role class to create custom user roles but that will be saved as configuration not as a record in the user__roles tables hence I am not getting the output that I'm looking for.

1 Answer 1

1

You can't do that, at least with standard Drupal setup. Probably you can code a hack that allows it, but is not how Drupal is designed.

Besides this, you can use current role system to achieve what you want. You only need to add more roles. You want edit own articles, view own articles and delete own articles to be independent. You can define 3 roles, and assign to users as you need.

If your problem is you'd have lots of roles (because you want lot of different permissions to be independent) you may use Content Access along with ACL:

This module allows you to manage permissions for content types by role and author. It allows you to specifiy custom view, edit and delete permissions for each content type. Optionally you can enable per content access settings, so you can customize the access for each content node.

[...]

It tries to reuse existing functionality instead of reimplementing it. So one can install the ACL module and set per user access control settings per content node.

Alternatively, you can code your own access system implementing a combination of hook_entity_access, hook_node_access and hook_query_TAG_alter.

You can have a full explanation of how node access rights works on this documentation page: https://api.drupal.org/api/drupal/core%21modules%21node%21node.module/group/node_access/8.8.x

Next, all implementations of hook_node_access() will be called. Each implementation may explicitly allow, explicitly forbid, or ignore the access request. If at least one module says to forbid the request, it will be rejected. If no modules deny the request and at least one says to allow it, the request will be permitted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.