The submodule "privatemsg_groups" supplies the permission "Write private messages to all organic groups". Users with this permission only can send public messages to all public groups. If the organic groups submodule "og_access" is enabled and there are some private groups, user with the permission "Write private messages to all organic groups" can not send to messages to this private groups.

I wrote a patch which adds a new permission: "Write private messages to all organic groups (public and private groups)"

  if (module_exists('og_access')) {
    $permissions['write privatemsg to all private organic groups'] = array(
      'title' => t('Write private messages to all organic groups (public and private groups)'),
      'description' => t('Allows to write messages to all users which belong to a public or a private organic group.'),
      'warning' => t('This permission allows users to view the title and the members of all private groups.'),
    );

In my patch I added two functions, which are a replacement of the organic group function og_get_all_group. og_get_all_group only returns the groups ids of users own groups and all public groups.

/**
 * Return all organic groups.
 *
 * @return array
 *   A array of groups IDs ($gids).
 */
function privatemsg_groups_get_all_groups() {
  $get_all_groups = 'og_get_all_group';

  if (module_exists('og_access') && user_access('write privatemsg to all private organic groups')) {
    $get_all_groups = '_privatemsg_groups_get_all_private_groups';
  }

  return $get_all_groups();
}

/**
 * Return all existing private and public groups.
 *
 * @return array
 *   A array of groups IDs ($gids).
 */
function _privatemsg_groups_get_all_private_groups() {

  if (!field_info_field(OG_GROUP_FIELD)) {
    return array();
  }

  $query = db_select('field_data_' . OG_GROUP_FIELD, 'f')
    ->fields('f',array('entity_id'))
    ->condition('f.' . OG_GROUP_FIELD . '_value', 1);

  $result = $query->execute()
    ->fetchAllAssoc('entity_id');

  return !empty($result) ? array_keys($result) : array();
}

Is there a possibility to add this permission to the 2.x dev branch?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JosefFriedrich’s picture

The patch as described above:

JosefFriedrich’s picture

Better patch then #1 (Fix some erorrs)

ptmkenny’s picture

Status: Active » Needs review
ptmkenny’s picture

Issue summary: View changes

Add some text

ivnish’s picture

Status: Needs review » Closed (outdated)