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 #390 from Gizra/7.x-2.10-rc1
Browse files Browse the repository at this point in the history
OG 7.x 2.10 release
  • Loading branch information
alesrebec authored Jun 27, 2018
2 parents 81cd92d + 731d5b8 commit faea5e6
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 56 deletions.
23 changes: 22 additions & 1 deletion og.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@
*/

/**
* Add group permissions.
* Define permissions specific to organic groups.
*
* This hook can supply permissions that the module defines, so that they can be
* selected on the group permissions page and used to grant or restrict access
* to actions pertaining to groups.
*
* Permissions are checked using og_user_access().
*
* @return array
* An array whose keys are permission names and whose corresponding values are
* arrays containg the following key-value pairs:
* - title: The human-readable name of the permission, to be shown on group
* permissions pages. This should be wrapped in the t() function so it can
* be translated.
* - description: (optional) A description of what the permission does. This
* should be wrapped in the t() function so it can be translated.
* - roles: (optional) An array of OG roles to which it is possible to assign
* this permission. The default value is an array containg OG_ANONYMOUS_ROLE
* and OG_AUTHENTICATED_ROLE.
* - default role: (optional) An array of OG roles that should be assigned
* this permission by default. If omitted then no role will receive the
* permission by default.
*/
function hook_og_permission() {
return array(
Expand Down
1 change: 0 additions & 1 deletion og.info
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ files[] = includes/views/handlers/og_plugin_argument_validate_group.inc
files[] = includes/views/handlers/og_plugin_argument_default_user_groups.inc

; Views fields
files[] = includes/views/handlers/og_handler_field_group_member_count.inc
files[] = includes/views/handlers/og_handler_field_group_audience_state.inc
files[] = includes/views/handlers/og_handler_field_prerender_list.inc
files[] = includes/views/handlers/og_handler_field_user_roles.inc
Expand Down
49 changes: 29 additions & 20 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function og_help($path, $arg) {
switch ($path) {
case 'admin/help#og':
$path = drupal_get_path('module', 'og');
$output = '<p>' . t("Read the <a href='@url'>README.txt</a> file in the Organic groups module directory.", array('@url' => "/$path/README.txt")) . '</p>';
$output .= '<p>' . t("Information about Organic Groups can also be found on the module's<a href='@og'>documentation page</a>.", array('@og' => 'http://drupal.org/documentation/modules/og')) . '</p>';
$output = '<p>' . t("Read the <a href='@url'>README.md</a> file in the Organic groups module directory.", array('@url' => "/$path/README.md")) . '</p>';
$output .= '<p>' . t("Information about Organic Groups can also be found on the module's <a href='@og'>documentation page</a>.", array('@og' => 'http://drupal.org/documentation/modules/og')) . '</p>';
return $output;
}
}
Expand Down Expand Up @@ -671,7 +671,15 @@ function og_field_create_instance($instance) {

$og_field = og_fields_info(OG_AUDIENCE_FIELD);
$og_field['field']['settings']['target_type'] = $entity_type;
$og_field['instance']['label'] = t('Group membership');
if ($entity_type == 'node') {
$og_field['instance']['label'] = t('Group membership');
}
else {
$entity_info = entity_get_info($entity_type);
$og_field['instance']['label'] = t('@label group membership', array(
'@label' => $entity_info['label'],
));
}

// If the user entity type has multiple bundles, make sure to attach a field
// instance to all of them.
Expand Down Expand Up @@ -786,7 +794,7 @@ function og_form_group_manager_validate($form, &$form_state) {
return;
}
$entity = $form_state[$entity_type];
$langcode = $form_state['values']['language'];
$langcode = isset($form_state['values']['language']) ? $form_state['values']['language'] : LANGUAGE_NONE;

if (!isset($form_state['values']['uid']) || !isset($entity->uid)) {
// There is no user ID property on the entity.
Expand Down Expand Up @@ -874,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 Expand Up @@ -2305,9 +2313,9 @@ function og_user_access_entity($perm, $entity_type, $entity, $account = NULL, $s
* (optional) The field name associated with the group.
*
* @return
* An array with the group's entity type as the key, and array - keyed by
* the OG membership ID and the group ID as the value. If nothing found,
* then an empty array.
* An associative array keyed by the group's entity type. Each value is itself
* an array, where each item has for its key the OG membership ID and for its
* value the group ID.
*/
function og_get_entity_groups($entity_type = 'user', $entity = NULL, $states = array(OG_STATE_ACTIVE), $field_name = NULL) {
$cache = &drupal_static(__FUNCTION__, array());
Expand Down Expand Up @@ -2572,8 +2580,8 @@ function og_get_all_group_content_bundle() {
* @param $entity
* The entity object. If empty the current user will be used.
* @param $states
* (optional) Array with the state to return. If empty groups of all state will
* return.
* (optional) Array with the membership states to check against. If omitted
* then only active (OG_STATE_ACTIVE) memberships will be checked.
*
* @return
* TRUE if the entity (e.g. the user) belongs to a group and is not pending or
Expand Down Expand Up @@ -3553,26 +3561,29 @@ function og_node_create_links($group_type, $gid, $field_name, $destination = NUL
* types will be fetched.
*
* @return
* An array with the group IDs or an empty array.
* If $group_type is provided then an array of group IDs matching the
* specified group type. If $group_type is not provided then an associative
* array is returned containing arrays of group IDs keyed by group type. If
* no results are found an empty array is returned.
*/
function og_get_groups_by_user($account = NULL, $group_type = NULL) {
if (empty($account)) {
global $user;
$account = $user;
}

$gids = array();

if (!og_get_group_audience_fields()) {
// User entity doesn't have group audience fields.
return;
return $gids;
}

$gids = array();

// Get all active OG membership that belong to the user.
$wrapper = entity_metadata_wrapper('user', $account->uid);
$og_memberships = $wrapper->{'og_membership__' . OG_STATE_ACTIVE}->value();
if (!$og_memberships) {
return;
return $gids;
}

foreach ($og_memberships as $og_membership) {
Expand All @@ -3581,12 +3592,10 @@ function og_get_groups_by_user($account = NULL, $group_type = NULL) {
}
}

if (empty($group_type)) {
return $gids;
}
elseif (!empty($gids[$group_type])) {
return $gids[$group_type];
if (isset($group_type)) {
return isset($gids[$group_type]) ? $gids[$group_type] : array();
}
return $gids;
}

/**
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
2 changes: 0 additions & 2 deletions og_access/og_access.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package = "Organic groups"
dependencies[] = og
core = 7.x
version = VERSION
files[] = og_access.module
files[] = og_access.install

; Tests
files[] = og_access.test
2 changes: 0 additions & 2 deletions og_context/og_context.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ description = "Get a group from a viewed page."
package = "Organic groups"
dependencies[] = og
core = 7.x
files[] = og_context.module
files[] = og_context.install

; Views default arguments
files[] = includes/views/handlers/og_context_plugin_argument_default_group_context.inc
Expand Down
1 change: 0 additions & 1 deletion og_field_access/og_field_access.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ description = "Provide field access based on group."
package = "Organic groups"
dependencies[] = og
core = 7.x
files[] = og_field_access.module

; Tests
files[] = og_field_access.test
2 changes: 0 additions & 2 deletions og_register/og_register.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ description = "Allow subscribing to groups during the user registration."
package = "Organic groups"
dependencies[] = og
core = 7.x
files[] = og_register.module
files[] = og_register.install
1 change: 1 addition & 0 deletions og_ui/og_ui.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ function og_ui_edit_membership($form, &$form_state, $group_type, $gid, $og_membe
'#options' => $og_roles,
'#title' => t('Roles'),
'#default_value' => array_keys(og_get_user_roles($group_type, $gid, $account->uid)),
'#disabled' => $og_membership->state != OG_STATE_ACTIVE,
);
}

Expand Down
7 changes: 1 addition & 6 deletions og_ui/og_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,7 @@ function og_ui_user_access_group($perm, $group_type, $gid) {
return FALSE;
}

$entity_info = entity_get_info($group_type);
if (!$group_type || !$entity_info) {
// Not a valid entity type.
return FALSE;
}
return og_is_group($group_type, $group) && og_user_access($group_type, $gid, $perm);
return og_user_access($group_type, $gid, $perm);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions og_ui/og_ui.pages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function og_ui_subscribe($entity_type, $etid, $field_name = NULL) {

$account = user_load($user->uid);
if (empty($field_name)) {
$field_name = og_get_best_group_audience_field('user', $account, $entity_type, $bundle);
$field_name = og_get_best_group_audience_field('user', $account, $entity_type, $bundle, TRUE);
if (empty($field_name)) {
// User entity has no group audience field.
drupal_not_found();
Expand Down Expand Up @@ -237,7 +237,7 @@ function og_ui_confirm_unsubscribe($form, &$form_state, $group_type, $group) {

$label = entity_label($group_type, $group);
$url = entity_uri($group_type, $group);
return confirm_form($form, t('Are you sure you want to unsubscribe from the group %title?', array('%title' => $label)), $url, NULL, t('Remove'), t('Cancel'));
return confirm_form($form, t('Are you sure you want to unsubscribe from the group %title?', array('%title' => $label)), $url, NULL, t('Unsubscribe'), t('Cancel'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion og_ui/og_ui.test
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class OgUiSubscribeTestCase extends DrupalWebTestCase {
$this->drupalGet('node/' . $node->nid);
$this->assertText(t('Unsubscribe from group'), t('Member gets correct unsubscribe text.'));
$this->clickLink(t('Unsubscribe from group'));
$this->drupalPost(NULL, array() , t('Remove'));
$this->drupalPost(NULL, array() , t('Unsubscribe'));

$this->assertFalse(og_is_member('node', $node->nid, 'user', $user2, array(OG_STATE_ACTIVE, OG_STATE_PENDING)), t('User unsubscribed from group.'));

Expand Down
28 changes: 11 additions & 17 deletions plugins/entityreference/behavior/OgBehaviorHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,20 @@ public function views_data_alter(&$data, $field) {
// that this field is attached to.
foreach ($entity_types as $entity_type) {
$entity_info = entity_get_info($entity_type);
$data['og_membership'] = array(
'table' => array(
'join' => array(
$entity_info['base table'] => array(
// Join entity base table on its id field with left_field.
'left_field' => $entity_info['entity keys']['id'],
'field' => 'etid',
'extra' => array(
0 => array(
'field' => 'entity_type',
'value' => $entity_type,
),
),
),
$data['og_membership']['table']['join'][$entity_info['base table']] = array(
// Join entity base table on its id field with left_field.
'left_field' => $entity_info['entity keys']['id'],
'field' => 'etid',
'extra' => array(
0 => array(
'field' => 'entity_type',
'value' => $entity_type,
),
),
// Copy the original config from the table definition.
$field['field_name'] => $data['field_data_' . $field['field_name']][$field['field_name']],
$field['field_name'] . '_target_id' => $data['field_data_' . $field['field_name']][$field['field_name'] . '_target_id'],
);
// Copy the original config from the table definition.
$data['og_membership'][$field['field_name']] = $data['field_data_' . $field['field_name']][$field['field_name']];
$data['og_membership'][$field['field_name'] . '_target_id'] = $data['field_data_' . $field['field_name']][$field['field_name'] . '_target_id'];

// Change config with settings from og_membership table.
foreach (array('filter', 'argument', 'sort', 'relationship') as $op) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS

$field_mode = $this->instance['field_mode'];
$user_groups = og_get_groups_by_user(NULL, $group_type);
$user_groups = $user_groups ? $user_groups : array();
$user_groups = array_merge($user_groups, $this->getGidsForCreate());


Expand Down

0 comments on commit faea5e6

Please sign in to comment.