Problem/Motivation

As of Drupal 9.3 each node bundle has it's own permissions tab, e.g. /admin/structure/types/manage/basic_page/permissions
The Node View Permissions permissions are missing there and it would be really convenient to see them there.

Steps to reproduce

- Install node_view_permissions module
- Create a node bundle named "basic_page"
- Navigate to /admin/structure/types/manage/basic_page/permissions

Proposed resolution

I would prefer the Node View Permissions to be added to the permissions tab itself. However, I've looked into the core implementation and I don't see an obvious way to achieve that.
So maybe a more reasonable solution would be to add a seperate tab for "View permissions" right next to the "Permissions" tab.

Remaining tasks

- Build View Permissions form to handle the permissions for a single node bundle
- Display the form on a "View permissions" tab next to the "Permissions" tab

User interface changes

A new tab "View permissions" with a seperate form to handle the permissions.

API changes

Data model changes

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

Paul Dudink created an issue. See original summary.

anybody’s picture

Version: 8.x-1.5 » 8.x-1.x-dev
guido_s’s picture

I think the publication_date module solved this in a good way using permission callbacks in its permissions.yml and then extending the NodePermissions class.

permission_callbacks:
  - \Drupal\publication_date\PublicationDateNodePermissions::nodeTypePermissions
use Drupal\node\Entity\NodeType;
use Drupal\node\NodePermissions;

/**
 * Permissions to "Published On" field.
 */
class PublicationDateNodePermissions extends NodePermissions {

  /**
   * Returns an array of node type permissions.
   *
   * @return array
   *   The node type permissions.
   *   @see \Drupal\user\PermissionHandlerInterface::getPermissions()
   */
  protected function buildPermissions(NodeType $type): array {
    $type_id = $type->id();
    $type_params = ['%type_name' => $type->label()];

    return [
      "set $type_id published on date" => [
        'title' => $this->t('Modify %type_name "Published On" date.', $type_params),
        'description' => $this->t('Change the "Published On" date for this content type.'),
      ],
    ];
  }

}

Something like this could be used here too.

guido_s’s picture

Status: Active » Needs review

I added it like that and opened a merge request.
Please test if everything works as expected.

guido_s’s picture

We need to check if the core version requirements in the info file need to be changed for this. I currently don't know if the NodePermissions class existed in Drupal 8 and only the bundle permissions trait was added later or something like that.

elkaro’s picture

Status: Needs review » Needs work

Working as expected for me. Looks great!

I agree with @guido_s. The NodePermissions class was added on 9.4 (Change record)
So a version of the module specifying that as the minimum core requirement would satisfy the requirements for this issue fork to be merged.

Switching to Needs work, but I think this is RTBC once a release with the updated core version requirement comes out.

anybody’s picture

Drupal 9 is EOL, I think we could require Drupal 10 as minimum, maybe even 10.3!

nagy.balint’s picture

Version: 8.x-1.x-dev » 2.x-dev

Now 2.x is Drupal 10+

  • nagy.balint committed eedbd48a on 2.x
    feat: #3330335 Add node view permissions to the node bundle's...
nagy.balint’s picture

Status: Needs work » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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