Subject: [PATCH] nodeaccess-overview --- Index: src/OverviewPageController.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/src/OverviewPageController.php b/src/OverviewPageController.php new file mode 100644 --- /dev/null (date 1705498785431) +++ b/src/OverviewPageController.php (date 1705498785431) @@ -0,0 +1,127 @@ +database = $database; + $this->entityTypeManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('database'), + $container->get('entity_type.manager'), + ); + } + + /** + * Render Overview page. + * TODO: Make it as an editable form. + */ + public function view() { + $settings = \Drupal::configFactory()->get('nodeaccess.settings'); + $user_storage = $this->entityTypeManager->getStorage('user'); + $node_storage = $this->entityTypeManager->getStorage('node'); + $role_alias = $settings->get('role_alias'); + $role_map = $settings->get('role_map'); + + $build['table'] = [ + '#type' => 'table', + '#header' => [ + 'has_access' => $this->t('Has access'), + 'access_type' => $this->t('Access type'), + 'link' => $this->t('Content'), + 'access_view' => $this->t('Access view'), + 'access_edit' => $this->t('Access edit'), + 'access_delete' => $this->t('Access delete'), + ], + ]; + + // TODO: Add pagination and limit amount of records. + // Get all records from 'nodeaccess' table. + $records = $this->database->select('nodeaccess', 'n') + ->fields('n') + ->execute() + ->fetchAll(); + + $rows = []; + foreach ($records as $record) { + $url = Url::fromRoute('entity.node.grants', ['node' => $record->nid]); + $entity = $node_storage->load($record->nid); + $link = Link::fromTextAndUrl($entity->label(), $url); + + $has_access = NULL; + if ($record->realm === 'nodeaccess_rid') { + $has_access = $role_alias[array_search($record->gid, $role_map)]['alias']; + } + elseif ($record->realm === 'nodeaccess_uid') { + $user = $user_storage->load($record->gid); + if (!empty($user)) { + $has_access = $user->getDisplayName(); + } + } + + $access_true = $this->t('Yes'); + $access_false = $this->t('No'); + $rows[] = [ + 'has_access' => $has_access, + 'access_type' => $record->realm === 'nodeaccess_rid' + ? $this->t('Role') + : $this->t('User'), + 'link' => $link, + 'access_view' => empty($record->grant_view) ? $access_false : $access_true, + 'access_edit' => empty($record->grant_update) ? $access_false : $access_true, + 'access_delete' => empty($record->grant_delete) ? $access_false : $access_true, + ]; + } + + // Sort table by access_type to display Role accesses at the top. + usort($rows, function($a, $b) { + $diff = strcmp($a['access_type'], $b['access_type']); + if ($diff) return $diff; + return strcmp($a['has_access'], $b['has_access']); + }); + + $build['table']['#rows'] = $rows; + + return $build; + } + +} Index: nodeaccess.permissions.yml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/nodeaccess.permissions.yml b/nodeaccess.permissions.yml --- a/nodeaccess.permissions.yml (revision 0cdd08d487f4de02dde802eb181ce2e5ac2d44b1) +++ b/nodeaccess.permissions.yml (date 1705499596763) @@ -4,7 +4,7 @@ restrict access: true grant node permissions: title: Grant all node permissions - description: Acces the Grants tab of all nodes + description: Access the Grants tab of all nodes restrict access: false permission_callbacks: - Drupal\nodeaccess\NodeGrantPermissions::permissions Index: nodeaccess.routing.yml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/nodeaccess.routing.yml b/nodeaccess.routing.yml --- a/nodeaccess.routing.yml (revision 0cdd08d487f4de02dde802eb181ce2e5ac2d44b1) +++ b/nodeaccess.routing.yml (date 1705499632686) @@ -17,3 +17,10 @@ parameters: node: type: entity:node +nodeaccess.overview: + path: '/admin/nodeaccess/overview' + defaults: + _controller: '\Drupal\nodeaccess\OverviewPageController:view' + _title: 'Overview all granted permissions' + requirements: + _permission: 'access overview nodeaccess' Index: nodeaccess.links.menu.yml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/nodeaccess.links.menu.yml b/nodeaccess.links.menu.yml --- a/nodeaccess.links.menu.yml (revision 0cdd08d487f4de02dde802eb181ce2e5ac2d44b1) +++ b/nodeaccess.links.menu.yml (date 1705498785433) @@ -3,3 +3,8 @@ description: 'Configure user role access to content by node type, and allow granting per-node access to roles and users.' parent: user.admin_index route_name: nodeaccess.administration +nodeaccess.overview: + title: 'Nodeaccess overview' + description: 'Displays all nodeaccess records.' + parent: user.admin_index + route_name: nodeaccess.overview