function _file_resource_access in Services 7.3
Same name and namespace in other branches
- 6.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 359 - File resource.
Code
function _file_resource_access($op = 'view', $args = array()) {
// Adds backwards compatability with regression fixed in #1083242
if (isset($args[0])) {
$args[0] = _services_access_value($args[0], 'file');
}
global $user;
if ($op != 'create' && $op != 'create_raw' && $op != 'index') {
$file = file_load($args[0]);
}
else {
if ($op == 'create' && $op != 'create_raw') {
$file = (object) $args[0];
}
}
if (empty($file) && $op != 'index' && ($op != 'create' && $op != 'create_raw')) {
return services_error(t('There is no file with ID @fid', array(
'@fid' => $args[0],
)), 406);
}
switch ($op) {
case 'view':
if (user_access('get any binary files')) {
return TRUE;
}
return $file->uid == $user->uid && user_access('get own binary files');
break;
case 'create':
case 'create_raw':
return user_access('save file information');
case 'delete':
return $file->uid == $user->uid && user_access('save file information');
break;
case 'index':
if (user_access('get any binary files')) {
return TRUE;
}
}
return FALSE;
}