diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d207d32..c011b11 100755 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -95,15 +95,15 @@ private static function castObjectType($type) return $type; } - private static function getOurTagId(){ + public static function getOurTagIdFromSystemTagManager($systemTagManager){ try{ - $tags = $this->systemTagManager->getAllTags( + $tags = $systemTagManager->getAllTags( null, self::TAG_NAME ); if(count($tags) < 1){ - $tag = $this->systemTagManager->createTag(self::TAG_NAME, false, false); + $tag = $systemTagManager->createTag(self::TAG_NAME, false, false); } else { $tag = current($tags); } diff --git a/lib/Controller/MfazonesController.php b/lib/Controller/MfazonesController.php index 4dd21d3..60b9ab7 100755 --- a/lib/Controller/MfazonesController.php +++ b/lib/Controller/MfazonesController.php @@ -116,8 +116,8 @@ public function get($source) try { $userRoot = $this->rootFolder->getUserFolder($this->userId); $node = $userRoot->get($source); - $tag = Application::getOurTagId(); - if ($tag === false) { + $tagId = Application::getOurTagIdFromSystemTagManager($this->systemTagManager); + if ($tagId === false) { error_log('A server admin should log in so the MFA Zone tag and flow can be created.'); return new JSONResponse( array( @@ -125,8 +125,7 @@ public function get($source) ) ); } - $tagId = $tag->getId(); - $type = $this->castObjectType($node->getType()); + $type = Application::castObjectType($node->getType()); $result = $this->tagMapper->haveTag($node->getId(), $type, $tagId); return new JSONResponse( @@ -173,7 +172,7 @@ public function getList($nodeIds) $results = []; foreach($nodeIds as $nodeId) { $node = $userRoot->getById($nodeId); - $type = $this->castObjectType($node->getType()); + $type = Application::castObjectType($node->getType()); $results[$nodeId] = $this->tagMapper->haveTag($nodeId, $type, $tagId); } @@ -211,12 +210,8 @@ public function set($source, $protect) if ($node->getType() !== 'dir') { return new DataResponse(['not a directory'], Http::STATUS_FORBIDDEN); } - $tags = $this->systemTagManager->getAllTags( - null, - Application::TAG_NAME - ); - $tag = current($tags); - if ($tag === false) { + $tagId = Application::getOurTagIdFromSystemTagManager($this->systemTagManager); + if ($tagId === false) { error_log('A server admin should log in so the MFA Zone tag and flow can be created.'); return new JSONResponse( array( @@ -224,9 +219,7 @@ public function set($source, $protect) ) ); } - $tagId = $tag->getId(); - - $type = $this->castObjectType($node->getType()); + $type = Application::castObjectType($node->getType()); if ($protect === "true") { $this->tagMapper->assignTags($node->getId(), $type, $tagId); @@ -254,15 +247,4 @@ public function access($source) ) ); } - - private function castObjectType($type) - { - if ($type === 'file') { - return "files"; - } - if ($type === "dir") { - return "files"; - } - return $type; - } } diff --git a/lib/MFAPlugin.php b/lib/MFAPlugin.php index cdeca13..da025ab 100644 --- a/lib/MFAPlugin.php +++ b/lib/MFAPlugin.php @@ -17,14 +17,19 @@ use Sabre\HTTP\ResponseInterface; class MFAPlugin extends ServerPlugin { + /** @var ISystemTagManager */ + private $sytemTagMapper; + /** @var ISystemTagObjectMapper */ private $tagMapper; public const ATTR_NAME = '{http://nextcloud.org/ns}requires-mfa'; public function __construct( + ISystemTagManager $systemTagManager, ISystemTagObjectMapper $tagMapper ) { + $this->systemTagManager = $systemTagManager; $this->tagMapper = $tagMapper; } @@ -35,7 +40,7 @@ public function initialize(Server $server) { public function propFind(PropFind $propFind, INode $node): void { $propFind->handle(self::ATTR_NAME, function() { - $tagId = Application::getOurTagId(); + $tagId = Application::getOurTagIdFromSystemTagManager($this->systemTagManager); if ($tagId === false) { return false; }