Esempio n. 1
0
 /**
  * @return User
  */
 public function getUser()
 {
     if ($this->userId === null) {
         return null;
     }
     if (SystemUser::isSystemUserId($this->userId)) {
         return SystemUser::create();
     }
     if (isset($this->user) && $this->userId == $this->user->getId()) {
         return $this->user;
     }
     $this->user = User::loadById($this->userId);
     return $this->user;
 }
 public static function onAfterUserUpdate($fields)
 {
     if (!Loader::includeModule('socialnetwork') || empty($fields['ID'])) {
         return;
     }
     if (!empty($fields['NAME']) || !empty($fields['LAST_NAME']) || !empty($fields['SECOND_NAME'])) {
         $user = User::loadById($fields['ID']);
         if (!$user || $user->isEmptyName()) {
             return;
         }
         $userStorage = Driver::getInstance()->getStorageByUserId($user->getId());
         if (!$userStorage) {
             return;
         }
         $userStorage->rename($user->getFormattedName());
     }
 }
Esempio n. 3
0
 /**
  * @param      $declinedBy
  * @param bool $withDeletingObject
  * @return bool
  */
 public function decline($declinedBy, $withDeletingObject = true)
 {
     $this->errorCollection->clear();
     if ($this->isDeclined()) {
         return true;
     }
     if ($withDeletingObject && ($this->isToUser() || $this->isToGroup() || $this->isToDepartmentChild())) {
         $linkModel = $this->getLinkObject();
         if ($linkModel instanceof FolderLink) {
             $linkModel->deleteTree($declinedBy);
         } elseif ($linkModel instanceof FileLink) {
             $linkModel->deleteWithoutSharing($declinedBy);
         }
     }
     $success = $this->update(array('LINK_OBJECT_ID' => null, 'LINK_STORAGE_ID' => null, 'STATUS' => SharingTable::STATUS_IS_DECLINED));
     if (!$success) {
         return false;
     }
     foreach ($this->getChildren() as $childSharing) {
         $childSharing->decline($declinedBy, $withDeletingObject);
     }
     unset($childSharing);
     if (!$this->getRealObject()) {
         return true;
     }
     if ($this->isToUser() || $this->isToGroup() || $this->isToDepartmentParent()) {
         $rightsManager = Driver::getInstance()->getRightsManager();
         $rightsManager->deleteByDomain($this->getRealObject(), $rightsManager->getSharingDomain($this->id));
     }
     if ($this->isToUser() && !$this->isToDepartmentChild() && self::CODE_USER . $declinedBy == $this->toEntity && $this->fromEntity != $this->toEntity) {
         $isFolder = $this->getRealObject() instanceof Folder;
         $message = Loc::getMessage($isFolder ? 'DISK_SHARING_MODEL_TEXT_SELF_DISCONNECT' : 'DISK_SHARING_MODEL_TEXT_SELF_DISCONNECT_FILE', array('#NAME#' => $this->getRealObject()->getName(), '#USERNAME#' => User::loadById($declinedBy)->getFormattedName()));
         list($subTag, $tag) = $this->getNotifyTags();
         Driver::getInstance()->sendNotify($this->createdBy, array('FROM_USER_ID' => $declinedBy, 'NOTIFY_EVENT' => 'sharing', 'NOTIFY_TAG' => $tag, 'NOTIFY_MESSAGE' => $message, 'NOTIFY_MESSAGE_OUT' => strip_tags($message)));
     }
     return true;
 }
 /**
  * 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($userId);
     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');
     }
     $this->attachedModel->getConnector()->addComment($userId, array('text' => $text, 'fileId' => $valueFileUf));
     $this->sendJsonSuccessResponse();
 }
Esempio n. 5
0
 /**
  * @return \Bitrix\Disk\User|null
  */
 private function getUser()
 {
     if ($this->user !== null) {
         return $this->user;
     }
     $this->user = UserModel::loadById($this->entityId);
     if (!$this->user) {
         $this->user = SystemUser::create();
     }
     return $this->user;
 }
Esempio n. 6
0
 protected function processActionInitialize()
 {
     $this->enableIgnoreQuotaError();
     $userStorageId = $this->getUserStorageId();
     $storage = $this->getStorageObject();
     $storage->setStorageId($userStorageId);
     $userModel = User::loadById($this->getUser()->getId());
     $storageModel = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
     $isExtranetUser = $userModel->isExtranetUser();
     $this->sendJsonSuccessResponse(array('userId' => (string) $this->getUser()->getID(), 'userStorageId' => $storage->getStringStorageId(), 'pathToUserLib' => $this->getPathToUserLib($userModel, $storageModel), 'pathToDiscuss' => $this->getPathToDiscuss($userModel), 'userStorageExtra' => array('iblockId' => (string) $userStorageId['IBLOCK_ID'], 'sectionId' => (string) $userStorageId['IBLOCK_SECTION_ID']), 'isB24' => (bool) isModuleInstalled('bitrix24'), 'isExtranetUser' => (bool) $isExtranetUser, 'version' => self::VERSION, 'token_sid' => bitrix_sessid(), 'defaultChunkSize' => Bitrix24Disk\UploadFileManager::DEFAULT_CHUNK_SIZE));
 }
Esempio n. 7
0
 /**
  * Creates storage for user and sets default rights.
  * If storage already exists returns its.
  *
  * @param integer $userId Id of user.
  * @return Storage|null
  * @throws ArgumentException
  * @throws SystemException
  * @throws \Bitrix\Main\LoaderException
  */
 public function addUserStorage($userId)
 {
     if (!Loader::includeModule('socialnetwork')) {
         throw new SystemException('Could not create user storage without module "socialnetwork"');
     }
     $userId = (int) $userId;
     $data = array('NAME' => "user {$userId}");
     /** @var User $userModel */
     $userModel = User::loadById($userId);
     if ($userModel && !$userModel->isEmptyName()) {
         $data['NAME'] = $userModel->getFormattedName();
     }
     $data['USE_INTERNAL_RIGHTS'] = 1;
     $data['MODULE_ID'] = self::INTERNAL_MODULE_ID;
     $data['ENTITY_TYPE'] = ProxyType\User::className();
     $data['ENTITY_ID'] = $userId;
     $rightsManager = $this->getRightsManager();
     $fullAccessTaskId = $rightsManager->getTaskIdByName($rightsManager::TASK_FULL);
     if ($userModel && $userModel->isIntranetUser()) {
         $rights = array(array('ACCESS_CODE' => 'IU' . $userId, 'TASK_ID' => $fullAccessTaskId));
     } else {
         //for extranet user we don't have IU.
         $rights = array(array('ACCESS_CODE' => 'U' . $userId, 'TASK_ID' => $fullAccessTaskId));
     }
     return self::addStorageIfNotExist($data, $rights);
 }
Esempio n. 8
0
 /**
  * @internal
  * @param      $userId
  * @param User $currentFieldValue
  * @return User|EmptyUser|SystemUser
  */
 public static function getModelForReferenceField($userId, User $currentFieldValue = null)
 {
     if ($userId === null) {
         return EmptyUser::create();
     }
     if (SystemUser::isSystemUserId($userId)) {
         return SystemUser::create();
     }
     if (isset($currentFieldValue) && $userId == $currentFieldValue->getId()) {
         return $currentFieldValue;
     }
     $user = User::loadById($userId);
     if (!$user) {
         return EmptyUser::create();
     }
     return $user;
 }
Esempio n. 9
0
 /**
  * @return User
  */
 public function getUser()
 {
     if (!$this->userId) {
         return null;
     }
     if (isset($this->user) && $this->userId == $this->user->getId()) {
         return $this->user;
     }
     $this->user = User::loadById($this->userId);
     return $this->user;
 }
Esempio n. 10
0
 /**
  * Adds new version to file.
  *
  * The method may joins version with last version.
  *
  * @param array $file Structure like $_FILES.
  * @param int $createdBy Id of user.
  * @param bool $disableJoin If set false the method attempts to join version with last version (@see \Bitrix\Disk\File::SECONDS_TO_JOIN_VERSION).
  * @return Version|null
  * @throws \Bitrix\Main\SystemException
  */
 public function addVersion(array $file, $createdBy, $disableJoin = false)
 {
     $this->errorCollection->clear();
     $now = new DateTime();
     $needToJoin = false;
     if (!$disableJoin && $this->updateTime && $this->updatedBy == $createdBy) {
         $updateTimestamp = $this->updateTime->getTimestamp();
         if ($now->getTimestamp() - $updateTimestamp < self::SECONDS_TO_JOIN_VERSION) {
             $needToJoin = true;
         }
     }
     if (!$this->updateContent($file, $createdBy)) {
         return null;
     }
     if ($needToJoin) {
         $lastVersion = $this->getLastVersion();
         if ($lastVersion) {
             if (!$lastVersion->joinData(array_merge(array('CREATE_TIME' => $now), $this->getHistoricalData()))) {
                 $this->errorCollection->add($lastVersion->getErrors());
                 return null;
             }
             if ($this->prevFileId && $this->prevFileId != $this->fileId) {
                 CFile::delete($this->prevFileId);
             }
             return $lastVersion;
         }
     }
     $versionModel = Version::add(array_merge(array('OBJECT_ID' => $this->id, 'FILE_ID' => $this->fileId, 'NAME' => $this->name, 'CREATED_BY' => $createdBy), $this->getHistoricalData()), $this->errorCollection);
     if (!$versionModel) {
         return null;
     }
     $valueVersionUf = FileUserType::NEW_FILE_PREFIX . $versionModel->getId();
     /** @var User $createUser */
     $createUser = User::loadById($createdBy);
     if (!$createUser) {
         //skip
         return $versionModel;
     }
     $text = Loc::getMessage('DISK_FILE_MODEL_UPLOAD_NEW_VERSION_IN_COMMENT_M');
     if ($createUser->getPersonalGender() == 'F') {
         $text = Loc::getMessage('DISK_FILE_MODEL_UPLOAD_NEW_VERSION_IN_COMMENT_F');
     }
     foreach ($this->getAttachedObjects() as $attache) {
         AttachedObject::storeDataByObjectId($this->getId(), array('IS_EDITABLE' => $attache->isEditable(), 'ALLOW_EDIT' => $attache->getAllowEdit()));
         $attache->getConnector()->addComment($createdBy, array('text' => $text, 'versionId' => $valueVersionUf));
         AttachedObject::storeDataByObjectId($this->getId(), null);
     }
     unset($attache);
     return $versionModel;
 }