You are here

function spaces_dashboard_access in Spaces 6.3

Same name and namespace in other branches
  1. 7.3 spaces_dashboard/spaces_dashboard.module \spaces_dashboard_access()
  2. 7 spaces_dashboard/spaces_dashboard.module \spaces_dashboard_access()

Menu access callback.

Because spaces_dashboard provides a speciality callback for the user space which can be visible at the same time as the normal callback we need a slightly more complex access check for the main callback.

Parameters

$op: The operation to check access for, either 'feature' for whether the user may view the dashboard feature or 'admin' for whether the user may alter the dashboard in question.

$dashboard: String identifier for the dashboard page to check access on.

$type: The type of dashboard, 'user' or 'site'.

$space: The space to check access against. If not provided the current space will be used.

2 calls to spaces_dashboard_access()
spaces_dashboard_access_user in spaces_dashboard/spaces_dashboard.module
Access callback for the user Dashboard.
spaces_dashboard_block in spaces_dashboard/spaces_dashboard.module
Implementation of hook_block().
1 string reference to 'spaces_dashboard_access'
spaces_dashboard_menu in spaces_dashboard/spaces_dashboard.module
Implementation of hook_menu()

File

spaces_dashboard/spaces_dashboard.module, line 170

Code

function spaces_dashboard_access($op = 'feature', $dashboard = NULL, $type = NULL, $space = NULL) {

  // Make sure the requested dashboard exists.
  if (isset($dashboard)) {
    $custom = variable_get('spaces_dashboard_custom', array(
      'custom-1' => t('Dashboard'),
    ));
    if (empty($custom[$dashboard]) && $dashboard !== 'custom-1') {
      return FALSE;
    }
  }

  // Non-spaces usage.
  if (!module_exists('spaces')) {
    switch ($op) {
      case 'admin':
        return user_access('administer dashboards');
      default:
        return user_access('access content');
    }
  }

  // Spaces usage.
  $space = isset($space) ? $space : spaces_get_space();
  $type = !isset($type) && isset($space->type) ? $space->type : $type;
  switch ($type) {
    case 'user':
      if ($space && $space->type === 'user') {

        // This check ensures that only the user that the dashboard belongs
        // to (and admins) can view and edit the user's dashboard.
        global $user;
        $access = $user->uid == $space->id || user_access('administer dashboards');
        return $access && spaces_access_feature($op, 'spaces_dashboard');
      }
      return FALSE;
    case 'og':
      if ($space && $space->type === 'og') {
        switch ($op) {
          case 'admin':
            return spaces_access_admin(NULL, $space);
          default:
            return spaces_access_feature($op, 'spaces_dashboard');
            break;
        }
        return FALSE;
      }
    default:

      // When the dashboard is turned on for a different space type and the
      // user space is active do a separate access check for the dashboard.
      if ($space && $space->type === 'user') {
        switch ($op) {
          case 'admin':
            return user_access('administer dashboards');
          default:
            if ($features = $space->controllers->variable
              ->get('spaces_features', 'original')) {
              return user_access('access content') && !empty($features['spaces_dashboard']);
            }
            break;
        }
        return FALSE;
      }

      // Otherwise, do a normal spaces access check.
      switch ($op) {
        case 'admin':
          return user_access('administer dashboards');
        default:
          return spaces_access_feature($op, 'spaces_dashboard');
      }
      break;
  }
}