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

Commit

Permalink
Merge pull request #322 from willzyx-dev/7.x-2.x
Browse files Browse the repository at this point in the history
Group owner membership is activated on every group save
  • Loading branch information
alesrebec authored Jun 20, 2018
2 parents 983ce45 + eb6ca6a commit 731d5b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion og.module
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ function og_entity_update($entity, $entity_type) {
}

list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
if (!empty($entity->uid) && !og_is_member($entity_type, $id, 'user', $entity->uid)) {
if (!empty($entity->uid) && !og_is_member($entity_type, $id, 'user', $entity->uid, array())) {
// Subscribe the group manager, in case the owner changed.
og_group($entity_type, $id, array('entity' => $entity->uid));
// Assign roles to group manager.
Expand Down
35 changes: 35 additions & 0 deletions og.test
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,41 @@ class OgGroupAndUngroup extends DrupalWebTestCase {
$user_roles = og_get_user_roles('entity_test', $entity1->pid, $user1->uid, FALSE);
$this->assertEqual($og_roles, $user_roles, t('Group manager was granted default role.'));
}

/**
* Test group behaviour when the group owner is not active.
*/
public function testGroupManagerNotActive() {
// Create the user.
$user1 = $this->drupalCreateUser();

// Create the group; the group owner is the previously created user.
$entity1 = entity_create('entity_test', array('name' => 'main', 'uid' => $user1->uid));
$wrapper = entity_metadata_wrapper('entity_test', $entity1);
$wrapper->{OG_GROUP_FIELD}->set(1);
$wrapper->save();

// Ensure that the user owner membership for the group has active status.
$og_membership = og_get_membership('entity_test', $entity1->pid, 'user', $user1->uid);
$this->assertEqual($og_membership->state, OG_STATE_ACTIVE, 'Owner Membership status is Active');

// Move the user owner membership to blocked.
$og_membership->state = OG_STATE_BLOCKED;
$og_membership->save();

$og_membership = og_membership_load($og_membership->identifier());
$this->assertEqual($og_membership->state, OG_STATE_BLOCKED, 'Owner Membership status is Blocked');

// Save the group entity.
$wrapper = entity_metadata_wrapper('entity_test', $entity1);
$wrapper->save();

// Ensure that the user owner membership for the group still has blocked
// status.
$og_membership = og_membership_load($og_membership->identifier());
$this->assertEqual($og_membership->state, OG_STATE_BLOCKED, 'Owner Membership status is Blocked');
}

}

class OgPermissionsTestCase extends DrupalWebTestCase {
Expand Down

0 comments on commit 731d5b8

Please sign in to comment.