protected function processActionAddFolder() { if (!$this->checkRequiredPostParams(array('name', 'targetFolderId'))) { $this->sendJsonErrorResponse(); } /** @var Folder $folder */ $folder = Folder::loadById((int) $this->request->getPost('targetFolderId'), array('STORAGE')); if (!$folder) { $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FOLDER_TOOLBAR_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT)); $this->sendJsonErrorResponse(); } $securityContext = $folder->getStorage()->getCurrentUserSecurityContext(); if (!$folder->canAdd($securityContext)) { $this->sendJsonAccessDeniedResponse(); } $name = $this->request->getPost('name'); $subFolderModel = $folder->addSubFolder(array('NAME' => Ui\Text::correctFolderName($name), 'CREATED_BY' => $this->getUser()->getId())); if ($subFolderModel === null) { $this->errorCollection->add($folder->getErrors()); $this->sendJsonErrorResponse(); } $this->sendJsonSuccessResponse(array('folder' => array('id' => $subFolderModel->getId()))); }
public static function connectGroupToSelfUserStorage($userId, Storage $storage, ErrorCollection $errorCollection) { return self::connectToUserStorage($userId, array('SELF_CONNECT' => true, 'CREATED_BY' => $userId, 'LINK_NAME' => Ui\Text::correctFolderName($storage->getProxyType()->getEntityTitle()), 'REAL_OBJECT' => $storage->getRootObject()), $errorCollection); }
public function Execute() { if (!CModule::IncludeModule("disk")) return CBPActivityExecutionStatus::Closed; $groupId = (int)$this->GroupId; $files = $this->Files; $folderName = \Bitrix\Disk\Ui\Text::correctFolderName($this->FolderName); $storage = \Bitrix\Disk\Driver::getInstance()->getStorageByGroupId($groupId); if (!$storage) { $storage = \Bitrix\Disk\Driver::getInstance()->addGroupStorage($groupId); } if (!$storage) { return CBPActivityExecutionStatus::Closed; } $folder = null; if (strlen($folderName) > 0) { $targetFolder = \Bitrix\Disk\Folder::load(array('=NAME' => $folderName, 'STORAGE_ID' => $storage->getId(), 'PARENT_ID' => $storage->getRootObjectId() )); if ($targetFolder) { $folder = $targetFolder; } else { $folder = $storage->addFolder(array( 'NAME' => $folderName, 'CREATED_BY' => \Bitrix\Disk\SystemUser::SYSTEM_USER_ID ), array(), true); } } if (!$folder) { $folder = $storage->getRootObject(); } foreach ($files as $file) { if (!(int)$file) continue; $fileArray = CFile::MakeFileArray($file); if (!is_array($fileArray)) continue; $folder->uploadFile($fileArray, array( 'NAME' => $fileArray['name'], 'CREATED_BY' => \Bitrix\Disk\SystemUser::SYSTEM_USER_ID, ), array(), true ); } return CBPActivityExecutionStatus::Closed; }
/** * Action only for Common docs. * We don't check rights on rootObject for changeRights if user has "update" operation. */ protected function processActionCreateFolderWithSharing() { //todo refactor actions. And move logic in rights manager if needed $this->checkRequiredPostParams(array('storageId', 'name')); 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(); } //todo refactor this code. with action ShowCreateFolderWithSharingInCommon $rightsManager = Driver::getInstance()->getRightsManager(); $securityContext = $storage->getCurrentUserSecurityContext(); if (!$storage->getProxyType() instanceof Bitrix\Disk\ProxyType\Common || !$storage->getRootObject()->canAdd($securityContext)) { $this->sendJsonAccessDeniedResponse(); } $entityToNewShared = $this->request->getPost('entityToNewShared'); $storageNewRights = $this->request->getPost('storageNewRights'); if (!$storageNewRights || !is_array($storageNewRights)) { $storageNewRights = array(); } $newRights = array(); foreach ($rightsManager->getAllListNormalizeRights($storage->getRootObject()) as $rightOnObject) { if (empty($rightOnObject['NEGATIVE']) && !isset($storageNewRights[$rightOnObject['ACCESS_CODE']])) { unset($rightOnObject['ID']); $rightOnObject['NEGATIVE'] = 1; $newRights[] = $rightOnObject; } } unset($rightOnObject); if ($newRights) { $newRights[] = array('ACCESS_CODE' => 'IU' . $this->getUser()->getId(), 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_FULL)); } $name = $this->request->getPost('name'); $newFolder = $storage->addFolder(array('NAME' => Ui\Text::correctFolderName($name), 'CREATED_BY' => $this->getUser()->getId()), $newRights); if ($newFolder === null) { $this->errorCollection->add($storage->getErrors()); $this->sendJsonErrorResponse(); } if (!empty($entityToNewShared) && is_array($entityToNewShared)) { $newExtendedRightsReformat = array(); foreach ($entityToNewShared as $entityId => $right) { switch ($right['right']) { case 'disk_access_read': $newExtendedRightsReformat[$entityId] = \Bitrix\Disk\RightsManager::TASK_READ; break; case 'disk_access_edit': $newExtendedRightsReformat[$entityId] = \Bitrix\Disk\RightsManager::TASK_EDIT; break; case 'disk_access_full': $newExtendedRightsReformat[$entityId] = \Bitrix\Disk\RightsManager::TASK_FULL; break; } } if ($newExtendedRightsReformat) { Sharing::addToManyEntities(array('FROM_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId(), 'REAL_OBJECT' => $newFolder, 'CREATED_BY' => $this->getUser()->getId(), 'CAN_FORWARD' => false), $newExtendedRightsReformat, $this->errorCollection); } unset($right); } $this->sendJsonSuccessResponse(array('folder' => array('id' => $newFolder->getId()))); }