Example #1
0
 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()));
 }