From 61ffd0d9980180be3a9c2ad113aee05a8353fb0d Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 13 Jun 2019 13:48:27 +0300 Subject: [PATCH 01/11] Consolidate the permissions regarding roles and permissions. We were using two separate permissions to handle these closely related subjects. We are going to follow the approach of Drupal core and use a single 'administer permissions' permission for both. --- src/EventSubscriber/OgEventSubscriber.php | 13 +++---------- tests/src/Kernel/PermissionEventTest.php | 3 +-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/EventSubscriber/OgEventSubscriber.php b/src/EventSubscriber/OgEventSubscriber.php index 3463cd3f2..e5b3cefe4 100644 --- a/src/EventSubscriber/OgEventSubscriber.php +++ b/src/EventSubscriber/OgEventSubscriber.php @@ -132,16 +132,9 @@ public function provideDefaultOgPermissions(PermissionEventInterface $event) { 'restrict access' => TRUE, ]), new GroupPermission([ - 'name' => 'manage roles', - 'title' => t('Add roles'), - 'description' => t('Users may view group roles and add new roles if group default roles are overridden.'), - 'default roles' => [OgRoleInterface::ADMINISTRATOR], - 'restrict access' => TRUE, - ]), - new GroupPermission([ - 'name' => 'manage permissions', - 'title' => t('Manage permissions'), - 'description' => t('Users may view the group permissions page and change permissions if group default roles are overridden.'), + 'name' => 'administer permissions', + 'title' => t('Administer permissions'), + 'description' => t('Users may view, create, edit and delete permissions and roles within the group.'), 'default roles' => [OgRoleInterface::ADMINISTRATOR], 'restrict access' => TRUE, ]), diff --git a/tests/src/Kernel/PermissionEventTest.php b/tests/src/Kernel/PermissionEventTest.php index 59ecefacf..fa7a73bf4 100644 --- a/tests/src/Kernel/PermissionEventTest.php +++ b/tests/src/Kernel/PermissionEventTest.php @@ -131,8 +131,7 @@ public function permissionEventDataProvider() { 'administer group', 'approve and deny subscription', 'manage members', - 'manage permissions', - 'manage roles', + 'administer permissions', 'subscribe without approval', 'subscribe', 'update group', From 7247ccf6e13ac2cd00de2e347d7fb93b5a581e33 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Thu, 13 Jun 2019 15:28:11 +0200 Subject: [PATCH 02/11] Create CHANGELOG.md --- CHANGELOG.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..6366dc90a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,74 @@ +# Changelog + +All notable changes to the Organic Groups project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0-alpha3] + +Third alpha release for Organic Groups. This release brings many small improvements and adds support for Drupal 8.7. + +Starting with this release PHP 7.1 or higher is required, + +## Improvements + +* #311 Throw an exception when calling MembershipManager::getGroupIds() with an entity which is not group content. +* #433 Remove obsolete "Use queue" setting. +* #450 Use Cache API to store the group relation map. +* #455 Early exit if there are no memberships to process. +* #458 Show UID in LogicException for existing membership. +* #462 Add default access check. +* #467 Use full pager on member overview. +* #468 Small optimization for adding/removing roles to/from memberships. +* #472 Provide a list cache tag for group memberships. +* #473 Add support for Drupal 8.7. +* #475 Provide a method to retrieve the membership IDs of a given group. +* #482 Allow to retrieve groups and roles by permissions. +* #483 Provide a list cache tag for group content. +* #489 Declare PHP 7.1 as the minimum supported version. +* #491 Update URL of repository now that Drupal has moved to Gitlab. +* #492 Add Slack to support channels. +* #493 Introduce strict typing in the OgMembership entity. +* #495 Use better way to check if an entity represents a user. +* #496 Adopt new module dependency format. +* #498 Improve documentation. +* #514 Fix coding standards violations. +* #516 Do not require to pass full OgRole objects when we only need the ID. + +## Bug fixes + +* #443 OgRole actions config throws error on import. +* #461 Fix minor typo in subscribe form. +* #465 Fix broken/missing handler for roles in OG membership view. +* #471 Fix unnecessarily gendered language in comments. +* #476 Only allow users with "access user profiles" permission to access the members overview. +* #479 MembershipManager returns memberships of the wrong group. +* #480 MembershipManager still returns memberships after a user is deleted. +* #503 Fix random failure when time service is instantiated one second too late +* #509 Do not invalidate group content list cache tags when the group itself changes. +## [1.0-alpha2] + +Second alpha release of the Drupal 8 port of Organic Groups. This release adds support for Drupal 8.6 and PHP 7.3. + +### New features + +* #451 Provide a method on the `MembershipManager` to retrieve all group memberships filtered by role. + +### Improvements + +* #447 Add support for Drupal 8.6 and PHP 7.3. Start preliminary testing on Drupal 8.7. +* #446 Avoid double caching of `OgMembership` entities. This reduces memory consumption. +* #449 Clarify how to work with membership states by providing a new constant and improving documentation. +* #437 Streamline the Travis CI installation procedure. + + +## [1.0-alpha1] + +Initial alpha release of the Drupal 8 port of Organic Groups. + + +[Unreleased]: https://github.com/Gizra/og/compare/8.x-1.0-alpha1...8.x-1.x +[1.0-alpha3]: https://github.com/Gizra/og/compare/8.x-1.0-alpha2...8.x-1.0-alpha3 +[1.0-alpha2]: https://github.com/Gizra/og/compare/8.x-1.0-alpha1...8.x-1.0-alpha2 +[1.0-alpha1]: https://github.com/Gizra/og/releases/tag/8.x-1.0-alpha1 From 2ea92c827779420069857606e959d9cd68189cec Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 24 Jun 2019 13:19:47 +0200 Subject: [PATCH 03/11] Added uuid field to OgMembership --- src/Entity/OgMembership.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Entity/OgMembership.php b/src/Entity/OgMembership.php index 0894ea62a..d48e7e17b 100644 --- a/src/Entity/OgMembership.php +++ b/src/Entity/OgMembership.php @@ -62,6 +62,7 @@ * fieldable = TRUE, * bundle_entity_type = "og_membership_type", * entity_keys = { + * "uuid" = "uuid", * "id" = "id", * "bundle" = "type", * }, From 74874b35ceddd51be7ca472621f7f22abbe8286c Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 24 Jun 2019 13:21:27 +0200 Subject: [PATCH 04/11] Add uuid field to OgMembership in hook_update. --- og.install | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/og.install b/og.install index 80ad218cf..d466cde17 100644 --- a/og.install +++ b/og.install @@ -77,3 +77,19 @@ function og_update_8001(&$sandbox) { return $message; } + +/** + * Add uuid field to OgMembership. + */ +function og_update_8002() { + $manager = \Drupal::entityDefinitionUpdateManager(); + $entity_type = $manager->getEntityType('og_membership'); + $entity_keys = $entity_type->getKeys(); + $entity_keys['uuid'] = 'uuid'; + $entity_type->set('entity_keys', $entity_keys); + $manager->updateEntityType($entity_type); + + foreach (['uuid'] as $field_name) { + $manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition($field_name, 'og_membership')); + } +} From 54f4deb15357f5889b748dde417f5d94ff675833 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 24 Jun 2019 13:29:06 +0200 Subject: [PATCH 05/11] Update og.install --- og.install | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/og.install b/og.install index d466cde17..f2808a694 100644 --- a/og.install +++ b/og.install @@ -89,7 +89,5 @@ function og_update_8002() { $entity_type->set('entity_keys', $entity_keys); $manager->updateEntityType($entity_type); - foreach (['uuid'] as $field_name) { - $manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition($field_name, 'og_membership')); - } + $manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition('uuid', 'og_membership')); } From e7b70bd7a7e3abafdf5739119a8d21eb27f0b9c3 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 24 Jun 2019 13:29:20 +0200 Subject: [PATCH 06/11] Update og.install --- og.install | 1 - 1 file changed, 1 deletion(-) diff --git a/og.install b/og.install index f2808a694..4fc373b6a 100644 --- a/og.install +++ b/og.install @@ -88,6 +88,5 @@ function og_update_8002() { $entity_keys['uuid'] = 'uuid'; $entity_type->set('entity_keys', $entity_keys); $manager->updateEntityType($entity_type); - $manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition('uuid', 'og_membership')); } From b163e79d98720c62ad81c3db2a76bcf668905578 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 8 Jul 2019 13:05:11 +0200 Subject: [PATCH 07/11] Update CHANGELOG.md --- CHANGELOG.md | 73 +--------------------------------------------------- 1 file changed, 1 insertion(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6366dc90a..df4658d6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,74 +1,3 @@ # Changelog -All notable changes to the Organic Groups project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [1.0-alpha3] - -Third alpha release for Organic Groups. This release brings many small improvements and adds support for Drupal 8.7. - -Starting with this release PHP 7.1 or higher is required, - -## Improvements - -* #311 Throw an exception when calling MembershipManager::getGroupIds() with an entity which is not group content. -* #433 Remove obsolete "Use queue" setting. -* #450 Use Cache API to store the group relation map. -* #455 Early exit if there are no memberships to process. -* #458 Show UID in LogicException for existing membership. -* #462 Add default access check. -* #467 Use full pager on member overview. -* #468 Small optimization for adding/removing roles to/from memberships. -* #472 Provide a list cache tag for group memberships. -* #473 Add support for Drupal 8.7. -* #475 Provide a method to retrieve the membership IDs of a given group. -* #482 Allow to retrieve groups and roles by permissions. -* #483 Provide a list cache tag for group content. -* #489 Declare PHP 7.1 as the minimum supported version. -* #491 Update URL of repository now that Drupal has moved to Gitlab. -* #492 Add Slack to support channels. -* #493 Introduce strict typing in the OgMembership entity. -* #495 Use better way to check if an entity represents a user. -* #496 Adopt new module dependency format. -* #498 Improve documentation. -* #514 Fix coding standards violations. -* #516 Do not require to pass full OgRole objects when we only need the ID. - -## Bug fixes - -* #443 OgRole actions config throws error on import. -* #461 Fix minor typo in subscribe form. -* #465 Fix broken/missing handler for roles in OG membership view. -* #471 Fix unnecessarily gendered language in comments. -* #476 Only allow users with "access user profiles" permission to access the members overview. -* #479 MembershipManager returns memberships of the wrong group. -* #480 MembershipManager still returns memberships after a user is deleted. -* #503 Fix random failure when time service is instantiated one second too late -* #509 Do not invalidate group content list cache tags when the group itself changes. -## [1.0-alpha2] - -Second alpha release of the Drupal 8 port of Organic Groups. This release adds support for Drupal 8.6 and PHP 7.3. - -### New features - -* #451 Provide a method on the `MembershipManager` to retrieve all group memberships filtered by role. - -### Improvements - -* #447 Add support for Drupal 8.6 and PHP 7.3. Start preliminary testing on Drupal 8.7. -* #446 Avoid double caching of `OgMembership` entities. This reduces memory consumption. -* #449 Clarify how to work with membership states by providing a new constant and improving documentation. -* #437 Streamline the Travis CI installation procedure. - - -## [1.0-alpha1] - -Initial alpha release of the Drupal 8 port of Organic Groups. - - -[Unreleased]: https://github.com/Gizra/og/compare/8.x-1.0-alpha1...8.x-1.x -[1.0-alpha3]: https://github.com/Gizra/og/compare/8.x-1.0-alpha2...8.x-1.0-alpha3 -[1.0-alpha2]: https://github.com/Gizra/og/compare/8.x-1.0-alpha1...8.x-1.0-alpha2 -[1.0-alpha1]: https://github.com/Gizra/og/releases/tag/8.x-1.0-alpha1 +All notable changes to the Organic Groups project are documented on [drupal.org](https://www.drupal.org/project/og/releases) and on [github](https://www.drupal.org/project/og/releases). From aa9d5cc427a64daa6a80e788aa66c815b494491a Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Tue, 23 Jul 2019 08:43:09 +0300 Subject: [PATCH 08/11] Start doing static analysis to detect if best practices have been used. --- phpcs-ruleset.xml.dist | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/phpcs-ruleset.xml.dist b/phpcs-ruleset.xml.dist index 6141b6305..86df7e2dd 100644 --- a/phpcs-ruleset.xml.dist +++ b/phpcs-ruleset.xml.dist @@ -14,4 +14,22 @@ *.min.js + + + + + + + + + + + + + + + + + + From 487102c423dc9fd75a1dbbcc5a86f3f161271531 Mon Sep 17 00:00:00 2001 From: Ilias Dimopoulos Date: Thu, 1 Aug 2019 14:06:15 +0300 Subject: [PATCH 09/11] Create a test for the ::getRolesIds(). --- tests/src/Kernel/Entity/OgMembershipTest.php | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/src/Kernel/Entity/OgMembershipTest.php b/tests/src/Kernel/Entity/OgMembershipTest.php index 2aa9ca6e5..6f5433fcb 100644 --- a/tests/src/Kernel/Entity/OgMembershipTest.php +++ b/tests/src/Kernel/Entity/OgMembershipTest.php @@ -777,6 +777,34 @@ public function testGetRolesFromMembershipWithoutGroup() { $this->assertEquals([], $roles); } + /** + * Tests that the role ids are being built properly by the membership. + * + * @covers ::getRolesIds + */ + public function testGetRolesIdsFromMembership() { + $entity_type_id = $this->group->getEntityTypeId(); + $bundle = $this->group->bundle(); + + $og_extra_role = OgRole::create() + ->setGroupType($entity_type_id) + ->setGroupBundle($bundle) + ->setName(mb_strtolower($this->randomMachineName())); + $og_extra_role->save(); + + $membership = OgMembership::create() + ->setGroup($this->group) + ->setOwner($this->user) + ->addRole($og_extra_role); + $membership->save(); + + $role_names = ['member', $og_extra_role->getName()]; + $expected_ids = array_map(function ($role_name) use ($entity_type_id, $bundle) { + return "{$entity_type_id}-{$bundle}-" . $role_name; + }, $role_names); + $this->assertEquals($expected_ids, $membership->getRolesIds(), 'Role ids are built properly.'); + } + /** * Tests that the membership can return if it belongs to the group owner. * From 0b54d7c01a3190e1bc68ab899ec27695315eabfa Mon Sep 17 00:00:00 2001 From: Ilias Dimopoulos Date: Thu, 1 Aug 2019 14:11:40 +0300 Subject: [PATCH 10/11] Make the generation of names a bit more compact. --- tests/src/Kernel/Entity/OgMembershipTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/Entity/OgMembershipTest.php b/tests/src/Kernel/Entity/OgMembershipTest.php index 6f5433fcb..2cd6dc9a1 100644 --- a/tests/src/Kernel/Entity/OgMembershipTest.php +++ b/tests/src/Kernel/Entity/OgMembershipTest.php @@ -800,7 +800,7 @@ public function testGetRolesIdsFromMembership() { $role_names = ['member', $og_extra_role->getName()]; $expected_ids = array_map(function ($role_name) use ($entity_type_id, $bundle) { - return "{$entity_type_id}-{$bundle}-" . $role_name; + return "{$entity_type_id}-{$bundle}-{$role_name}"; }, $role_names); $this->assertEquals($expected_ids, $membership->getRolesIds(), 'Role ids are built properly.'); } From 31f7e2e43449e5a9865d6d9649ebc58b5b52aeba Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 7 Aug 2019 19:11:48 +0300 Subject: [PATCH 11/11] Sort the arrays before comparison to avoid random failures related to sorting order. --- tests/src/Kernel/Entity/OgMembershipTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/src/Kernel/Entity/OgMembershipTest.php b/tests/src/Kernel/Entity/OgMembershipTest.php index 2cd6dc9a1..3414285d3 100644 --- a/tests/src/Kernel/Entity/OgMembershipTest.php +++ b/tests/src/Kernel/Entity/OgMembershipTest.php @@ -802,7 +802,14 @@ public function testGetRolesIdsFromMembership() { $expected_ids = array_map(function ($role_name) use ($entity_type_id, $bundle) { return "{$entity_type_id}-{$bundle}-{$role_name}"; }, $role_names); - $this->assertEquals($expected_ids, $membership->getRolesIds(), 'Role ids are built properly.'); + $actual_ids = $membership->getRolesIds(); + + // Sort the two arrays before comparing so we can check the contents + // regardless of their order. + sort($expected_ids); + sort($actual_ids); + + $this->assertEquals($expected_ids, $actual_ids, 'Role ids are built properly.'); } /**