--- revisit_permissions-2708809-52.patch 2018-04-13 14:28:01.000000000 +0300 +++ revisit_permissions-2708809-56.patch 2020-04-07 11:54:28.000000000 +0300 @@ -12,12 +12,12 @@ type: none options: { } diff --git a/contact_storage.install b/contact_storage.install -index 0973584..f024c5c 100644 +index 688db13..ce09983 100644 --- a/contact_storage.install +++ b/contact_storage.install -@@ -121,3 +121,21 @@ function contact_storage_update_8200() { - function contact_storage_update_8201() { - \Drupal::service('module_installer')->install(['options']); +@@ -138,3 +138,22 @@ function contact_storage_update_8202() { + \Drupal::entityDefinitionUpdateManager()->updateEntityType($entity_type); + } } + +/** @@ -28,38 +28,37 @@ + * have access to administer contact forms will be able to view contact + * messages. + */ -+function contact_storage_update_8202() { ++function contact_storage_update_8203() { + // Change the view permission to the new view contact messages permission if + // it hasn't been customised by the site builder to something else. + $config = \Drupal::configFactory()->getEditable('views.view.contact_messages'); -+ if ($config->get('display.default.display_options.access.options.perm') == 'administer contact messages') { ++ ++ if ($config->get('display.default.display_options.access.options.perm') == 'administer contact forms') { + $config->set('display.default.display_options.access.options.perm', 'view contact messages'); + $config->save(TRUE); + } +} diff --git a/contact_storage.module b/contact_storage.module -index ace7d07..9427871 100644 +index 4e8ea06..f455b82 100644 --- a/contact_storage.module +++ b/contact_storage.module -@@ -17,6 +17,8 @@ use Drupal\Core\Language\LanguageInterface; - use Drupal\contact\Entity\ContactForm; +@@ -18,6 +18,8 @@ use Drupal\contact\Entity\ContactForm; use Drupal\Core\Routing\RouteMatchInterface; + use Drupal\Core\Url; use Drupal\views\Views; +use Drupal\Core\Access\AccessResult; +use Drupal\Core\Session\AccountInterface; /** * Implements hook_help(). -@@ -509,3 +511,20 @@ function contact_storage_contact_form_delete(EntityInterface $entity) { - // Delete all aliases with this contact form as a source. +@@ -513,6 +515,22 @@ function contact_storage_contact_form_delete(EntityInterface $entity) { \Drupal::service('path.alias_storage')->delete(['source' => '/' . $entity->toUrl('canonical')->getInternalPath()]); } -+ + +/** + * Implements hook_entity_access(). + */ +function contact_storage_entity_access(EntityInterface $entity, $operation, AccountInterface $account) { -+ + // Check access to the contact message entity. + $available_operations = ['view', 'delete', 'update']; + if ($entity->getEntityTypeId() === 'contact_message' && in_array($operation, $available_operations)) { @@ -71,9 +70,13 @@ + // No opinion. + return AccessResult::neutral(); +} ++ + /** + * Implements hook_action_info_alter(). + */ diff --git a/contact_storage.permissions.yml b/contact_storage.permissions.yml new file mode 100644 -index 0000000..630e703 +index 0000000..43d39b2 --- /dev/null +++ b/contact_storage.permissions.yml @@ -0,0 +1,9 @@ @@ -86,18 +89,15 @@ +delete contact messages: + title: 'Delete contact messages' + description: 'Allow the user to delete contact messages' +\ No newline at end of file diff --git a/contact_storage.post_update.php b/contact_storage.post_update.php -new file mode 100644 -index 0000000..009200f ---- /dev/null +index dacb7a8..244918c 100644 +--- a/contact_storage.post_update.php +++ b/contact_storage.post_update.php -@@ -0,0 +1,40 @@ -+save(); + } + } + +/** + * Post update to split permissions from administer all to view edit delete. @@ -133,18 +133,31 @@ + } +} diff --git a/contact_storage.routing.yml b/contact_storage.routing.yml -index dca717f..9a2671e 100644 +index 05a905e..d04b2b5 100644 --- a/contact_storage.routing.yml +++ b/contact_storage.routing.yml -@@ -27,4 +27,4 @@ entity.contact.multiple_delete_confirm: - defaults: - _form: '\Drupal\contact_storage\Form\DeleteMultiple' +@@ -28,4 +28,4 @@ entity.contact.multiple_delete_confirm: + _form: 'Drupal\Core\Entity\Form\DeleteMultipleForm' + entity_type_id: 'contact_message' requirements: - _permission: 'administer contact forms' + _permission: 'delete contact messages' +diff --git a/src/ContactRouteProvider.php b/src/ContactRouteProvider.php +index a759cf9..4dbc9c1 100644 +--- a/src/ContactRouteProvider.php ++++ b/src/ContactRouteProvider.php +@@ -24,7 +24,7 @@ class ContactRouteProvider extends DefaultHtmlRouteProvider { + '_title' => 'Contact messages', + ]) + ->addRequirements([ +- '_permission' => 'administer contact forms', ++ '_permission' => 'view contact messages', + ]); + $route_collection->add('entity.' . $entity_type->id() . '.collection', $route); + } diff --git a/tests/src/Functional/ContactStorageAccessTest.php b/tests/src/Functional/ContactStorageAccessTest.php new file mode 100644 -index 0000000..a3d58ff +index 0000000..bde450f --- /dev/null +++ b/tests/src/Functional/ContactStorageAccessTest.php @@ -0,0 +1,200 @@ @@ -153,7 +166,7 @@ +namespace Drupal\Tests\contact_storage\Functional; + +use Drupal\Core\Test\AssertMailTrait; -+use Drupal\field_ui\Tests\FieldUiTestTrait; ++use Drupal\Tests\field_ui\Traits\FieldUiTestTrait; + +/** + * Tests storing contact messages and viewing them through UI. @@ -306,11 +319,10 @@ + ])); + + // Make sure no messages are available. -+ $this->assertText('There is no Contact message yet.'); -+ ++ $this->assertText('There are no contact messages yet.'); + } + -+ /** ++ /** + * Tests that the view and edit user can both view and edit. + */ + public function testContactStorageViewAndEditAccess() { @@ -344,12 +356,13 @@ + 'subject[0][value]' => 'Test_edited_subject', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); -+ $this->assertText('Test_edited_subject', 'The subject was updated successfully.'); ++ $this->clickLink(t('Edit')); ++ $this->assertText('Edit Test_edited_subject'); + } + +} diff --git a/tests/src/Functional/ContactStorageTest.php b/tests/src/Functional/ContactStorageTest.php -index 9a5ffda..fe8928c 100644 +index d1f904e..6eda93f 100644 --- a/tests/src/Functional/ContactStorageTest.php +++ b/tests/src/Functional/ContactStorageTest.php @@ -44,6 +44,9 @@ class ContactStorageTest extends ContactStorageTestBase {