public function delete()
 {
     try {
         if (!$this->isAdmin) {
             if (!$this->tag->isUserVisible()) {
                 throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found');
             }
             if (!$this->tag->isUserAssignable()) {
                 throw new Forbidden('No permission to delete tag ' . $this->tag->getId());
             }
         }
         $this->tagManager->deleteTags($this->tag->getId());
     } catch (TagNotFoundException $e) {
         // can happen if concurrent deletion occurred
         throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e);
     }
 }
 /**
  * Update tag
  *
  * @param string $name new tag name
  * @param bool $userVisible user visible
  * @param bool $userAssignable user assignable
  * @throws NotFound whenever the given tag id does not exist
  * @throws Forbidden whenever there is no permission to update said tag
  * @throws Conflict whenever a tag already exists with the given attributes
  */
 public function update($name, $userVisible, $userAssignable)
 {
     try {
         if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
             throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
         }
         if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
             throw new Forbidden('No permission to update tag ' . $this->tag->getId());
         }
         // only admin is able to change permissions, regular users can only rename
         if (!$this->isAdmin) {
             // only renaming is allowed for regular users
             if ($userVisible !== $this->tag->isUserVisible() || $userAssignable !== $this->tag->isUserAssignable()) {
                 throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId());
             }
         }
         $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable);
     } catch (TagNotFoundException $e) {
         throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
     } catch (TagAlreadyExistsException $e) {
         throw new Conflict('Tag with the properties "' . $name . '", ' . $userVisible . ', ' . $userAssignable . ' already exists');
     }
 }
 /**
  * @param ISystemTag $tag1
  * @param ISystemTag $tag2
  */
 private function assertSameTag($tag1, $tag2)
 {
     $this->assertEquals($tag1->getId(), $tag2->getId());
     $this->assertEquals($tag1->getName(), $tag2->getName());
     $this->assertEquals($tag1->isUserVisible(), $tag2->isUserVisible());
     $this->assertEquals($tag1->isUserAssignable(), $tag2->isUserAssignable());
 }
 /**
  * {@inheritdoc}
  */
 public function canUserAssignTag(ISystemTag $tag, IUser $user)
 {
     // early check to avoid unneeded group lookups
     if ($tag->isUserAssignable() && $tag->isUserVisible()) {
         return true;
     }
     if ($this->groupManager->isAdmin($user->getUID())) {
         return true;
     }
     if (!$tag->isUserVisible()) {
         return false;
     }
     $groupIds = $this->groupManager->getUserGroupIds($user);
     if (!empty($groupIds)) {
         $matchingGroups = array_intersect($groupIds, $this->getTagGroups($tag));
         if (!empty($matchingGroups)) {
             return true;
         }
     }
     return false;
 }
Exemple #5
0
 /**
  * @param ISystemTag $tag
  * @return string
  */
 protected function prepareTagAsParameter(ISystemTag $tag)
 {
     if (!$tag->isUserVisible()) {
         return '{{{' . $tag->getName() . '|||invisible}}}';
     } else {
         if (!$tag->isUserAssignable()) {
             return '{{{' . $tag->getName() . '|||not-assignable}}}';
         } else {
             return '{{{' . $tag->getName() . '|||assignable}}}';
         }
     }
 }