You are here

function services_views_access in Services Views 7

Same name and namespace in other branches
  1. 6 services_views.module \services_views_access()

Check the access permission to a given views.

Parameters

string $op: The operation that's going to be performed.

array $args: The arguments that will be passed to the callback.

Return value

bool TRUE if the user is allowed to load the given view.

1 string reference to 'services_views_access'
services_views_services_resources in ./services_views.module
Implements hook_services_resources().

File

./services_views.module, line 187
Provides a generic but powerful API for web services.

Code

function services_views_access($op = 'view', array $args = array()) {
  $args = services_views_convert_numeric_args_to_named_args($args);
  switch ($op) {
    case 'view':
      $router_item = menu_get_item();
      $page_arguments = $router_item['page_arguments'];
      $endpoint = $page_arguments[0];
      $prefix = 'services_views_' . $endpoint;
      $whitelist = variable_get($prefix . '_white_list', 0);
      $listed_views = variable_get($prefix . "_view_displays", array());
      $view = views_get_view($args['view_name']);
      if (empty($view)) {
        return services_error(t('View @view could not be found', array(
          '@view' => $args['view_name'],
        )), 404);
      }

      // Determine the display we want to use.
      $display_id = $args['display_id'];
      if (empty($view->display[$display_id]) || $view->display[$display_id]->display_plugin != 'services') {
        $display_id = 'services_clone_' . $display_id;
        if (empty($view->display[$display_id]) || $view->display[$display_id]->display_plugin != 'services') {
          return services_error(t('Display @display on view @view could not be found', array(
            '@display' => $args['display_id'],
            '@view' => $args['view_name'],
          )), 404);
        }
      }
      $listed_view_key = $args['view_name'] . '|' . $display_id;
      if (!empty($whitelist) && empty($listed_views[$listed_view_key])) {
        return services_error(t('Display @display on view @view could not be found', array(
          '@display' => $args['display_id'],
          '@view' => $args['view_name'],
        )), 404);
      }
      elseif (empty($whitelist) && !empty($listed_views[$listed_view_key])) {
        return services_error(t('Display @display on view @view could not be found', array(
          '@display' => $args['display_id'],
          '@view' => $args['view_name'],
        )), 404);
      }
      return $view
        ->access($display_id);
  }
}