You are here

function _file_resource_access in Services 6.3

Same name and namespace in other branches
  1. 7.3 resources/file_resource.inc \_file_resource_access()

Access check callback for file controllers.

1 string reference to '_file_resource_access'
_file_resource_definition in resources/file_resource.inc
THERE SHOULD BE NO UPDATE!!! Drupal doesn't allow updating or replacing a file in the files table. If you need to, create a new file and remove the old file.

File

resources/file_resource.inc, line 343
File resource.

Code

function _file_resource_access($op = 'view', $args = array()) {

  // Adds backwards compatability with regression fixed in #1083242
  $args[0] = _services_access_value($args[0], 'file');
  global $user;
  if (user_access('administer files')) {
    return TRUE;
  }
  if ($op == 'create') {
    $file = (object) $args[0];
  }
  else {
    $file = db_fetch_object(db_query('SELECT * FROM {files} WHERE fid = %d', $args[0]));
  }
  switch ($op) {
    case 'view':
    case 'index':
      if (user_access('get any binary files')) {
        return TRUE;
      }
      return $file->uid == $user->uid && user_access('get own binary files');
      break;
    case 'create':
    case 'delete':
      return $file->uid == $user->uid && user_access('save file information');
      break;
  }
  return FALSE;
}