Unverified Commit 09d8cb80 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3418353 by codebymikey, acbramley, quadrexdev, smustgrave, catch,...

Issue #3418353 by codebymikey, acbramley, quadrexdev, smustgrave, catch, ressa, benjifisher, berdir: Add new permission for rebuild permissions form
parent 5edaa75e
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@ revert all revisions:
delete all revisions:
  title: 'Delete all revisions'
  description: 'To delete a revision, you also need permission to delete the content item.'
rebuild node access permissions:
  title: 'Rebuild content access permissions'
  description: 'Trigger a content access permission rebuild. This can be a potentially long and disruptive process.'
  restrict access: true

permission_callbacks:
  - \Drupal\node\NodePermissions::nodeTypePermissions
+14 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\node\NodeTypeInterface;
use Drupal\user\RoleInterface;

/**
 * Implements hook_removed_post_updates().
@@ -45,3 +46,16 @@ function node_post_update_create_promote_base_field_overrides(&$sandbox = []): v
      return $changed;
    });
}

/**
 * Grants a new permission for rebuilding node access permissions.
 */
function node_post_update_add_rebuild_permission_to_roles(?array &$sandbox = NULL): void {
  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'user_role', function (RoleInterface $role): bool {
    if ($role->isAdmin() || !$role->hasPermission('administer nodes')) {
      return FALSE;
    }
    $role->grantPermission('rebuild node access permissions');
    return TRUE;
  });
}
+1 −1
Original line number Diff line number Diff line
@@ -163,4 +163,4 @@ node.configure_rebuild_confirm:
  defaults:
    _form: '\Drupal\node\Form\RebuildPermissionsForm'
  requirements:
    _permission: 'administer nodes'
    _permission: 'rebuild node access permissions'
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ public function help($route_name, RouteMatchInterface $route_match): ?string {
    // Remind site administrators about the {node_access} table being flagged
    // for rebuild. We don't need to issue the message on the confirm form, or
    // while the rebuild is being processed.
    if ($route_name != 'node.configure_rebuild_confirm' && $route_name != 'system.batch_page.html' && $route_name != 'help.page.node' && $route_name != 'help.main' && \Drupal::currentUser()->hasPermission('administer nodes') && node_access_needs_rebuild()) {
    if ($route_name != 'node.configure_rebuild_confirm' && $route_name != 'system.batch_page.html' && $route_name != 'help.page.node' && $route_name != 'help.main' && \Drupal::currentUser()->hasPermission('rebuild node access permissions') && node_access_needs_rebuild()) {
      if ($route_name == 'system.status') {
        $message = $this->t('The content access permissions need to be rebuilt.');
      }
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ protected function setUp(): void {
      'administer site configuration',
      'access administration pages',
      'access site reports',
      'administer nodes',
      'rebuild node access permissions',
    ]);
    $this->drupalLogin($this->adminUser);

Loading