- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/controller/documentservice.php
- Класс: BitrixDiskControllerDocumentService
- Вызов: DocumentService::goToEditOrPreviewAction
public function goToEditOrPreviewAction($serviceCode, $attachedObjectId = null, $objectId = null, $versionId = null)
{
$driver = Driver::getInstance();
$handlersManager = $driver->getDocumentHandlersManager();
$documentHandler = $handlersManager->getHandlerByCode($serviceCode);
if (!$documentHandler)
{
$this->addError(new Error('There is no document service by code'));
}
if (!($documentHandler instanceof OnlyOfficeHandler))
{
$this->addError(new Error('Work only with OnlyOffice'));
}
if ($this->getErrors())
{
return null;
}
$canEdit = false;
if ($versionId)
{
$version = DiskVersion::getById($versionId);
if ($version)
{
$objectId = $version->getObjectId();
}
}
if ($objectId)
{
$file = DiskFile::getById($objectId);
if ($file)
{
$securityContext = $file->getStorage()->getSecurityContext($this->getCurrentUser());
$canEdit = $file->canUpdate($securityContext);
}
}
if ($attachedObjectId)
{
$attachedObject = DiskAttachedObject::getById($attachedObjectId);
if ($attachedObject)
{
$canEdit = $canEdit || $attachedObject->canUpdate($this->getCurrentUser()->getId());
}
}
if ($canEdit)
{
return $this->goToEditAction($serviceCode, $attachedObjectId, $objectId);
}
return $this->goToPreviewAction($serviceCode, $attachedObjectId, $objectId, $versionId);
}