private static function needProxyToDiskByDocType($documentType) { if (!(\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk'))) { return false; } if (empty($documentType)) { return false; } $storage = null; if (substr($documentType, 0, 7) == 'STORAGE') { $storageId = (int) substr($documentType, 8); if ($storageId) { $storage = \Bitrix\Disk\Storage::loadById($storageId); } if ($storage) { return $storage; } } list(, $iblockId, $typeLib, $entityId) = explode('_', $documentType); if ($typeLib == 'user') { $storage = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($entityId); } elseif ($typeLib == 'group') { $storage = \Bitrix\Disk\Driver::getInstance()->getStorageByGroupId($entityId); } else { return false; } return $storage; }
public static function GetStorage() { if (!self::Enabled()) { return false; } $storageModel = false; if ($storageId = self::GetStorageId()) { $storageModel = \Bitrix\Disk\Storage::loadById($storageId); if (!$storageModel || $storageModel->getModuleId() != self::MODULE_ID) { $storageModel = false; } } if (!$storageModel) { $data['NAME'] = GetMessage('IM_DISK_STORAGE_TITLE'); $data['USE_INTERNAL_RIGHTS'] = 1; $data['MODULE_ID'] = self::MODULE_ID; $data['ENTITY_TYPE'] = IM\Disk\ProxyType\Im::className(); $data['ENTITY_ID'] = self::MODULE_ID; $driver = \Bitrix\Disk\Driver::getInstance(); $rightsManager = $driver->getRightsManager(); $fullAccessTaskId = $rightsManager->getTaskIdByName($rightsManager::TASK_FULL); $storageModel = $driver->addStorageIfNotExist($data, array(array('ACCESS_CODE' => 'AU', 'TASK_ID' => $fullAccessTaskId))); if ($storageModel) { self::SetStorageId($storageModel->getId()); } else { $storageModel = false; } } return $storageModel; }
/** * Initializes storage by component parameters. * @return $this */ protected function initializeStorage() { if (isset($this->arParams['STORAGE'])) { $this->storage = $this->arParams['STORAGE']; return $this; } elseif (isset($this->arParams['STORAGE_ID'])) { $this->storage = Storage::loadById($this->arParams['STORAGE_ID']); } else { $this->storage = Storage::load(array('MODULE_ID' => $this->arParams['STORAGE_MODULE_ID'], 'ENTITY_TYPE' => $this->arParams['STORAGE_ENTITY_TYPE'], 'ENTITY_ID' => $this->arParams['STORAGE_ENTITY_ID'])); } return $this; }
/** * @return Storage|null */ public function getRealStorage() { if (!$this->realStorageId) { return null; } if (isset($this->realStorage) && $this->realStorageId === $this->realStorage->getId()) { return $this->realStorage; } $this->realStorage = Storage::loadById($this->realStorageId); return $this->realStorage; }
/** * @param $storageId * @return $this */ public function setStorageId($storageId) { $this->storageId = $storageId; $this->storage = \Bitrix\Disk\Storage::loadById($storageId['IBLOCK_ID'], array('ROOT_OBJECT')); return $this; }
public static function getUsersFromUserGroup($group, $documentId) { if (substr($documentId, 0, 8) == "STORAGE_") { $storageId = self::getStorageIdByType($documentId); } else { if (is_array($documentId)) { $documentId = intval($documentId[2]); } /** @var File $file */ $file = File::loadById($documentId); if (!$file) { return array(); } $storageId = $file->getStorageId(); } if (strtolower($group) == "author") { $documentId = intval($documentId); if ($documentId <= 0) { return array(); } /** @var File $file */ $file = File::loadById($documentId); if (!$file) { return array(); } return array($file->getCreatedBy()); } if ($storageId) { $storage = Storage::loadById($storageId, array('ROOT_OBJECT')); if ($storage->getProxyType() instanceof ProxyType\Group) { $entityId = $storage->getEntityId(); $group = strtoupper($group); if (Loader::includeModule("socialnetwork")) { $listUserGroup = array(); if ($group == SONET_ROLES_OWNER) { $listGroup = \CSocNetGroup::getByID($entityId); if ($listGroup) { $listUserGroup[] = $listGroup["OWNER_ID"]; } } elseif ($group == SONET_ROLES_MODERATOR) { $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_MODERATOR, "USER_ACTIVE" => "Y"), false, false, array("USER_ID")); while ($res = $dbRes->fetch()) { $listUserGroup[] = $res["USER_ID"]; } } elseif ($group == SONET_ROLES_USER) { $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y"), false, false, array("USER_ID")); while ($res = $dbRes->fetch()) { $listUserGroup[] = $res["USER_ID"]; } } return $listUserGroup; } } } $group = intval($group); if ($group <= 0) { return array(); } $userIds = array(); $filter = array("ACTIVE" => "Y"); if ($group != 2) { $filter["GROUPS_ID"] = $group; } $query = \CUser::getList($b = "ID", $o = "ASC", $filter); while ($user = $query->fetch()) { $userIds[] = $user["ID"]; } return $userIds; }
private function getStorageByType($type, $storageId) { $storage = null; if ($type === 'user') { return Driver::getInstance()->getStorageByUserId($this->getUser()->getId()); } elseif ($type === 'group') { $storage = Storage::loadById($storageId); if (!$storage->getProxyType() instanceof ProxyType\Group) { $this->errorCollection->add(array(new Error("Invalid storage type {$type}. Is not a group."))); return null; } } elseif ($type === 'common') { $storage = Storage::loadById($storageId); if (!$storage->getProxyType() instanceof ProxyType\Common) { $this->errorCollection->add(array(new Error("Invalid storage type {$type}. Is not a common storage."))); return null; } } return $storage; }
/** * Collect all subscribers by object (@see Sharing) * Return associative array: storageId => userId. * * @param \Bitrix\Disk\BaseObject|BaseObject $object Target object. * @return array */ public function collectSubscribers(BaseObject $object) { $subscribers = array(); foreach ($object->getParents($this->getFakeSecurityContext()) as $parent) { if (!$parent instanceof Folder) { continue; } $subscribers = $this->appendSubscribersBySharings($parent, $subscribers); } unset($parent); $subscribers = $this->appendSubscribersBySharings($object, $subscribers); $storage = Storage::loadById($object->getStorageId()); if ($storage && $storage->getProxyType() instanceof ProxyType\User) { $subscribers[$storage->getId()] = $storage->getEntityId(); } return $subscribers; }
protected function processActionLoadItems() { $this->checkRequiredPostParams(array('FORM_TAB_TYPE', 'FORM_TAB_ID', 'FORM_PATH')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $dialogName = $this->request->getPost('FORM_NAME') ?: 'DiskFileDialog'; $typeStorage = strtolower($this->request->getPost('FORM_TAB_TYPE')); if (!in_array($typeStorage, array('user', 'common', 'group', 'cloud'), true)) { $this->errorCollection->add(array(new Error("Invalid storage type {$typeStorage}"))); $this->sendJsonErrorResponse(); } $storageId = (int) $this->request->getPost('FORM_TAB_ID'); $path = $this->request->getPost('FORM_PATH'); $storage = null; if ($typeStorage === 'user') { $storage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId()); } elseif ($typeStorage === 'group') { $storage = Storage::loadById($storageId); if (!$storage->getProxyType() instanceof ProxyType\Group) { $this->errorCollection->add(array(new Error("Invalid storage type {$typeStorage}. Is not a group."))); $this->sendJsonErrorResponse(); } } elseif ($typeStorage === 'common') { $storage = Storage::loadById($storageId); if (!$storage->getProxyType() instanceof ProxyType\Common) { $this->errorCollection->add(array(new Error("Invalid storage type {$typeStorage}. Is not a common storage."))); $this->sendJsonErrorResponse(); } } elseif ($typeStorage === 'cloud') { $documentHandlersManager = Driver::getInstance()->getDocumentHandlersManager(); $documentHandler = $documentHandlersManager->getHandlerByCode($this->request->getQuery('service')); if (!$documentHandler) { $this->errorCollection->add($documentHandlersManager->getErrors()); $this->sendJsonErrorResponse(); } if (!$documentHandler->checkAccessibleTokenService()) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE', array('#NAME#' => $documentHandler->getName())), self::ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE))); $this->errorCollection->add($documentHandler->getErrors()); $this->sendJsonErrorResponse(); } if (!$documentHandler->queryAccessToken()->hasAccessToken() || $documentHandler->isRequiredAuthorization()) { $this->sendNeedAuth($documentHandler->getUrlForAuthorizeInTokenService('opener')); } $itemsCloud = $this->listItemsCloud($documentHandler, $path); if ($itemsCloud === null && $documentHandler->isRequiredAuthorization()) { $this->sendNeedAuth($documentHandler->getUrlForAuthorizeInTokenService('opener')); } $this->sendJsonSuccessResponse(array('FORM_NAME' => $dialogName, 'FORM_ITEMS' => $itemsCloud, 'FORM_ITEMS_DISABLED' => array(), 'FORM_PATH' => $path, 'FORM_IBLOCK_ID' => 0)); } if (!$storage) { $this->errorCollection->add(array(new Error('Could not find storage for current user'))); $this->sendJsonErrorResponse(); } $this->sendJsonSuccessResponse(array('FORM_NAME' => $dialogName, 'FORM_ITEMS' => $this->listItems($storage, $path), 'FORM_ITEMS_DISABLED' => array(), 'FORM_PATH' => $path, 'FORM_IBLOCK_ID' => 0)); }
protected function processActionSaveRightsOnStorage() { $this->checkRequiredPostParams(array('storageId')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $storage = Storage::loadById((int) $this->request->getPost('storageId'), array('ROOT_OBJECT')); if (!$storage) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FOLDER_LIST_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT))); $this->sendJsonErrorResponse(); } $rightsManager = Driver::getInstance()->getRightsManager(); $securityContext = $storage->getCurrentUserSecurityContext(); if (!$storage->canChangeRights($securityContext)) { $this->sendJsonAccessDeniedResponse(); } $showExtendedRights = (bool) $this->request->getPost('showExtendedRights'); if ($storage->isEnabledShowExtendedRights() != $showExtendedRights) { $showExtendedRights ? $storage->enableShowExtendedRights() : $storage->disableShowExtendedRights(); } if (!$this->request->getPost('isChangedRights')) { $this->sendJsonSuccessResponse(); } $storageNewRights = $this->request->getPost('storageNewRights'); if (!empty($storageNewRights) && is_array($storageNewRights)) { $newRights = array(); foreach ($storageNewRights as $accessCode => $right) { if (!empty($right['right']['id'])) { $newRights[] = array('ACCESS_CODE' => $accessCode, 'TASK_ID' => $right['right']['id']); } } unset($accessCode, $right); if (empty($newRights)) { $this->sendJsonErrorResponse(); } if ($rightsManager->set($storage->getRootObject(), $newRights)) { $this->sendJsonSuccessResponse(); } } $this->sendJsonErrorResponse(); }
private static function needProxyToDiskByDocType($documentType) { if (!(\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk'))) { return false; } if (empty($documentType)) { return false; } $storage = null; if (substr($documentType, 0, 7) == 'STORAGE') { $storageId = (int) substr($documentType, 8); if ($storageId) { $storage = \Bitrix\Disk\Storage::loadById($storageId); } if ($storage) { return $storage; } } list(, $iblockId) = explode('_', $documentType); if (!$iblockId) { return false; } $storage = \Bitrix\Disk\Storage::load(array('XML_ID' => $iblockId, 'MODULE_ID' => \Bitrix\Disk\Driver::INTERNAL_MODULE_ID, 'ENTITY_TYPE' => \Bitrix\Disk\ProxyType\Common::className())); if (!$storage) { return false; } return $storage; }
private function checkUseInternalsRightsOnStorage(BaseObject $object, $rights) { $storageModel = Storage::loadById($object->getStorageId()); if (!empty($rights) && !$storageModel->isUseInternalRights()) { throw new SystemException('Attempt to set the rights, but not to use the internal rights.'); } }
} global $USER; if (!isset($USER) || !$USER->isAuthorized() || !$USER->getId()) { return; } $arDefaultUrlTemplates404 = array("trashcan_list" => "trashcan/#TRASH_PATH#", "trashcan_file_view" => "trash/file/#TRASH_FILE_PATH#", "folder_list" => "path/#PATH#", "file_view" => "file/#FILE_PATH#", "external_link_list" => "external", "disk_help" => "help", "disk_bizproc_workflow_admin" => "bp/", "disk_bizproc_workflow_edit" => "bp_edit/#ID#/", "disk_start_bizproc" => "bp_start/#ELEMENT_ID#/", "disk_task" => "bp_task/#ID#/", "disk_task_list" => "bp_task_list/"); $arDefaultVariableAliases404 = array(); $arDefaultVariableAliases = array(); $componentPage = ''; $arComponentVariables = array('FOLDER_ID', 'FILE_ID', 'PATH'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); if (empty($arParams['STORAGE'])) { if (empty($arParams['STORAGE_ID'])) { return; } $arParams['STORAGE'] = \Bitrix\Disk\Storage::loadById((int) $arParams['STORAGE_ID'], array('ROOT_OBJECT')); } if (empty($arParams['STORAGE'])) { //necessary return; } if ($arParams['SEF_MODE'] == 'Y') { $arVariables = array(); $engine = new CComponentEngine($this); $engine->addGreedyPart("#PATH#"); $engine->addGreedyPart("#FILE_PATH#"); $engine->addGreedyPart("#TRASH_PATH#"); $engine->addGreedyPart("#TRASH_FILE_PATH#"); $engine->setResolveCallback(array(\Bitrix\Disk\Driver::getInstance()->getUrlManager(), "resolvePathComponentEngine")); $arUrlTemplates = CComponentEngine::MakeComponentUrlTemplates($arDefaultUrlTemplates404, isset($arParams["SEF_URL_TEMPLATES"]) ? $arParams["SEF_URL_TEMPLATES"] : array()); $arVariableAliases = CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases404, isset($arParams["VARIABLE_ALIASES"]) ? $arParams["VARIABLE_ALIASES"] : array());
/** * Returns storage model. * @return array|Storage|null */ public function getStorage() { if (!$this->storageId) { return null; } if (isset($this->storage) && $this->storageId == $this->storage->getId()) { return $this->storage; } $this->storage = Storage::loadById($this->storageId, array('ROOT_OBJECT')); if (!$this->storage) { return array(); } return $this->storage; }