Skip to content
Snippets Groups Projects
Verified Commit f4ae13d0 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3445215 by narendraR, borisson_, mtift, mikelutz, smustgrave, Wim...

Issue #3445215 by narendraR, borisson_, mtift, mikelutz, smustgrave, Wim Leers, alexpott: Add validation constraints to user.role.*
parent b2109b4e
No related branches found
No related tags found
27 merge requests!12227Issue #3181946 by jonmcl, mglaman,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8736Update the Documention As per the Function uses.,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8513Issue #3453786: DefaultSelection should document why values for target_bundles NULL and [] behave as they do,!8126Added escape fucntionality on admintoolbar close icon,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #214626 canceled
Pipeline: drupal

#214627

    Showing with 34 additions and 23 deletions
    ......@@ -59,16 +59,6 @@ public function testDraggableList(): void {
    $this->drupalGet('admin/people/roles');
    $this->assertSession()->responseContains('<td>' . Html::escape($role_name));
    // Make sure that NULL weights do not break the list builder. Use the
    // configuration API so that the value does not get type-casted according to
    // the configuration schema.
    \Drupal::configFactory()
    ->getEditable('user.role.role_0')
    ->set('weight', NULL)
    ->save(TRUE);
    $this->drupalGet('admin/people/roles');
    $this->assertSession()->statusCodeEquals(200);
    }
    }
    ......@@ -91,7 +91,7 @@ protected function getExpectedDocument() {
    'status' => TRUE,
    'dependencies' => [],
    'label' => 'Llama',
    'is_admin' => NULL,
    'is_admin' => FALSE,
    'permissions' => [],
    'drupal_internal__id' => 'llama',
    ],
    ......
    ......@@ -58,8 +58,7 @@ protected function setUp(): void {
    $this->installSchema('node', 'node_access');
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installConfig('filter');
    $this->installConfig('node');
    $this->installConfig(['filter', 'node', 'user']);
    $this->accessHandler = \Drupal::entityTypeManager()->getAccessControlHandler('node');
    ......
    ......@@ -123,6 +123,8 @@ user.flood:
    user.role.*:
    type: config_entity
    label: 'User role settings'
    constraints:
    FullyValidatable: ~
    mapping:
    id:
    type: machine_name
    ......@@ -143,6 +145,9 @@ user.role.*:
    sequence:
    type: string
    label: 'Permission'
    constraints:
    Callback:
    callback: [\Drupal\user\Entity\Role, getAllValidPermissions]
    action.configuration.user_add_role_action:
    type: mapping
    ......
    ......@@ -88,7 +88,7 @@ class Role extends ConfigEntityBase implements RoleInterface {
    *
    * @var bool
    */
    protected $is_admin;
    protected $is_admin = FALSE;
    /**
    * {@inheritdoc}
    ......@@ -181,12 +181,11 @@ public static function postLoad(EntityStorageInterface $storage, array &$entitie
    public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    if (!isset($this->weight) && ($roles = $storage->loadMultiple())) {
    if (!isset($this->weight)) {
    // Set a role weight to make this new role last.
    $max = array_reduce($roles, function ($max, $role) {
    return $max > $role->weight ? $max : $role->weight;
    });
    $this->weight = $max + 1;
    $this->weight = array_reduce($storage->loadMultiple(), function ($max, $role) {
    return $max > $role->weight ? $max : $role->weight + 1;
    }, 0);
    }
    if (!$this->isSyncing() && $this->hasTrustedData()) {
    ......@@ -265,4 +264,19 @@ public function onDependencyRemoval(array $dependencies) {
    return $changed;
    }
    /**
    * Returns all valid permissions.
    *
    * @return string[]
    * All possible valid permissions.
    *
    * @see \Drupal\user\PermissionHandler::getPermissions()
    *
    * @internal
    * @todo Revisit in https://www.drupal.org/node/3446364
    */
    public static function getAllValidPermissions(): array {
    return array_keys(\Drupal::service('user.permissions')->getPermissions());
    }
    }
    ......@@ -2,6 +2,7 @@
    namespace Drupal\user;
    use Drupal\Core\Config\Entity\ConfigEntityStorage;
    use Drupal\Core\Entity\EntityForm;
    use Drupal\Core\Form\FormStateInterface;
    ......@@ -32,7 +33,7 @@ public function form(array $form, FormStateInterface $form_state) {
    '#required' => TRUE,
    '#disabled' => !$entity->isNew(),
    '#size' => 30,
    '#maxlength' => 64,
    '#maxlength' => ConfigEntityStorage::MAX_ID_LENGTH,
    '#machine_name' => [
    'exists' => ['\Drupal\user\Entity\Role', 'load'],
    ],
    ......
    ......@@ -56,7 +56,7 @@ protected function getExpectedNormalizedEntity() {
    'dependencies' => [],
    'id' => 'llama',
    'label' => 'Llama',
    'is_admin' => NULL,
    'is_admin' => FALSE,
    'permissions' => [],
    ];
    }
    ......
    ......@@ -25,6 +25,8 @@ class RoleValidationTest extends ConfigEntityValidationTestBase {
    protected function setUp(): void {
    parent::setUp();
    $this->installConfig('user');
    $this->entity = Role::create([
    'id' => 'test',
    'label' => 'Test',
    ......
    ......@@ -24,7 +24,7 @@ dependencies:
    id: author
    label: Author
    weight: 3
    is_admin: null
    is_admin: false
    permissions:
    - 'access content overview'
    - 'access contextual links'
    ......
    ......@@ -26,7 +26,7 @@ dependencies:
    id: editor
    label: Editor
    weight: 4
    is_admin: null
    is_admin: false
    permissions:
    - 'access administration pages'
    - 'access content overview'
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment