From 7b833f3c6f0daae8df14dd7bc5adcaf0da072978 Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Fri, 13 Oct 2017 10:37:33 +0200 Subject: [PATCH] interdiff --- core/modules/user/src/AccountSettingsForm.php | 44 ---------------------- .../modules/user/src/Tests/UserPermissionsTest.php | 43 --------------------- 2 files changed, 87 deletions(-) diff --git a/core/modules/user/src/AccountSettingsForm.php b/core/modules/user/src/AccountSettingsForm.php index 5c94e9a..b12360b 100644 --- a/core/modules/user/src/AccountSettingsForm.php +++ b/core/modules/user/src/AccountSettingsForm.php @@ -100,34 +100,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#required' => TRUE, ]; - // Administrative role option. - $form['admin_role'] = [ - '#type' => 'details', - '#title' => $this->t('Administrator role'), - '#open' => TRUE, - ]; - // Do not allow users to set the anonymous or authenticated user roles as - // the administrator role. - $roles = user_role_names(TRUE); - unset($roles[RoleInterface::AUTHENTICATED_ID]); - - $admin_roles = $this->roleStorage->getQuery() - ->condition('is_admin', TRUE) - ->execute(); - $default_value = reset($admin_roles); - - $form['admin_role']['user_admin_role'] = [ - '#type' => 'select', - '#title' => $this->t('Administrator role'), - '#empty_value' => '', - '#default_value' => $default_value, - '#options' => $roles, - '#description' => $this->t('This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.'), - // Don't allow to select a single admin role in case multiple roles got - // marked as admin role already. - '#access' => count($admin_roles) <= 1, - ]; - // @todo Remove this check once language settings are generalized. if ($this->moduleHandler->moduleExists('content_translation')) { $form['language'] = [ @@ -460,22 +432,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.site') ->set('mail_notification', $form_state->getValue('mail_notification_address')) ->save(); - - // Change the admin role. - if ($form_state->hasValue('user_admin_role')) { - $admin_roles = $this->roleStorage->getQuery() - ->condition('is_admin', TRUE) - ->execute(); - - foreach ($admin_roles as $rid) { - $this->roleStorage->load($rid)->setIsAdmin(FALSE)->save(); - } - - $new_admin_role = $form_state->getValue('user_admin_role'); - if ($new_admin_role) { - $this->roleStorage->load($new_admin_role)->setIsAdmin(TRUE)->save(); - } - } } } diff --git a/core/modules/user/src/Tests/UserPermissionsTest.php b/core/modules/user/src/Tests/UserPermissionsTest.php index 9ebeff3..2a54432 100644 --- a/core/modules/user/src/Tests/UserPermissionsTest.php +++ b/core/modules/user/src/Tests/UserPermissionsTest.php @@ -86,49 +86,6 @@ public function testUserPermissionChanges() { } /** - * Test assigning of permissions for the administrator role. - */ - public function testAdministratorRole() { - $this->drupalLogin($this->adminUser); - $this->drupalGet('admin/config/people/accounts'); - - // Verify that the administration role is 'administrator' by default. - $this->assertOptionSelected('edit-user-admin-role', RoleInterface::ADMINISTRATOR_ID, 'Administration role defaults to administrator.'); - - $this->assertFalse(Role::load($this->rid)->isAdmin()); - - // Set the user's role to be the administrator role. - $edit = []; - $edit['user_admin_role'] = $this->rid; - $this->drupalPostForm('admin/config/people/accounts', $edit, t('Save configuration')); - - \Drupal::entityManager()->getStorage('user_role')->resetCache(); - $this->assertTrue(Role::load($this->rid)->isAdmin()); - - // Enable aggregator module and ensure the 'administer news feeds' - // permission is assigned by default. - \Drupal::service('module_installer')->install(['aggregator']); - - $this->assertTrue($this->adminUser->hasPermission('administer news feeds'), 'The permission was automatically assigned to the administrator role'); - - // Ensure that selecting '- None -' removes the admin role. - $edit = []; - $edit['user_admin_role'] = ''; - $this->drupalPostForm('admin/config/people/accounts', $edit, t('Save configuration')); - - \Drupal::entityManager()->getStorage('user_role')->resetCache(); - \Drupal::configFactory()->reset(); - $this->assertFalse(Role::load($this->rid)->isAdmin()); - - // Manually create two admin roles, in that case the single select should be - // hidden. - Role::create(['id' => 'admin_role_0', 'is_admin' => TRUE, 'label' => 'Admin role 0'])->save(); - Role::create(['id' => 'admin_role_1', 'is_admin' => TRUE, 'label' => 'Admin role 1'])->save(); - $this->drupalGet('admin/config/people/accounts'); - $this->assertNoFieldByName('user_admin_role'); - } - - /** * Verify proper permission changes by user_role_change_permissions(). */ public function testUserRoleChangePermissions() { -- 2.8.1