You are here

function group_membership_access in Group 7

Entity API access callback for group memberships.

Only used for 'view', 'update' and 'delete'; 'create' is usually handled by membership actions such as "Join group" and 'Request membership". Same goes for 'delete', actually, but we only allow administrative deletes here.

2 string references to 'group_membership_access'
GroupMembershipUIController::hook_menu in classes/group_membership.ui_controller.inc
Provides definitions for implementing hook_menu().
group_entity_info in ./group.entity.inc
Implements hook_entity_info().

File

./group.entity.inc, line 252
Contains all Entity API functions for the Group module.

Code

function group_membership_access($op, GroupMembership $group_membership = NULL, $account = NULL) {
  if (!empty($group_membership)) {
    $group = group_load($group_membership->gid);
    global $user;
    if (!isset($account)) {
      $account = $user;
    }
    $is_own = $group_membership->uid == $account->uid;
    switch ($op) {
      case 'view':
        return $is_own || group_access('access member pages', $group, $account);
      case 'update':
        return group_access('administer members', $group, $account) || $is_own && group_access('edit own membership', $group, $account);
      case 'delete':
        return group_access('administer members', $group, $account);
      case 'metadata':
        return group_access('access member metadata', $group, $account);
    }
  }
  return FALSE;
}