public static function PrepareStorageElementInfo(&$arFields) { $storageTypeID = isset($arFields['STORAGE_TYPE_ID']) ? (int) $arFields['STORAGE_TYPE_ID'] : StorageType::Undefined; if (!StorageType::IsDefined($storageTypeID)) { $storageTypeID = self::GetDefaultStorageTypeID(); } $storageElementIDs = isset($arFields['STORAGE_ELEMENT_IDS']) && is_array($arFields['STORAGE_ELEMENT_IDS']) ? $arFields['STORAGE_ELEMENT_IDS'] : array(); if ($storageTypeID === StorageType::File) { $arFields['FILES'] = array(); foreach ($storageElementIDs as $fileID) { $arData = CFile::GetFileArray($fileID); if (is_array($arData)) { $arFields['FILES'][] = array('fileID' => $arData['ID'], 'fileName' => $arData['FILE_NAME'], 'fileURL' => CCrmUrlUtil::UrnEncode($arData['SRC']), 'fileSize' => $arData['FILE_SIZE']); } } } elseif ($storageTypeID === StorageType::WebDav) { $infos = array(); foreach ($storageElementIDs as $elementID) { $infos[] = \CCrmWebDavHelper::GetElementInfo($elementID, $storageTypeID); } $arFields['WEBDAV_ELEMENTS'] =& $infos; unset($infos); } elseif ($storageTypeID === StorageType::Disk) { $infos = array(); foreach ($storageElementIDs as $elementID) { $infos[] = Bitrix\Crm\Integration\DiskManager::getFileInfo($elementID, false, array('OWNER_TYPE_ID' => CCrmOwnerType::Activity, 'OWNER_ID' => $arFields['ID'])); } $arFields['DISK_FILES'] =& $infos; unset($infos); } }
public 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) { $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; } } if (!CCrmActivity::CheckStorageElementExists($ownerID, CCrmActivityStorageType::Disk, $fileID)) { $errors[] = 'File not found'; return false; } $isPermitted = false; if (CCrmPerms::IsAdmin()) { $isPermitted = true; } else { $userPermissions = CCrmPerms::GetCurrentUserPermissions(); $bindings = CCrmActivity::GetBindings($ownerID); foreach ($bindings as $binding) { if (CCrmAuthorizationHelper::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); return true; }