Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'github/8.x-1.x' into do-not-load-role-o…
Browse files Browse the repository at this point in the history
…bjects
  • Loading branch information
pfrenssen committed Aug 8, 2019
2 parents b9dc9f7 + 862f7d9 commit 7bee878
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

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).
13 changes: 13 additions & 0 deletions og.install
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,16 @@ 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);
$manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition('uuid', 'og_membership'));
}
18 changes: 18 additions & 0 deletions phpcs-ruleset.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@
<!-- Deprecation versions are allowed to include beta versions. -->
<exclude name="Drupal.Semantics.FunctionTriggerError.TriggerErrorVersion" />
</rule>
<rule ref="./vendor/drupal/coder/coder_sniffer/DrupalPractice">
<!-- https://github.com/Gizra/og/issues/549 -->
<exclude name="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable" />
<!-- https://github.com/Gizra/og/issues/545 -->
<exclude name="DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable" />
<!-- https://github.com/Gizra/og/issues/548 -->
<exclude name="DrupalPractice.Commenting.ExpectedException.TagFound" />
<!-- https://github.com/Gizra/og/issues/550 -->
<exclude name="DrupalPractice.Constants.GlobalDefine.GlobalConstant" />
<!-- https://github.com/Gizra/og/issues/544 -->
<exclude name="DrupalPractice.InfoFiles.NamespacedDependency.NonNamespaced" />
<!-- https://github.com/Gizra/og/issues/546 -->
<exclude name="DrupalPractice.Objects.GlobalClass.GlobalClass" />
<!-- https://github.com/Gizra/og/issues/547 -->
<exclude name="DrupalPractice.Objects.GlobalDrupal.GlobalDrupal" />
<!-- https://github.com/Gizra/og/issues/543 -->
<exclude name="DrupalPractice.Objects.GlobalFunction.GlobalFunction" />
</rule>
</ruleset>
1 change: 1 addition & 0 deletions src/Entity/OgMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* fieldable = TRUE,
* bundle_entity_type = "og_membership_type",
* entity_keys = {
* "uuid" = "uuid",
* "id" = "id",
* "bundle" = "type",
* },
Expand Down
13 changes: 3 additions & 10 deletions src/EventSubscriber/OgEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]),
Expand Down
35 changes: 35 additions & 0 deletions tests/src/Kernel/Entity/OgMembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,41 @@ 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);
$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.');
}

/**
* Tests that the membership can return if it belongs to the group owner.
*
Expand Down
3 changes: 1 addition & 2 deletions tests/src/Kernel/PermissionEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 7bee878

Please sign in to comment.