function childExists($name)
 {
     try {
         $this->tagManager->getTagsByIds([$name]);
         return true;
     } catch (\InvalidArgumentException $e) {
         throw new BadRequest('Invalid tag id', 0, $e);
     } catch (TagNotFoundException $e) {
         return false;
     }
 }
Exemple #2
0
 /**
  * @param MapperEvent $event
  */
 public function mapperEvent(MapperEvent $event)
 {
     $tagIds = $event->getTags();
     if ($event->getObjectType() !== 'files' || empty($tagIds) || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) || !$this->appManager->isInstalled('activity')) {
         // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy)
         return;
     }
     try {
         $tags = $this->tagManager->getTagsByIds($tagIds);
     } catch (TagNotFoundException $e) {
         // User assigned/unassigned a non-existing tag, ignore...
         return;
     }
     if (empty($tags)) {
         return;
     }
     // Get all mount point owners
     $cache = $this->mountCollection->getMountCache();
     $mounts = $cache->getMountsForFileId($event->getObjectId());
     if (empty($mounts)) {
         return;
     }
     $users = [];
     foreach ($mounts as $mount) {
         $owner = $mount->getUser()->getUID();
         $ownerFolder = $this->rootFolder->getUserFolder($owner);
         $nodes = $ownerFolder->getById($event->getObjectId());
         if (!empty($nodes)) {
             /** @var Node $node */
             $node = array_shift($nodes);
             $path = $node->getPath();
             if (strpos($path, '/' . $owner . '/files/') === 0) {
                 $path = substr($path, strlen('/' . $owner . '/files'));
             }
             // Get all users that have access to the mount point
             $users = array_merge($users, Share::getUsersSharingFile($path, $owner, true, true));
         }
     }
     $actor = $this->session->getUser();
     if ($actor instanceof IUser) {
         $actor = $actor->getUID();
     } else {
         $actor = '';
     }
     $activity = $this->activityManager->generateEvent();
     $activity->setApp(Extension::APP_NAME)->setType(Extension::APP_NAME)->setAuthor($actor)->setObject($event->getObjectType(), $event->getObjectId());
     foreach ($users as $user => $path) {
         $activity->setAffectedUser($user);
         foreach ($tags as $tag) {
             if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) {
                 $activity->setSubject(Extension::ASSIGN_TAG, [$actor, $path, $this->prepareTagAsParameter($tag)]);
             } else {
                 if ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) {
                     $activity->setSubject(Extension::UNASSIGN_TAG, [$actor, $path, $this->prepareTagAsParameter($tag)]);
                 }
             }
             $this->activityManager->publish($activity);
         }
     }
 }
 function getChildren()
 {
     $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType));
     if (empty($tagIds)) {
         return [];
     }
     $tags = $this->tagManager->getTagsByIds($tagIds);
     return array_values(array_map(function ($tag) {
         return $this->makeNode($tag);
     }, $tags));
 }
 /**
  * Asserts that all the given tag ids exist.
  *
  * @param string[] $tagIds tag ids to check
  *
  * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
  */
 private function assertTagsExist($tagIds)
 {
     $tags = $this->tagManager->getTagsByIds($tagIds);
     if (count($tags) !== count($tagIds)) {
         // at least one tag missing, bail out
         $foundTagIds = array_map(function (ISystemTag $tag) {
             return $tag->getId();
         }, $tags);
         $missingTagIds = array_diff($tagIds, $foundTagIds);
         throw new TagNotFoundException('Tags not found', 0, null, $missingTagIds);
     }
 }
 /**
  * @param string $name
  */
 function childExists($name)
 {
     try {
         $tag = $this->tagManager->getTagsByIds([$name]);
         $tag = current($tag);
         if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) {
             return false;
         }
         return true;
     } catch (\InvalidArgumentException $e) {
         throw new BadRequest('Invalid tag id', 0, $e);
     } catch (TagNotFoundException $e) {
         return false;
     }
 }
 /**
  * @param string $name
  */
 function childExists($name)
 {
     try {
         $tag = $this->tagManager->getTagsByIds([$name]);
         $tag = current($tag);
         if (!$this->isAdmin() && !$tag->isUserVisible()) {
             return false;
         }
         return true;
     } catch (\InvalidArgumentException $e) {
         throw new BadRequest('Invalid tag id', 0, $e);
     } catch (TagNotFoundException $e) {
         return false;
     }
 }
 function childExists($tagId)
 {
     try {
         $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true);
         if ($result) {
             $tags = $this->tagManager->getTagsByIds([$tagId]);
             $tag = current($tags);
             if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
                 return false;
             }
         }
         return $result;
     } catch (\InvalidArgumentException $e) {
         throw new BadRequest('Invalid tag id', 0, $e);
     } catch (TagNotFoundException $e) {
         return false;
     }
 }
 /**
  * Find file ids matching the given filter rules
  *
  * @param array $filterRules
  * @return array array of unique file id results
  *
  * @throws TagNotFoundException whenever a tag was not found
  */
 public function processFilterRules($filterRules)
 {
     $ns = '{' . $this::NS_OWNCLOUD . '}';
     $resultFileIds = null;
     $systemTagIds = [];
     foreach ($filterRules as $filterRule) {
         if ($filterRule['name'] === $ns . 'systemtag') {
             $systemTagIds[] = $filterRule['value'];
         }
     }
     // check user permissions, if applicable
     if (!$this->isAdmin()) {
         // check visibility/permission
         $tags = $this->tagManager->getTagsByIds($systemTagIds);
         $unknownTagIds = [];
         foreach ($tags as $tag) {
             if (!$tag->isUserVisible()) {
                 $unknownTagIds[] = $tag->getId();
             }
         }
         if (!empty($unknownTagIds)) {
             throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found');
         }
     }
     // fetch all file ids and intersect them
     foreach ($systemTagIds as $systemTagId) {
         $fileIds = $this->tagMapper->getObjectIdsForTags($systemTagId, 'files');
         if (empty($fileIds)) {
             // This tag has no files, nothing can ever show up
             return [];
         }
         // first run ?
         if ($resultFileIds === null) {
             $resultFileIds = $fileIds;
         } else {
             $resultFileIds = array_intersect($resultFileIds, $fileIds);
         }
         if (empty($resultFileIds)) {
             // Empty intersection, nothing can show up anymore
             return [];
         }
     }
     return $resultFileIds;
 }
 function childExists($tagId)
 {
     try {
         $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true);
         if ($this->isAdmin || !$result) {
             return $result;
         }
         // verify if user is allowed to see this tag
         $tag = $this->tagManager->getTagsByIds($tagId);
         $tag = current($tag);
         if (!$tag->isUserVisible()) {
             return false;
         }
         return true;
     } catch (\InvalidArgumentException $e) {
         throw new BadRequest('Invalid tag id', 0, $e);
     } catch (TagNotFoundException $e) {
         return false;
     }
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testGetInvalidTagIdFormat()
 {
     $tag1 = $this->tagManager->createTag('one', true, false);
     $this->tagManager->getTagsByIds([$tag1->getId() . 'suffix']);
 }