- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/file_proxy.php
- Класс: \CCrmFileProxy
- Вызов: CCrmFileProxy::WriteDiskFileToResponse
static function WriteDiskFileToResponse($ownerTypeID, $ownerID, $fileID, &$errors, $options = array())
{
$ownerTypeID = (int)$ownerTypeID;
$ownerTypeName = CCrmOwnerType::ResolveName($ownerTypeID);
$ownerID = (int)$ownerID;
$fileID = (int)$fileID;
$options = is_array($options) ? $options : array();
if(!CCrmOwnerType::IsDefined($ownerTypeID) || $ownerID <= 0 || $fileID <= 0)
{
$errors[] = 'Invalid data ownerTypeID = '.$ownerTypeID.', ownerID = '.$ownerID.', fileID = '.$fileID;
return false;
}
if($ownerTypeID !== CCrmOwnerType::Activity && $ownerTypeID !== CCrmOwnerType::Quote)
{
$errors[] = "The owner type '{$ownerTypeName}' is not supported in current context";
return false;
}
$authToken = isset($options['oauth_token']) ? $options['oauth_token'] : '';
if($authToken !== '')
{
$authData = array();
if(!(CModule::IncludeModule('rest')
&& CRestUtil::checkAuth($authToken, CCrmRestService::SCOPE_NAME, $authData)
&& CRestUtil::makeAuth($authData)))
{
$errors[] = 'Access denied.';
return false;
}
}
$isFileExists = false;
switch ($ownerTypeID)
{
case CCrmOwnerType::Activity:
$isFileExists = CCrmActivity::CheckStorageElementExists($ownerID, StorageType::Disk, $fileID);
break;
case CCrmOwnerType::Quote:
$isFileExists = CCrmQuote::CheckStorageElementExists($ownerID, StorageType::Disk, $fileID);
break;
}
if(!$isFileExists)
{
$errors[] = 'File not found';
return false;
}
$isPermitted = false;
if(CCrmPerms::IsAdmin())
{
$isPermitted = true;
}
else
{
$userPermissions = CCrmPerms::GetCurrentUserPermissions();
switch ($ownerTypeID)
{
case CCrmOwnerType::Activity:
$bindings = CCrmActivity::GetBindings($ownerID);
break;
case CCrmOwnerType::Quote:
$bindings = array(array('OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => $ownerTypeID));
break;
default:
$bindings = array();
}
foreach($bindings as $binding)
{
if(\Bitrix\Crm\Security\EntityAuthorization::checkReadPermission(
$binding['OWNER_TYPE_ID'],
$binding['OWNER_ID'],
$userPermissions
)
)
{
$isPermitted = true;
break;
}
}
}
if(!$isPermitted)
{
$errors[] = 'Access denied.';
return false;
}
Bitrix\Crm\Integration\DiskManager::writeFileToResponse($fileID, $options);
return true;
}