Commit 0d41fff9 authored by mxh's avatar mxh
Browse files

Issue #3255595 by nanak, mxh: "%type_id delete any entities" permission was not properly converted

parent a596a88d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ class StoragePermissions {
      "delete own $type_id storage entities" => [
        'title' => $this->t('Delete own %type_name Storage entities', $type_params),
      ],
      "delete any $type_id entities" => [
      "delete any $type_id storage entities" => [
        'title' => $this->t('Delete any %type_name Storage entities', $type_params),
        'restrict access' => TRUE,
      ],
+30 −0
Original line number Diff line number Diff line
@@ -51,3 +51,33 @@ function storage_update_8101(&$sandbox) {
  }
  return t('Update completed, no changes were made.');
}

/**
 * Convert "Delete any %type entities" to "Delete any %type storage entities".
 *
 * The previous update did not convert this permission to the new format.
 * Export your configuration after performing this update.
 */
function storage_update_8102() {
  $config_changed = FALSE;
  /** @var \Drupal\user\RoleInterface $role */
  foreach (\Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple() as $role) {
    $permissions_changed = FALSE;
    foreach (\Drupal::entityTypeManager()->getStorage('storage_type')->loadMultiple() as $storage_type) {
      $type_id = $storage_type->id();
      if (!$role->isAdmin() && $role->hasPermission("delete any $type_id entities")) {
        $role->revokePermission("delete any $type_id entities");
        $role->grantPermission("delete any $type_id storage entities");
        $permissions_changed = TRUE;
        $config_changed = TRUE;
      }
    }
    if ($permissions_changed) {
      $role->trustData()->save();
    }
  }
  if ($config_changed) {
    return t('Permission conversion completed. Export your configuration to synchronize the applied changes.');
  }
  return t('Update completed, no changes were made.');
}