예제 #1
0
 /**
  * @param null
  * @return array(Calendar)
  */
 public static function getAllSharedCalendars($params)
 {
     $collaborator = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
     $shareType = CalendarManager::getInstance()->getNewCalendar();
     $result = SharingManager::getInstance()->getAllShareInfoFromCollaborator($collaborator, null, $shareType);
     return self::toArray($result);
 }
예제 #2
0
 public function updateCollaboratorPermission(AbstractEyeosPrincipal $collaborator, SharePermission $permission)
 {
     SharingManager::getInstance()->updateCollaboratorPermission($this, $collaborator, $permission);
 }
 public function testUpdateCollaboratorPermission()
 {
     $this->assertEquals(0, count($this->fixture->getAllShareInfo()));
     $perms = new SharePermission('read,write');
     $this->fixture->addCollaborator($this->collaborator1, $perms);
     $perms = new SharePermission('READ');
     $this->fixture->addCollaborator($this->collaborator2, $perms);
     $perms = new SharePermission('write');
     $this->fixture->addCollaborator($this->collaborator3, $perms);
     $this->assertEquals('read,write', SharingManager::getInstance()->getShareInfo($this->fixture, $this->collaborator1)->getPermissions()->getActionsAsString());
     $this->assertEquals('read', SharingManager::getInstance()->getShareInfo($this->fixture, $this->collaborator2)->getPermissions()->getActionsAsString());
     $coll3Perms = SharingManager::getInstance()->getShareInfo($this->fixture, $this->collaborator3)->getPermissions();
     $this->assertEquals('write', $coll3Perms->getActionsAsString());
     $perms = new SharePermission('execute');
     $this->fixture->updateCollaboratorPermission($this->collaborator1, $perms);
     $perms = new SharePermission('read,WRITE');
     $this->fixture->updateCollaboratorPermission($this->collaborator2, $perms);
     $perms = new SharePermission(array_merge($coll3Perms->getActions(), array('READ')));
     $this->fixture->updateCollaboratorPermission($this->collaborator3, $perms);
     $this->assertEquals('execute', SharingManager::getInstance()->getShareInfo($this->fixture, $this->collaborator1)->getPermissions()->getActionsAsString());
     $this->assertEquals('read,write', SharingManager::getInstance()->getShareInfo($this->fixture, $this->collaborator2)->getPermissions()->getActionsAsString());
     $this->assertEquals('read,write', SharingManager::getInstance()->getShareInfo($this->fixture, $this->collaborator3)->getPermissions()->getActionsAsString());
     // Try to edit collaborators without being the owner
     $this->loginAsAlice();
     try {
         $perms = new SharePermission(array('read'));
         SharingManager::getInstance()->updateCollaboratorPermission($this->fixture, $this->collaborator2, $perms);
         $this->fail();
     } catch (EyeAccessControlException $e) {
         // normal situation
     }
     $this->loginAsJohn();
 }
예제 #4
0
 public static function getInstance()
 {
     if (!self::$IsManagerLoaded) {
         self::$Logger = Logger::getLogger('system.services.Sharing.SharingManager');
         require SERVICE_SHARING_SHARINGMANAGERS_MANAGERS_PATH . '/' . SERVICE_SHARING_MANAGERCLASSNAME . '.php';
         self::$IsManagerLoaded = true;
     }
     return parent::getInstance(SERVICE_SHARING_MANAGERCLASSNAME);
 }
 /**
  * TODO
  * 
  * @param mixed $object
  * @param IPermission $permission
  * @param LoginContext $context
  * @return bool TRUE if the handler performed the permission check successfully, FALSE otherwise.
  * 
  * @throws EyeInvalidArgumentException
  * @throws EyeUnexpectedValueException
  * @throws EyeAccessControlException
  */
 public function checkPermission($object, IPermission $permission, LoginContext $context)
 {
     if (!$object instanceof IShareable) {
         throw new EyeInvalidArgumentException('$object must be an IShareable.');
     }
     if ($object->getId(false) === null) {
         $this->failureException = new EyeHandlerFailureException('$object has no ID and though is probably not currently shared.');
         return false;
     }
     try {
         $eyeosUser = $context->getEyeosUser();
     } catch (EyeNullPointerException $e) {
         $this->failureException = new EyeHandlerFailureException('No eyeos user found in login context.');
         return false;
     }
     // General sharing actions (addCollaborator, removeCollaborator, updateCollaborator)
     $actions = $permission->getActions();
     if (in_array('addcollaborator', $actions) || in_array('removecollaborator', $actions) || in_array('updatecollaborator', $actions)) {
         // currently, only the owner can perform those actions
         if ($eyeosUser->getId() != $object->getShareOwner()->getId()) {
             self::$Logger->info('Access denied to non-owner user ' . $eyeosUser->getName() . ' for actions "' . $permission->getActionsAsString() . '" on object ' . $object->getId() . '.');
             throw new EyeAccessControlException('Only the owner of the object can perform that kind of actions (' . $permission->getActionsAsString() . ').');
         }
         self::$Logger->debug('Access granted to owner ' . $eyeosUser->getName() . ' for actions "' . $permission->getActionsAsString() . '" on object ' . $object->getId() . '.');
         return true;
     }
     // Object-dependant sharing actions
     try {
         $shareInfos = SharingManager::getInstance()->getAllShareInfo($object);
     } catch (Exception $e) {
         $logger = Logger::getLogger('system.services.Security.ShareableObjectSecurityHandler');
         $logger->warn('Cannot retrieve shareinfo on object with ID: ' . $object->getId(false));
         if ($logger->isDebugEnabled()) {
             $logger->debug(ExceptionStackUtil::getStackTrace($e, false));
         } else {
             $logger->warn('Exception message: ' . $e->getMessage());
         }
         $this->failureException = new EyeHandlerFailureException('Cannot retrieve shareinfo on object with ID: ' . $object->getId(false) . ': ' . $e->getMessage());
         return false;
     }
     foreach ($shareInfos as $shareInfo) {
         $collaborator = $shareInfo->getCollaborator();
         //$collaborator is a group
         if ($collaborator instanceof IGroup) {
             // "is the subject in the current login context representative of the group collaborator?"
             if (in_array($collaborator, $context->getSubject()->getPrincipals())) {
                 if ($shareInfo->getPermissions()->implies($permission)) {
                     return true;
                 } else {
                     throw new EyeAccessControlException('$object permission actions (' . $shareInfo->getPermissions()->getActionsAsString() . ') ' . 'do not imply requested permission (' . $permission->getActionsAsString() . ') for collaborator ' . $eyeosUser->getName() . '');
                 }
             }
         } else {
             if ($shareInfo->getCollaborator()->getId() == $eyeosUser->getId()) {
                 if ($shareInfo->getPermissions()->implies($permission)) {
                     return true;
                 } else {
                     throw new EyeAccessControlException('$object permission actions (' . $shareInfo->getPermissions()->getActionsAsString() . ') ' . 'do not imply requested permission (' . $permission->getActionsAsString() . ') for collaborator ' . $eyeosUser->getName() . '');
                 }
             }
         }
     }
     // No matching collaborator found => this module is not applicable to the current check => set it as FAILED
     $this->failureException = new EyeHandlerFailureException('No matching collaborator found for object with ID ' . $object->getId(false) . '.');
     return false;
 }
예제 #6
0
 /**
  *
  * @param array $params (
  * 		'userId' => String,
  *		'files'	=> Array
  * 	)
  * @return <Array>
  */
 public static function changePrivilege($params)
 {
     $toBeRemoved = false;
     $user = UMManager::getInstance()->getUserById($params['userId']);
     if ($params['operation'] == 'Viewer') {
         $perms = new SharePermission('read');
     } else {
         if ($params['operation'] == 'Editor') {
             $perms = new SharePermission('read, write');
         } else {
             if ($params['operation'] == 'Remove') {
                 $toBeRemoved = true;
             }
         }
     }
     $files = array();
     $paramsFiles = $params['files'];
     for ($i = 0; $i < count($paramsFiles); $i++) {
         $trueFile = FSI::getFile($paramsFiles[$i]);
         if ($toBeRemoved) {
             SharingManager::getInstance()->removeCollaborator($trueFile, $user);
             $files[] = self::getSharedInfo($trueFile);
         } else {
             try {
                 SharingManager::getInstance()->addCollaborator($trueFile, $user, $perms);
                 $files[] = self::getSharedInfo($trueFile);
                 $info = new EyeosEventNotification();
                 $info->setType('Share_NewShare');
                 $info->setReceiver($params['userId']);
                 $eventManager = new EventNotificationManager();
                 $eventManager->sendEventByType($info);
             } catch (EyeDBException $e) {
                 SharingManager::getInstance()->updateCollaboratorPermission($trueFile, $user, $perms);
                 $files[] = self::getSharedInfo($trueFile);
             }
         }
     }
     return $files;
 }
예제 #7
0
 public function updateCollaboratorPermission(IShareable $object, AbstractEyeosPrincipal $collaborator, IPermission $permission)
 {
     return parent::updateCollaboratorPermission($object, $collaborator, $permission);
 }
예제 #8
0
 public function ownerChanged(FileEvent $e)
 {
     $source = $this->getSource($e);
     $oldOwner = UMManager::getInstance()->getUserByName($e->getChanges());
     SharingManager::getInstance()->notifyShareableObjectUpdated($source, $oldOwner);
 }
예제 #9
0
 public function updateCollaboratorPermission(AbstractEyeosPrincipal $collaborator, SharePermission $permission)
 {
     if ($this->realFile === null) {
         throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path);
     }
     SharingManager::getInstance()->updateCollaboratorPermission($this, $collaborator, $permission);
 }
예제 #10
0
 public static function changePrivilege($params)
 {
     $toBeRemoved = false;
     $user = UMManager::getInstance()->getUserById($params[1]);
     if ($params[0] == 'Viewer') {
         $perms = new SharePermission('read');
     } else {
         if ($params[0] == 'Editor') {
             $perms = new SharePermission('read, write');
         } else {
             if ($params[0] == 'Remove') {
                 $toBeRemoved = true;
             }
         }
     }
     $files = array();
     for ($i = 2; $i < count($params); $i++) {
         $trueFile = FSI::getFile($params[$i]);
         if ($toBeRemoved) {
             SharingManager::getInstance()->removeCollaborator($trueFile, $user);
             $files[] = self::getSharedInfo($trueFile);
         } else {
             try {
                 SharingManager::getInstance()->addCollaborator($trueFile, $user, $perms);
                 $files[] = self::getSharedInfo($trueFile);
             } catch (EyeDBException $e) {
                 SharingManager::getInstance()->updateCollaboratorPermission($trueFile, $user, $perms);
                 $files[] = self::getSharedInfo($trueFile);
             }
         }
     }
     return $files;
 }
예제 #11
0
        $file->setMeta($meta);
    }
    private static function initContext(EyeosAbstractVirtualFile $file, &$meta, &$activity, &$by)
    {
        self::checkFile($file);
        // Metadata
        $meta = $file->getMeta();
        if ($meta === null) {
            $meta = MetaManager::getInstance()->getNewMetaDataInstance();
        }
        // Activity node
        if ($meta->exists('activity')) {
            $activity = $meta->get('activity');
        } else {
            $activity = array();
        }
        // Current user ("by")
        $by = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
    }
    public static function getInstance()
    {
        if (self::$Instance === null) {
            self::$Instance = new FileActivityListener();
        }
        return self::$Instance;
    }
}
// Register singleton listener on the target dispatchers
EyeosGlobalFileEventsDispatcher::getInstance()->addListener(FileActivityListener::getInstance());
SharingManager::getInstance()->addListener(FileActivityListener::getInstance());
예제 #12
0
            } else {
                $parentId = '0';
                $path = $pathParent;
            }
            if ($parentId !== false) {
                $pathAbsolute = AdvancedPathLib::getPhpLocalHackPath($e->getSource()->getRealFile()->getAbsolutePath());
                $token = $_SESSION['access_token_' . $cloud->name . '_v2'];
                if ($resourceUrl) {
                    $token = $resourceUrl->token;
                    $resourceUrl = $resourceUrl->resource_url;
                }
                $result = $apiManager->createMetadata($cloud->name, $token, $user->getId(), true, $e->getSource()->getName(), $parentId, $path, $pathAbsolute, $resourceUrl);
                if ($result['status'] == 'OK') {
                    $params = array($e->getSource()->getParentPath(), $e->getSource()->getPath());
                    $message = new ClientBusMessage('file', 'refreshStackSync', $params);
                    ClientMessageBusController::getInstance()->queueMessage($message);
                } else {
                    if ($result['error'] == 403) {
                        $path = $this->cleanCloud($cloud->name, $user);
                        $params = array($path, $cloud->name);
                        $message = new ClientBusMessage('file', 'permissionDenied', $params);
                        ClientMessageBusController::getInstance()->queueMessage($message);
                    }
                }
            }
        }
    }
}
EyeosGlobalFileEventsDispatcher::getInstance()->addListener(StoreListener::getInstance());
SharingManager::getInstance()->addListener(StoreListener::getInstance());
예제 #13
0
 public function listFiles($pattern = '*', $flags = AdvancedPathLib::GLOB_NORMAL)
 {
     $files = array();
     $urlParts = $this->getURLComponents();
     $isRoot = false;
     if (!isset($urlParts['principalname'])) {
         $isRoot = true;
         if ($urlParts['path'] != '/') {
             throw new EyeBadMethodCallException('Cannot list files: ' . $this->path . ' is not a (handled) directory.');
         }
     }
     // ROOT (share://): list the owners sharing files with the current user
     if ($isRoot) {
         //--- Legacy code [I'd like to keep this part of the code in case some people change suddenly their minds, once again...]
         /*$currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
         		$shareInfo = SharingManager::getInstance()->getAllShareInfoFromCollaborator($currentUser, null, 'IShareableFile');
         		
         		// Build an array(ownerId => ownerName)
         		$owners = array();
         		foreach($shareInfo as $shareInfoData) {
         			try {
         				$currentOwner = $shareInfoData->getOwner();
         				if (!isset($owners[$currentOwner->getId()])) {
         					$owners[$currentOwner->getId()] = $currentOwner->getName();
         				}
         			} catch (Exception $e) {
         				Logger::getLogger('system.services.FileSystem.EyeSharedFile')->warn('Cannot retrieve ShareInfo components from shared file: "' . $shareInfoData->getShareable() . '", skipping.');
         			}
         		}
         		sort($owners);
         		
         		foreach($owners as $ownerName) {
         			$files[] = new EyeSharedFile(self::URL_SCHEME_SHARE . '://' . self::URL_LOCATOR_CHAR . $ownerName . '/');
         		}*/
         //--- Legacy code
         $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
         $peopleController = PeopleController::getInstance();
         $contacts = $peopleController->getAllContacts($currentUser->getId());
         foreach ($contacts as $contact) {
             if ($contact->getRelation()->getSourceId() == $currentUser->getId()) {
                 $otherUser = UMManager::getInstance()->getUserById($contact->getRelation()->getTargetId());
             } else {
                 $otherUser = UMManager::getInstance()->getUserById($contact->getRelation()->getSourceId());
             }
             $files[] = new EyeSharedFile(self::URL_SCHEME_SHARE . '://' . self::URL_LOCATOR_CHAR . $otherUser->getName() . '/');
         }
     } else {
         if ($flags & AdvancedPathLib::GLOB_ONLY_DIR) {
             // Folders are not shareable yet
             return array();
         }
         $ownerName = $urlParts['principalname'];
         $owner = UMManager::getInstance()->getUserByName($ownerName);
         $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
         // CURRENT USER ROOT (share://~currentUser/): Show the list of all the files that are currently
         // shared by the current user
         if ($owner == $currentUser) {
             $shareInfo = SharingManager::getInstance()->getAllShareInfoFromOwner($currentUser, 'IShareableFile');
         } else {
             $shareInfo = SharingManager::getInstance()->getAllShareInfoFromCollaborator($currentUser, $owner, 'IShareableFile');
         }
         // Special temporary array for files IDs to avoid duplication in the returned array
         $fileIds = array();
         foreach ($shareInfo as $shareInfoData) {
             $sharedFile = $shareInfoData->getShareable();
             $id = $sharedFile->getId();
             if (!isset($fileIds[$id])) {
                 $fileIds[$id] = 0;
                 // Arbitrary value (we only use keys in this array)
                 $files[] = $sharedFile;
             }
         }
     }
     return $files;
 }