Esempio n. 1
0
 protected function checkUpdatePermissions()
 {
     if (!$this->attachedModel->canUpdate($this->getUser()->getId())) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_DOCUMENT_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
         $this->sendJsonErrorResponse();
     }
 }
 /**
  * For UF and work with local editors we have special scenario:
  * If user don't have permission for update file,
  * we have to attach new file to entity by posting comment with
  * alternative version.
  */
 protected function processActionCommit()
 {
     $userId = $this->getUser()->getId();
     if ($this->attachedModel->canUpdate($userId)) {
         parent::processActionCommit();
         return;
     }
     $this->checkRequiredFilesParams(array('file'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $userStorage = Driver::getInstance()->getStorageByUserId($userId);
     if (!$userStorage) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE)));
         $this->sendJsonErrorResponse();
     }
     $folder = $userStorage->getFolderForCreatedFiles();
     if (!$folder) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES'), self::ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES)));
         $this->sendJsonErrorResponse();
     }
     if (!$folder->canAdd($folder->getStorage()->getCurrentUserSecurityContext())) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
         $this->sendJsonErrorResponse();
     }
     //todo fix Cherezov. Ban encoding 1251
     $fileArray = $this->request->getFile('file');
     $fileArray['name'] = $this->file->getName();
     $newFile = $folder->uploadFile($fileArray, array('NAME' => $this->file->getName(), 'CREATED_BY' => $userId), array(), true);
     if (!$newFile) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE)));
         $this->errorCollection->add($folder->getErrors());
         $this->sendJsonErrorResponse();
     }
     $valueFileUf = FileUserType::NEW_FILE_PREFIX . $newFile->getId();
     /** @var User $createUser */
     $createUser = User::loadById($userId);
     if (!$createUser) {
         $this->sendJsonErrorResponse();
     }
     $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_M');
     if ($createUser->getPersonalGender() == 'F') {
         $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_F');
     }
     if ($this->attachedModel->getAllowAutoComment()) {
         $this->attachedModel->getConnector()->addComment($userId, array('text' => $text, 'fileId' => $valueFileUf));
     }
     $this->sendJsonSuccessResponse();
 }