Example #1
0
 /**
  * @param array $inputParams
  * @param array $required
  * @return bool
  */
 protected function checkRequiredInputParams(array $inputParams, array $required)
 {
     foreach ($required as $item) {
         if (!isset($inputParams[$item]) || !$inputParams[$item] && !(is_string($inputParams[$item]) && strlen($inputParams[$item]))) {
             $this->errorCollection->add(array(new Error("Error: required parameter {$item}", self::ERROR_REQUIRED_PARAMETER)));
             return false;
         }
     }
     return true;
 }
Example #2
0
 /**
  * Processes method to services.
  * @param array        $params Input parameters ($_GET, $_POST).
  * @param     string   $start Start position.
  * @param \CRestServer $restServer REST server.
  * @return array
  * @throws RestException
  */
 public function processMethodRequest(array $params, $start, \CRestServer $restServer)
 {
     $service = $this->checkMethodName($restServer->getMethod())->buildService($params, $start, $restServer);
     $data = $service->processMethodRequest();
     if ($data === null) {
         $this->errorCollection->add($service->getErrors());
         $errors = $this->getErrors();
         if ($errors) {
             $error = array_pop($errors);
             throw new RestException($error->getMessage(), $error->getCode());
         }
     }
     $externalizer = new Externalizer($service, $restServer);
     return $externalizer->getExternalData($data);
 }
 public function isReady(DocumentHandler $documentHandler)
 {
     if (!$documentHandler->checkAccessibleTokenService()) {
         $this->errorCollection->add($documentHandler->getErrors());
         return false;
     }
     return $documentHandler->queryAccessToken()->hasAccessToken() && !$documentHandler->isRequiredAuthorization();
 }
Example #4
0
 /**
  * BaseObject is leaf (does not have children)
  * @param \Bitrix\Disk\BaseObject|BaseObject $object
  * @param array                      $rights
  * @throws \Bitrix\Main\SystemException
  * @return bool
  */
 public function setAsNewLeaf(BaseObject $object, array $rights)
 {
     $this->checkUseInternalsRightsOnStorage($object, $rights);
     $this->errorCollection->clear();
     $rights = $this->uniqualizeRightsOnObject($rights);
     if (!$this->validateNegativeRights($object, $rights)) {
         $this->errorCollection->add(array(new Error('Could not set negative right on not exist right (task + access_code)', self::ERROR_COULD_NOT_SET_NEGATIVE_RIGHT)));
         return false;
     }
     if (!$this->insertRightsInternal($object, $rights)) {
         return false;
     }
     $simpleBuilder = new SimpleReBuilder($object, $rights);
     $simpleBuilder->runAsNewLeaf();
     Driver::getInstance()->getIndexManager()->recalculateRights($object);
     return true;
 }
Example #5
0
 /**
  * Checks required parameters.
  * Fills error collection if required parameter is missed.
  * @param array $inputParams Input data.
  * @param array $required Required parameters.
  * @return bool
  */
 protected function checkRequiredInputParams(array $inputParams, array $required)
 {
     foreach ($required as $item) {
         if (!isset($inputParams[$item]) || !$inputParams[$item] && !(is_string($inputParams[$item]) && strlen($inputParams[$item]))) {
             $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_CONTROLLER_ERROR_REQUIRED_PARAMETER', array('#PARAM#' => $item)), self::ERROR_REQUIRED_PARAMETER)));
             return false;
         }
     }
     return true;
 }
Example #6
0
 /**
  * @return bool
  * @throws \Bitrix\Main\NotImplementedException
  */
 protected function deleteInternal()
 {
     $this->errorCollection->clear();
     /** @var DataManager $tableClassName */
     $tableClassName = static::getTableClassName();
     $deleteResult = $tableClassName::delete($this->id);
     if (!$deleteResult->isSuccess()) {
         $this->errorCollection->add(array(new Error('', self::ERROR_INTERNAL_DELETE)));
         return false;
     }
     return true;
 }
Example #7
0
 /**
  * Clones uf values from entity and creates new files (copies from attach) to save in new entity.
  * @param array $attachedIds List of attached objects id.
  * @param int $userId Id of user.
  * @internal
  * @return array
  */
 public function cloneUfValuesFromAttachedObject(array $attachedIds, $userId)
 {
     $this->errorCollection->clear();
     $userId = (int) $userId;
     if ($userId <= 0) {
         $this->errorCollection->addOne(new Error('Invalid $userId'));
         return null;
     }
     $userStorage = Driver::getInstance()->getStorageByUserId($userId);
     if (!$userStorage) {
         $this->errorCollection->addOne(new Error("Could not find storage for user {$userId}"));
         $this->errorCollection->add(Driver::getInstance()->getErrors());
         return null;
     }
     $folder = $userStorage->getFolderForUploadedFiles();
     if (!$folder) {
         $this->errorCollection->addOne(new Error("Could not create/find folder for upload"));
         $this->errorCollection->add($userStorage->getErrors());
         return null;
     }
     $newValues = array();
     foreach ($attachedIds as $id) {
         list($type, $realValue) = FileUserType::detectType($id);
         if (FileUserType::TYPE_ALREADY_ATTACHED != $type) {
             continue;
         }
         $attachedObject = AttachedObject::loadById($realValue, array('OBJECT'));
         if (!$attachedObject) {
             continue;
         }
         if (!$attachedObject->canRead($userId)) {
             continue;
         }
         $file = $attachedObject->getFile();
         if (!$file) {
             continue;
         }
         $newFile = $file->copyTo($folder, $userId, true);
         if (!$newFile) {
             $this->errorCollection->add($file->getErrors());
             continue;
         }
         $newValues[] = FileUserType::NEW_FILE_PREFIX . $newFile->getId();
     }
     return $newValues;
 }
 /**
  * Rollback upload by token. Destroy temporary content.
  * @return bool Status of delete.
  */
 public function rollbackByToken()
 {
     if (!$this->hasToken()) {
         $this->errorCollection->addOne(new Error("Could not delete content file by token. Have to set token parameter.", self::ERROR_EMPTY_TOKEN));
         return false;
     }
     $tmpFile = $this->findUserSpecificTmpFileByToken();
     if (!$tmpFile) {
         $this->errorCollection->addOne(new Error("Could not find file by token", self::ERROR_UNKNOWN_TOKEN));
         return false;
     }
     $success = $tmpFile->delete();
     if (!$success) {
         $this->errorCollection->add($tmpFile->getErrors());
     }
     return $success;
 }
Example #9
0
 /**
  * Connect object $data['REAL_OBJECT'] (or $data['REAL_OBJECT_ID']) to user storage
  * $data['SELF_CONNECT'] - don't ask about connecting object,
  * @param                 $userId
  * @param array           $data
  * @param ErrorCollection $errorCollection
  * @return Sharing|null
  * @throws \Bitrix\Main\NotImplementedException
  * @throws \Bitrix\Main\SystemException
  */
 public static function connectToUserStorage($userId, array $data, ErrorCollection $errorCollection)
 {
     $storage = Driver::getInstance()->getStorageByUserId($userId);
     if (!$storage) {
         $storage = Driver::getInstance()->addUserStorage($userId);
     }
     if (!$storage) {
         $errorCollection->add(array(new Error(Loc::getMessage('DISK_SHARING_MODEL_ERROR_COULD_NOT_FIND_USER_STORAGE', array('#USER_ID#' => $userId)), self::ERROR_COULD_NOT_FIND_USER_STORAGE)));
         return null;
     }
     $selfConnect = !empty($data['SELF_CONNECT']);
     $linkName = !empty($data['LINK_NAME']) ? $data['LINK_NAME'] : null;
     unset($data['SELF_CONNECT'], $data['LINK_NAME']);
     $data['TYPE'] = SharingTable::TYPE_TO_USER;
     $data['FROM_ENTITY'] = self::CODE_USER . (int) $userId;
     $data['TO_ENTITY'] = self::CODE_USER . (int) $userId;
     $data['TASK_NAME'] = RightsManager::TASK_READ;
     if (isset($data['REAL_OBJECT']) && $data['REAL_OBJECT'] instanceof BaseObject) {
         /** @noinspection PhpUndefinedMethodInspection */
         $data['REAL_OBJECT_ID'] = $data['REAL_OBJECT']->getId();
     } elseif (isset($data['REAL_OBJECT_ID'])) {
         $data['REAL_OBJECT'] = BaseObject::loadById($data['REAL_OBJECT_ID']);
     } else {
         $errorCollection->add(array(new Error(Loc::getMessage('DISK_SHARING_MODEL_ERROR_EMPTY_REAL_OBJECT'), self::ERROR_EMPTY_REAL_OBJECT)));
         return null;
     }
     /** @var \Bitrix\Disk\BaseObject $objectToSharing */
     $objectToSharing = $data['REAL_OBJECT'];
     //resolve to last real object. In table we write only real (not link) id.
     $objectToSharing = $objectToSharing->getRealObject();
     $data['REAL_OBJECT_ID'] = $objectToSharing->getId();
     $data['REAL_STORAGE_ID'] = $objectToSharing->getStorageId();
     $dataToInsert = $data;
     unset($dataToInsert['REAL_OBJECT']);
     $sharingModel = parent::add($dataToInsert, $errorCollection);
     if (!$sharingModel) {
         return null;
     }
     $sharingModel->setAttributes(array('REAL_OBJECT' => $objectToSharing));
     if (!$selfConnect) {
         self::processConnectAndNotify(array($sharingModel), $objectToSharing);
     } else {
         if (!$sharingModel->approve(array('LINK_NAME' => $linkName))) {
             $errorCollection->add($sharingModel->getErrors());
             $sharingModel->delete($userId);
             return null;
         }
     }
     return $sharingModel;
 }
Example #10
0
 function processActionHandleFile($hash, &$file, &$package, &$upload, &$error)
 {
     $errorCollection = new ErrorCollection();
     $storage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
     if (!$storage) {
         $errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_FIND_USER_STORAGE'), self::ERROR_COULD_NOT_FIND_USER_STORAGE)));
         $error = implode(" ", $errorCollection->toArray());
         return false;
     }
     $folder = $storage->getFolderForUploadedFiles();
     if (!$folder) {
         $errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_FIND_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER)));
         $error = implode(" ", $errorCollection->toArray());
         return false;
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     if ($folder->canAdd($storage->getCurrentUserSecurityContext())) {
         $fileModel = $folder->uploadFile($file["files"]["default"], array('NAME' => $file['name'], 'CREATED_BY' => $this->getUser()->getId()), array(), true);
         if ($fileModel) {
             $name = $fileModel->getName();
             $id = FileUserType::NEW_FILE_PREFIX . $fileModel->getId();
             $file = array_merge($file, array('id' => $id, 'originalId' => $fileModel->getId(), 'name' => $name, 'label' => getFileNameWithoutExtension($name), 'ext' => $fileModel->getExtension(), 'size' => \CFile::formatSize($fileModel->getSize()), 'sizeInt' => $fileModel->getSize(), 'storage' => $storage->getProxyType()->getTitleForCurrentUser() . ' / ' . $folder->getName(), 'deleteUrl' => $urlManager->getUrlUfController('deleteFile', array('attachedId' => $id)), 'canChangeName' => true), TypeFile::isImage($name) ? array('previewUrl' => $urlManager->getUrlForShowFile($fileModel, array("width" => self::$previewParams["width"], "height" => self::$previewParams["height"]))) : array());
         } else {
             $error = is_array($folder->getErrors()) ? implode(" ", $folder->getErrors()) : 'The file has not been saved';
         }
     }
     return empty($error);
 }