Beispiel #1
0
 private function getUserShareObjectIds()
 {
     $sharedObjectIds = array();
     foreach (SharingTable::getList(array('select' => array('REAL_OBJECT_ID', 'TO_ENTITY', 'FROM_ENTITY'), 'filter' => array(array('LOGIC' => 'OR', '=TO_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId(), '=FROM_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId()), '!=STATUS' => SharingTable::STATUS_IS_DECLINED, 'REAL_STORAGE_ID' => $this->folder->getStorageId())))->fetchAll() as $row) {
         $sharedObjectIds[$row['REAL_OBJECT_ID']] = $row;
     }
     unset($row);
     return $sharedObjectIds;
 }
Beispiel #2
0
 public function changeTaskName($newTaskName)
 {
     if ($this->taskName == $newTaskName) {
         return true;
     }
     $success = $this->update(array('TASK_NAME' => $newTaskName));
     if (!$success) {
         return false;
     }
     if ($this->isToDepartmentParent()) {
         SharingTable::updateBatch(array('TASK_NAME' => $newTaskName), array('PARENT_ID' => $this->id));
         if ($this->isLoadedChildren()) {
             foreach ($this->getChildren() as $child) {
                 $child->setAttributes(array('TASK_NAME' => $newTaskName));
             }
             unset($child);
         }
     }
     return true;
 }
Beispiel #3
0
 protected function deleteNonRecursive($deletedBy)
 {
     foreach ($this->getSharingsAsReal() as $sharing) {
         $sharing->delete($deletedBy);
     }
     //with status unreplied, declined (not approved)
     $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id));
     $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     DeletedLog::addFolder($this, $deletedBy, $this->errorCollection);
     $resultDelete = FolderTable::delete($this->id);
     if (!$resultDelete->isSuccess()) {
         return false;
     }
     if (!$this->isLink()) {
         //todo potential - very hard operation.
         foreach (Folder::getModelList(array('filter' => array('REAL_OBJECT_ID' => $this->id, '!=REAL_OBJECT_ID' => $this->id))) as $link) {
             $link->deleteTree($deletedBy);
         }
         unset($link);
     }
     $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFolder", array($this->getId(), $deletedBy));
     $event->send();
     return true;
 }
Beispiel #4
0
 protected function processActionChangeSharingAndRights()
 {
     $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();
     }
     $securityContext = $object->getStorage()->getCurrentUserSecurityContext();
     if (!$object->canChangeRights($securityContext)) {
         $this->sendJsonAccessDeniedResponse();
     }
     $entityToNewShared = $this->request->getPost('entityToNewShared');
     if (!empty($entityToNewShared) && is_array($entityToNewShared)) {
         $extendedRights = $entityToNewShared;
         $newExtendedRightsReformat = array();
         foreach ($extendedRights 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;
             }
         }
         //todo move this code to Object or Sharing model (reset sharing)
         $query = Sharing::getList(array('filter' => array('REAL_OBJECT_ID' => $object->getRealObjectId(), 'REAL_STORAGE_ID' => $object->getRealObject()->getStorageId(), '!=STATUS' => SharingTable::STATUS_IS_DECLINED, 'PARENT_ID' => null)));
         $needToOverwrite = $needToDelete = $needToAdd = array();
         while ($sharingRow = $query->fetch()) {
             if (isset($newExtendedRightsReformat[$sharingRow['TO_ENTITY']])) {
                 if ($newExtendedRightsReformat[$sharingRow['TO_ENTITY']] != $sharingRow['TASK_NAME']) {
                     $needToOverwrite[$sharingRow['TO_ENTITY']] = $sharingRow;
                 } elseif ($newExtendedRightsReformat[$sharingRow['TO_ENTITY']] == $sharingRow['TASK_NAME']) {
                     unset($newExtendedRightsReformat[$sharingRow['TO_ENTITY']]);
                 }
             } else {
                 $needToDelete[$sharingRow['TO_ENTITY']] = $sharingRow;
             }
         }
         unset($sharingRow);
         $needToAdd = array_diff_key($newExtendedRightsReformat, $needToOverwrite);
         if ($needToAdd) {
             Sharing::addToManyEntities(array('FROM_ENTITY' => Sharing::CODE_USER . $this->getUser()->getId(), 'REAL_OBJECT' => $object, 'CREATED_BY' => $this->getUser()->getId(), 'CAN_FORWARD' => false), $needToAdd, $this->errorCollection);
         }
         if ($needToOverwrite) {
             $rightsManager = Driver::getInstance()->getRightsManager();
             foreach ($needToOverwrite as $sharingRow) {
                 $rightsManager->deleteByDomain($object->getRealObject(), $rightsManager->getSharingDomain($sharingRow['ID']));
             }
             unset($sharingRow);
             $newRights = array();
             foreach ($needToOverwrite as $sharingRow) {
                 $sharingDomain = $rightsManager->getSharingDomain($sharingRow['ID']);
                 $newRights[] = array('ACCESS_CODE' => $sharingRow['TO_ENTITY'], 'TASK_ID' => $rightsManager->getTaskIdByName($newExtendedRightsReformat[$sharingRow['TO_ENTITY']]), 'DOMAIN' => $sharingDomain);
                 //todo refactor. Move most logic to Sharing and SharingTable!
                 if ($sharingRow['TYPE'] == SharingTable::TYPE_TO_DEPARTMENT) {
                     /** @var \Bitrix\Disk\Sharing $sharingModel */
                     $sharingModel = Sharing::buildFromArray($sharingRow);
                     $sharingModel->changeTaskName($newExtendedRightsReformat[$sharingRow['TO_ENTITY']]);
                 } else {
                     SharingTable::update($sharingRow['ID'], array('TASK_NAME' => $newExtendedRightsReformat[$sharingRow['TO_ENTITY']]));
                 }
             }
             unset($sharingRow);
             if ($newRights) {
                 $rightsManager->append($object->getRealObject(), $newRights);
             }
         }
         if ($needToDelete) {
             $ids = array();
             foreach ($needToDelete as $sharingRow) {
                 $ids[] = $sharingRow['ID'];
             }
             unset($sharingRow);
             foreach (Sharing::getModelList(array('filter' => array('ID' => $ids))) as $sharing) {
                 $sharing->delete($this->getUser()->getId());
             }
             unset($sharing);
         }
         unset($right);
         $this->sendJsonSuccessResponse();
     } else {
         //user delete all sharing
         $userId = $this->getUser()->getId();
         foreach ($object->getRealObject()->getSharingsAsReal() as $sharing) {
             $sharing->delete($userId);
         }
         unset($sharing);
         $this->sendJsonSuccessResponse();
     }
 }
Beispiel #5
0
 /**
  * Deletes file and all connected data and entities (@see Sharing, @see Rights, etc).
  * @param int $deletedBy Id of user.
  * @return bool
  * @throws \Bitrix\Main\ArgumentNullException
  */
 public function delete($deletedBy)
 {
     $this->errorCollection->clear();
     $success = EditSessionTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     $success = ExternalLinkTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     foreach ($this->getSharingsAsReal() as $sharing) {
         $sharing->delete($deletedBy);
     }
     //with status unreplied, declined (not approved)
     $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     foreach ($this->getAttachedObjects() as $attached) {
         $attached->delete();
     }
     unset($attached);
     BizProcDocument::deleteWorkflowsFile($this->id);
     SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id));
     $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     $success = VersionTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     DeletedLog::addFile($this, $deletedBy, $this->errorCollection);
     \CFile::delete($this->fileId);
     $deleteResult = FileTable::delete($this->id);
     if (!$deleteResult->isSuccess()) {
         return false;
     }
     Driver::getInstance()->getIndexManager()->dropIndex($this);
     if (!$this->isLink()) {
         //todo potential - very hard operation.
         foreach (File::getModelList(array('filter' => array('REAL_OBJECT_ID' => $this->id, '!=REAL_OBJECT_ID' => $this->id))) as $link) {
             $link->delete($deletedBy);
         }
         unset($link);
     }
     $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFile", array($this->getId(), $deletedBy));
     $event->send();
     return true;
 }
Beispiel #6
0
 protected function deleteProcess($deletedBy, $withDeletingSharing = true)
 {
     $this->errorCollection->clear();
     $success = EditSessionTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     $success = ExternalLinkTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if ($withDeletingSharing) {
         foreach ($this->getSharingsAsLink() as $sharing) {
             $sharing->delete($deletedBy, false);
         }
         //with status unreplied, declined (not approved)
         $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id));
     }
     if (!$success) {
         return false;
     }
     SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id));
     $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     DeletedLog::addFile($this, $deletedBy, $this->errorCollection);
     $resultDelete = FileTable::delete($this->id);
     if (!$resultDelete->isSuccess()) {
         return false;
     }
     $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFile", array($this->getId(), $deletedBy));
     $event->send();
     return true;
 }
Beispiel #7
0
 /**
  * Returns list users who have sharing on this object.
  * @return array
  * @throws \Bitrix\Main\ArgumentException
  * @throws \Bitrix\Main\LoaderException
  */
 public function getMembersOfSharing()
 {
     $sharings = $this->getRealObject()->getSharingsAsReal();
     $members = array();
     $membersToSharing = array();
     foreach ($sharings as $sharing) {
         if ($sharing->isToDepartmentChild()) {
             continue;
         }
         list($type, $id) = Sharing::parseEntityValue($sharing->getToEntity());
         $members[$type][] = $id;
         $membersToSharing[$type . '|' . $id] = $sharing;
     }
     unset($sharing);
     $enabledSocialnetwork = Loader::includeModule('socialnetwork');
     $entityList = array();
     foreach (SharingTable::getListOfTypeValues() as $type) {
         if (empty($members[$type])) {
             continue;
         }
         if ($type == SharingTable::TYPE_TO_USER) {
             $query = \Bitrix\Main\UserTable::getList(array('select' => array('ID', 'PERSONAL_PHOTO', 'NAME', 'LOGIN', 'LAST_NAME', 'SECOND_NAME'), 'filter' => array('ID' => array_values($members[$type]))));
             while ($userRow = $query->fetch()) {
                 /** @var Sharing $sharing */
                 $sharing = $membersToSharing[$type . '|' . $userRow['ID']];
                 $entityList[] = array('entityId' => Sharing::CODE_USER . $userRow['ID'], 'name' => \CUser::formatName('#NAME# #LAST_NAME#', array("NAME" => $userRow['NAME'], "LAST_NAME" => $userRow['LAST_NAME'], "SECOND_NAME" => $userRow['SECOND_NAME'], "LOGIN" => $userRow['LOGIN']), false), 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getPerson($userRow['PERSONAL_PHOTO']), 'type' => 'users');
             }
         } elseif ($type == SharingTable::TYPE_TO_GROUP && $enabledSocialnetwork) {
             $query = \CSocNetGroup::getList(array(), array('ID' => array_values($members[$type])), false, false, array('ID', 'IMAGE_ID', 'NAME'));
             while ($query && ($groupRow = $query->fetch())) {
                 /** @var Sharing $sharing */
                 $sharing = $membersToSharing[$type . '|' . $groupRow['ID']];
                 $entityList[] = array('entityId' => Sharing::CODE_SOCNET_GROUP . $groupRow['ID'], 'name' => $groupRow['NAME'], 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getGroup($groupRow['IMAGE_ID']), 'type' => 'groups');
             }
         } elseif ($type == SharingTable::TYPE_TO_DEPARTMENT && $enabledSocialnetwork) {
             // intranet structure
             $structure = \CSocNetLogDestination::getStucture();
             foreach (array_values($members[$type]) as $departmentId) {
                 if (empty($structure['department']['DR' . $departmentId])) {
                     continue;
                 }
                 /** @var Sharing $sharing */
                 $sharing = $membersToSharing[$type . '|' . $departmentId];
                 $entityList[] = array('entityId' => Sharing::CODE_DEPARTMENT . $departmentId, 'name' => $structure['department']['DR' . $departmentId]['name'], 'right' => $sharing->getTaskName(), 'avatar' => Avatar::getDefaultGroup(), 'type' => 'department');
             }
             unset($departmentId);
         }
     }
     unset($type);
     return $entityList;
 }