/** * @return Sharing|null */ public function getParent() { if (!$this->parentId) { return null; } if (isset($this->parent) && $this->parentId === $this->parent->getId()) { return $this->parent; } $this->parent = Sharing::loadById($this->parentId); return $this->parent; }
protected function processActionDefault() { $this->getApplication()->setTitle($this->storage->getProxyType()->getTitleForCurrentUser()); $securityContext = $this->storage->getCurrentUserSecurityContext(); $this->arParams['STATUS_BIZPROC'] = $this->storage->isEnabledBizProc() && Loader::includeModule("bizproc"); $gridId = 'folder_list_' . $this->storage->getId(); $this->processGridActions($gridId); $errorsInGridActions = array(); if ($this->errorCollection->hasErrors()) { foreach ($this->getErrors() as $error) { /** @var Error $error */ $errorsInGridActions[] = array('message' => $error->getMessage(), 'code' => $error->getCode()); } $this->errorCollection->clear(); } $proxyType = $this->storage->getProxyType(); $isGroupStorage = $proxyType instanceof ProxyType\Group; $isConnectedGroupStorage = false; $groupSharingData = array(); if ($isGroupStorage) { $isConnectedGroupStorage = Sharing::isConnectedToUserStorage($this->getUser()->getId(), $this->storage->getRootObject(), $groupSharingData); } if ($this->arParams['STATUS_BIZPROC']) { $documentData = array('DISK' => array('DOCUMENT_TYPE' => \Bitrix\Disk\BizProcDocument::generateDocumentComplexType($this->storage->getId())), 'WEBDAV' => array('DOCUMENT_TYPE' => \Bitrix\Disk\BizProcDocumentCompatible::generateDocumentComplexType($this->storage->getId()))); $this->arParams['TEMPLATE_BIZPROC'] = $this->getTemplateBizProc($documentData); } $this->arResult = array('ERRORS_IN_GRID_ACTIONS' => $errorsInGridActions, 'GRID' => $this->getGridData($gridId), 'IS_BITRIX24' => \Bitrix\Main\ModuleManager::isModuleInstalled('bitrix24'), 'FOLDER' => array('ID' => $this->folder->getId(), 'NAME' => $this->folder->getName(), 'IS_DELETED' => $this->folder->isDeleted(), 'CREATE_TIME' => $this->folder->getCreateTime(), 'UPDATE_TIME' => $this->folder->getUpdateTime()), 'STORAGE' => array('NETWORK_DRIVE_LINK' => Driver::getInstance()->getUrlManager()->getHostUrl() . $proxyType->getBaseUrlFolderList(), 'ID' => $this->storage->getId(), 'NAME' => $proxyType->getEntityTitle(), 'LINK' => $proxyType->getStorageBaseUrl(), 'LINK_ON_HELP' => $proxyType->getStorageBaseUrl() . 'help', 'ROOT_OBJECT_ID' => $this->storage->getRootObjectId(), 'CAN_CHANGE_RIGHTS_ON_STORAGE' => $this->storage->canChangeRights($securityContext), 'CAN_CHANGE_SETTINGS_ON_STORAGE' => $this->storage->canChangeSettings($securityContext), 'CAN_CHANGE_SETTINGS_ON_BIZPROC' => $this->storage->canCreateWorkflow($securityContext), 'CAN_CHANGE_SETTINGS_ON_BIZPROC_EXCEPT_USER' => $proxyType instanceof ProxyType\User ? false : true, 'SHOW_BIZPROC' => $this->arParams['STATUS_BIZPROC'], 'FOR_SOCNET_GROUP' => $isGroupStorage, 'CONNECTED_SOCNET_GROUP' => $isConnectedGroupStorage, 'CONNECTED_SOCNET_GROUP_OBJECT_ID' => isset($groupSharingData['LINK_OBJECT_ID']) ? $groupSharingData['LINK_OBJECT_ID'] : null), 'BREADCRUMBS' => $this->getBreadcrumbs(), 'BREADCRUMBS_ROOT' => array('NAME' => $proxyType->getTitleForCurrentUser(), 'LINK' => $proxyType->getBaseUrlFolderList(), 'ID' => $this->storage->getRootObjectId()), 'URL_TO_DETACH_OBJECT' => '?action=detachConnectedObject'); if ($this->arParams['STATUS_BIZPROC']) { $this->getAutoloadTemplateBizProc($documentData); } $this->includeComponentTemplate(); }
private function loadFormattedFolderTreeAndBreadcrumbs($returnTree = false) { $cache = Data\Cache::createInstance(); if ($cache->initCache(15768000, 'storage_tr_' . $this->storage->getId(), 'disk')) { list($formattedFolders, $this->cacheBreadcrumbs) = $cache->getVars(); } else { $querySharedFolders = \Bitrix\Disk\Sharing::getList(array('filter' => array('FROM_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId(), '!TO_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId()))); $sharedFolders = array(); while ($sharedFolder = $querySharedFolders->fetch()) { $sharedFolders[$sharedFolder['REAL_OBJECT_ID']] = $sharedFolder['REAL_OBJECT_ID']; } $formattedFolders = array(); foreach ($this->walkAndBuildTree($this->storage->getRootObject()) as $folder) { /** @var Folder $folder */ $formattedFolders[] = $this->formatFolderToResponse($folder, isset($sharedFolders[$folder->getId()])); } unset($folder); $cache->startDataCache(); $cache->endDataCache(array($formattedFolders, $this->cacheBreadcrumbs)); } return $returnTree ? $formattedFolders : null; }
/** * Deletes folder and all descendants objects. * @param int $deletedBy Id of user (or SystemUser::SYSTEM_USER_ID). * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentNullException * @return bool */ public function deleteTree($deletedBy) { /** @var Sharing $sharing */ $sharing = Sharing::load(array('LINK_OBJECT_ID' => $this->getId())); if ($sharing) { $sharing->decline($deletedBy, false); } return parent::deleteNonRecursive($deletedBy); }
public static function onSocNetFeaturesUpdate($id, $fields) { static $updateGroupFilesFeatures = false; if (!$updateGroupFilesFeatures && isset($fields['ACTIVE']) && $fields['ACTIVE'] == 'N') { /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $features = \CSocNetFeatures::getById($id); if ($features && isset($features['FEATURE']) && $features['FEATURE'] == 'files' && $features['ENTITY_TYPE'] == 'G' && $features['ENTITY_ID']) { $updateGroupFilesFeatures = true; $groupId = $features['ENTITY_ID']; if (empty($groupId)) { return; } $storage = Driver::getInstance()->getStorageByGroupId($groupId); if (!$storage) { return; } $userId = self::getActivityUserId(); foreach (Sharing::getModelList(array('filter' => array('REAL_OBJECT_ID' => (int) $storage->getRootObjectId(), 'REAL_STORAGE_ID' => (int) $storage->getId()))) as $sharing) { $sharing->delete($userId); } unset($sharing); } } elseif (isset($fields['ACTIVE']) && $fields['ACTIVE'] == 'Y') { /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $features = \CSocNetFeatures::getById($id); if ($features && isset($features['FEATURE']) && $features['FEATURE'] == 'files' && $features['ENTITY_TYPE'] == 'G' && $features['ENTITY_ID']) { $groupId = $features['ENTITY_ID']; if (!empty($groupId)) { Driver::getInstance()->addGroupStorage($groupId); } } } }
protected function processActionConnectToUserStorage() { $this->checkRequiredPostParams(array('objectId')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } /** @var \Bitrix\Disk\File|\Bitrix\Disk\Folder $object */ $object = BaseObject::loadById((int) $this->request->getPost('objectId'), array('STORAGE')); if (!$object) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FOLDER_LIST_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT))); $this->sendJsonErrorResponse(); } $storage = $object->getStorage(); $securityContext = $storage->getCurrentUserSecurityContext(); if (!$object->canRead($securityContext)) { $this->sendJsonAccessDeniedResponse(); } if ($storage->getRootObjectId() == $object->getId()) { $sharingModel = Sharing::connectGroupToSelfUserStorage($this->getUser()->getId(), $storage, $this->errorCollection); if ($sharingModel) { $this->sendJsonSuccessResponse(array('objectName' => $object->getName(), 'manage' => array('link' => array('object' => array('id' => $sharingModel->getLinkObjectId()))), 'message' => Loc::getMessage('DISK_FOLDER_LIST_MESSAGE_CONNECT_GROUP_DISK'))); } } else { $sharingModel = Sharing::connectObjectToSelfUserStorage($this->getUser()->getId(), $object, $this->errorCollection); } if ($sharingModel === null) { $this->sendJsonErrorResponse(); } $this->sendJsonSuccessResponse(array('objectName' => $object->getName())); }
/** * Returns list users who have sharing on this object. * @return array * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\LoaderException */ public function getMembersOfSharing() { $sharings = $this->getRealObject()->getSharingsAsReal(); $members = array(); $membersToSharing = array(); foreach ($sharings as $sharing) { if ($sharing->isToDepartmentChild()) { continue; } list($type, $id) = Sharing::parseEntityValue($sharing->getToEntity()); $members[$type][] = $id; $membersToSharing[$type . '|' . $id] = $sharing; } unset($sharing); $enabledSocialnetwork = Loader::includeModule('socialnetwork'); $entityList = array(); foreach (SharingTable::getListOfTypeValues() as $type) { if (empty($members[$type])) { continue; } if ($type == SharingTable::TYPE_TO_USER) { $query = \Bitrix\Main\UserTable::getList(array('select' => array('ID', 'PERSONAL_PHOTO', 'NAME', 'LOGIN', 'LAST_NAME', 'SECOND_NAME'), 'filter' => array('ID' => array_values($members[$type])))); while ($userRow = $query->fetch()) { /** @var Sharing $sharing */ $sharing = $membersToSharing[$type . '|' . $userRow['ID']]; $entityList[] = array('entityId' => Sharing::CODE_USER . $userRow['ID'], 'name' => \CUser::formatName('#NAME# #LAST_NAME#', array("NAME" => $userRow['NAME'], "LAST_NAME" => $userRow['LAST_NAME'], "SECOND_NAME" => $userRow['SECOND_NAME'], "LOGIN" => $userRow['LOGIN']), false), 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getPerson($userRow['PERSONAL_PHOTO']), 'type' => 'users'); } } elseif ($type == SharingTable::TYPE_TO_GROUP && $enabledSocialnetwork) { $query = \CSocNetGroup::getList(array(), array('ID' => array_values($members[$type])), false, false, array('ID', 'IMAGE_ID', 'NAME')); while ($query && ($groupRow = $query->fetch())) { /** @var Sharing $sharing */ $sharing = $membersToSharing[$type . '|' . $groupRow['ID']]; $entityList[] = array('entityId' => Sharing::CODE_SOCNET_GROUP . $groupRow['ID'], 'name' => $groupRow['NAME'], 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getGroup($groupRow['IMAGE_ID']), 'type' => 'groups'); } } elseif ($type == SharingTable::TYPE_TO_DEPARTMENT && $enabledSocialnetwork) { // intranet structure $structure = \CSocNetLogDestination::getStucture(); foreach (array_values($members[$type]) as $departmentId) { if (empty($structure['department']['DR' . $departmentId])) { continue; } /** @var Sharing $sharing */ $sharing = $membersToSharing[$type . '|' . $departmentId]; $entityList[] = array('entityId' => Sharing::CODE_DEPARTMENT . $departmentId, 'name' => $structure['department']['DR' . $departmentId]['name'], 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getDefaultGroup(), 'type' => 'department'); } unset($departmentId); } } unset($type); return $entityList; }