/** * Delete tag to object association */ public function delete() { try { $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); } }
/** * @expectedException Sabre\DAV\Exception\NotFound */ public function testDeleteTagNotFound() { // assuming the tag existed at the time the node was created, // but got deleted concurrently in the database $tag = new SystemTag(1, 'Test', true, true); $this->tagManager->expects($this->once())->method('canUserSeeTag')->with($tag)->will($this->returnValue($tag->isUserVisible())); $this->tagManager->expects($this->once())->method('canUserAssignTag')->with($tag)->will($this->returnValue($tag->isUserAssignable())); $this->tagMapper->expects($this->once())->method('unassignTags')->with(123, 'files', 1)->will($this->throwException(new TagNotFoundException())); $this->getMappingNode($tag)->delete(); }
function childExists($tagId) { try { return $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true); } catch (\InvalidArgumentException $e) { throw new BadRequest('Invalid tag id', 0, $e); } catch (TagNotFoundException $e) { return false; } }
public function testProcessFilterRulesVisibleTagAsUser() { $this->groupManager->expects($this->any())->method('isAdmin')->will($this->returnValue(false)); $tag1 = $this->getMock('\\OCP\\SystemTag\\ISystemTag'); $tag1->expects($this->any())->method('getId')->will($this->returnValue('123')); $tag1->expects($this->any())->method('isUserVisible')->will($this->returnValue(true)); $tag2 = $this->getMock('\\OCP\\SystemTag\\ISystemTag'); $tag2->expects($this->any())->method('getId')->will($this->returnValue('123')); $tag2->expects($this->any())->method('isUserVisible')->will($this->returnValue(true)); $this->tagManager->expects($this->once())->method('getTagsByIds')->with(['123', '456'])->will($this->returnValue([$tag1, $tag2])); $this->tagMapper->expects($this->at(0))->method('getObjectIdsForTags')->with('123')->will($this->returnValue(['111', '222'])); $this->tagMapper->expects($this->at(1))->method('getObjectIdsForTags')->with('456')->will($this->returnValue(['222', '333'])); $rules = [['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'], ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456']]; $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules]))); }
/** * 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); } }
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 Sabre\DAV\Exception\NotFound */ public function testDeleteTagNotFound() { $this->tagMapper->expects($this->once())->method('unassignTags')->with(123, 'files', 1)->will($this->throwException(new TagNotFoundException())); $this->node->delete(); }
/** * @expectedException Sabre\DAV\Exception\BadRequest */ public function testChildExistsInvalidId() { $this->tagMapper->expects($this->once())->method('haveTag')->with([111], 'files', '555')->will($this->throwException(new \InvalidArgumentException())); $this->getNode()->childExists('555'); }
/** * @expectedException \OCP\SystemTag\TagNotFoundException */ public function testHaveTagNonExisting() { $this->tagMapper->haveTag([1], 'testtype', 100); }