/**
  * Retrieves system tag properties
  *
  * @param PropFind $propFind
  * @param \Sabre\DAV\INode $node
  */
 public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
 {
     if (!$node instanceof SystemTagNode && !$node instanceof SystemTagMappingNode) {
         return;
     }
     $propFind->handle(self::ID_PROPERTYNAME, function () use($node) {
         return $node->getSystemTag()->getId();
     });
     $propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use($node) {
         return $node->getSystemTag()->getName();
     });
     $propFind->handle(self::USERVISIBLE_PROPERTYNAME, function () use($node) {
         return $node->getSystemTag()->isUserVisible() ? 'true' : 'false';
     });
     $propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function () use($node) {
         // this is the tag's inherent property "is user assignable"
         return $node->getSystemTag()->isUserAssignable() ? 'true' : 'false';
     });
     $propFind->handle(self::CANASSIGN_PROPERTYNAME, function () use($node) {
         // this is the effective permission for the current user
         return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false';
     });
     $propFind->handle(self::GROUPS_PROPERTYNAME, function () use($node) {
         if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) {
             // property only available for admins
             throw new Forbidden();
         }
         $groups = [];
         // no need to retrieve groups for namespaces that don't qualify
         if ($node->getSystemTag()->isUserVisible() && !$node->getSystemTag()->isUserAssignable()) {
             $groups = $this->tagManager->getTagGroups($node->getSystemTag());
         }
         return implode('|', $groups);
     });
 }
 function createFile($tagId, $data = null)
 {
     try {
         $tags = $this->tagManager->getTagsByIds([$tagId]);
         $tag = current($tags);
         if (!$this->tagManager->canUserSeeTag($tag, $this->user)) {
             throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
         }
         if (!$this->tagManager->canUserAssignTag($tag, $this->user)) {
             throw new Forbidden('No permission to assign tag ' . $tagId);
         }
         $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId);
     } catch (TagNotFoundException $e) {
         throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign');
     }
 }
 /**
  * @dataProvider assignabilityCheckProvider
  */
 public function testAssignabilityCheck($userVisible, $userAssignable, $isAdmin, $expectedResult, $userGroupIds = [], $tagGroupIds = [])
 {
     $user = $this->getMockBuilder('\\OCP\\IUser')->getMock();
     $user->expects($this->any())->method('getUID')->will($this->returnValue('test'));
     $tag1 = $this->tagManager->createTag('one', $userVisible, $userAssignable);
     $this->tagManager->setTagGroups($tag1, $tagGroupIds);
     $this->groupManager->expects($this->any())->method('isAdmin')->with('test')->will($this->returnValue($isAdmin));
     $this->groupManager->expects($this->any())->method('getUserGroupIds')->with($user)->will($this->returnValue($userGroupIds));
     $this->assertEquals($expectedResult, $this->tagManager->canUserAssignTag($tag1, $user));
 }
 /**
  * Delete tag to object association
  */
 public function delete()
 {
     try {
         if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
             throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found');
         }
         if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
             throw new Forbidden('No permission to unassign tag ' . $this->tag->getId());
         }
         $this->tagMapper->unassignTags($this->objectId, $this->objectType, $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);
     }
 }