public function testTagGroups()
 {
     $tag1 = $this->tagManager->createTag('tag1', true, false);
     $tag2 = $this->tagManager->createTag('tag2', true, false);
     $this->tagManager->setTagGroups($tag1, ['group1', 'group2']);
     $this->tagManager->setTagGroups($tag2, ['group2', 'group3']);
     $this->assertEquals(['group1', 'group2'], $this->tagManager->getTagGroups($tag1));
     $this->assertEquals(['group2', 'group3'], $this->tagManager->getTagGroups($tag2));
     // change groups
     $this->tagManager->setTagGroups($tag1, ['group3', 'group4']);
     $this->tagManager->setTagGroups($tag2, []);
     $this->assertEquals(['group3', 'group4'], $this->tagManager->getTagGroups($tag1));
     $this->assertEquals([], $this->tagManager->getTagGroups($tag2));
 }
예제 #2
0
 /**
  * Updates tag attributes
  *
  * @param string $path
  * @param PropPatch $propPatch
  *
  * @return void
  */
 public function handleUpdateProperties($path, PropPatch $propPatch)
 {
     $propPatch->handle([self::DISPLAYNAME_PROPERTYNAME, self::USERVISIBLE_PROPERTYNAME, self::USERASSIGNABLE_PROPERTYNAME, self::GROUPS_PROPERTYNAME], function ($props) use($path) {
         $node = $this->server->tree->getNodeForPath($path);
         if (!$node instanceof SystemTagNode) {
             return;
         }
         $tag = $node->getSystemTag();
         $name = $tag->getName();
         $userVisible = $tag->isUserVisible();
         $userAssignable = $tag->isUserAssignable();
         $updateTag = false;
         if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) {
             $name = $props[self::DISPLAYNAME_PROPERTYNAME];
             $updateTag = true;
         }
         if (isset($props[self::USERVISIBLE_PROPERTYNAME])) {
             $propValue = $props[self::USERVISIBLE_PROPERTYNAME];
             $userVisible = $propValue !== 'false' && $propValue !== '0';
             $updateTag = true;
         }
         if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) {
             $propValue = $props[self::USERASSIGNABLE_PROPERTYNAME];
             $userAssignable = $propValue !== 'false' && $propValue !== '0';
             $updateTag = true;
         }
         if (isset($props[self::GROUPS_PROPERTYNAME])) {
             if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
                 // property only available for admins
                 throw new Forbidden();
             }
             $propValue = $props[self::GROUPS_PROPERTYNAME];
             $groupIds = explode('|', $propValue);
             $this->tagManager->setTagGroups($tag, $groupIds);
         }
         if ($updateTag) {
             $node->update($name, $userVisible, $userAssignable);
         }
         return true;
     });
 }