You are here

function redhen_relation_entity_access in RedHen CRM 7

Relation entity access call back. Replaces the default relation entity access and menu access callbacks.

Parameters

string $op: Operation. One of view, update, create or delete.

array $entity: Relation entity.

Return value

bool Access grant.

1 call to redhen_relation_entity_access()
redhen_relation_connections_page in modules/redhen_relation/redhen_relation.module
Page callback for listing connections.
3 string references to 'redhen_relation_entity_access'
redhen_relation_entity_info_alter in modules/redhen_relation/redhen_relation.module
Implements hook_entity_info_alter().
redhen_relation_menu in modules/redhen_relation/redhen_relation.module
Implements hook_menu().
redhen_relation_menu_alter in modules/redhen_relation/redhen_relation.module
Implements hook_menu_alter().

File

modules/redhen_relation/redhen_relation.module, line 115
Redhen CRM Relation Module.

Code

function redhen_relation_entity_access($op, $entity) {
  global $user;

  // If admin, skip other checks.
  if (user_access('administer relations')) {
    return TRUE;
  }
  $permission = FALSE;
  switch ($op) {
    case 'view':
      $permission = 'access relations';
      $relation_permission = 'view_relation';
      break;
    case 'create':
      $permission = 'create relations';
      $relation_permission = 'edit_relation';
      break;
    case 'update':
      $relation_permission = 'edit_relation';
      $permission = 'edit relations';
      break;
    case 'delete':
      $relation_permission = 'delete_relation';
      $permission = 'delete relations';
      break;
  }

  // Get the default access permission based on the $op.
  $user_access = user_access($permission);

  // Check that this is a relation we care about.
  if (array_key_exists('relation_type', $entity) && $entity->relation_type == REDHEN_RELATION_AFFILIATION) {

    // Check for Org relation permissions.
    $permissions = redhen_relation_role_get_permissions($user);
    $relation = relation_get_endpoints($entity, 'redhen_org');
    $org = $relation ? current(current($relation)) : array();
    if ($relation && isset($permissions[$org->org_id][$relation_permission]) && $permissions[$org->org_id][$relation_permission] !== 0) {
      $user_access = TRUE;
    }
  }
  return $user_access;
}