Skip to content

Commit

Permalink
Small refactor and first attempt to implement DAV plugin, ref ponders…
Browse files Browse the repository at this point in the history
michielbdejong committed Dec 20, 2023
1 parent 8010f03 commit 0f2c1fd
Showing 3 changed files with 32 additions and 21 deletions.
26 changes: 17 additions & 9 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -80,26 +80,39 @@ public function __construct() {
$user = $userSession->getUser();
// The first time an admin logs in to the server, this will create the tag and flow
if ($user !== null && $groupManager->isAdmin($user->getUID())) {
$this->addTag();
$this->addFlows();
}
}

private function addTag(){
private static function getOurTagId(){
try{
$tags = $this->systemTagManager->getAllTags(
null,
self::TAG_NAME
);

if(count($tags) < 1){
$this->systemTagManager->createTag(self::TAG_NAME, false, false);
$tag = $this->systemTagManager->createTag(self::TAG_NAME, false, false);
} else {
$tag = current($tags);
}
return $tag->getId();
}catch (Exception $e) {
$this->logger->error('Error when inserting tag on enabling mfazones app', ['exception' => $e]);
return false;
}
}

public function nodeHasTag($node, $tagId){
$tags = $this->systemTagManager->getTagsForObjects([$node->getId()]);
foreach ($tags as $tag) {
if ($tag->getId() === $tagId) {
return true;
}
}
return false;
}

private function addFlows(){
try {
$hash = md5('OCA\WorkflowEngine\Check\MfaVerified::!is::');
@@ -115,12 +128,7 @@ private function addFlows(){
return;
}

$tags = $this->systemTagManager->getAllTags(
null,
self::TAG_NAME
);
$tag = current($tags);
$tagId = $tag->getId();
$tagId = self::getOurTagId(); // will create the tag if necessary

$scope = new ScopeContext(IManager::SCOPE_ADMIN);
$class = "OCA\\FilesAccessControl\\Operation";
6 changes: 1 addition & 5 deletions lib/Controller/MfazonesController.php
Original file line number Diff line number Diff line change
@@ -116,11 +116,7 @@ public function get($source)
try {
$userRoot = $this->rootFolder->getUserFolder($this->userId);
$node = $userRoot->get($source);
$tags = $this->systemTagManager->getAllTags(
null,
Application::TAG_NAME
);
$tag = current($tags);
$tag = Application::getOurTagId();
if ($tag === false) {
error_log('A server admin should log in so the MFA Zone tag and flow can be created.');
return new JSONResponse(
21 changes: 14 additions & 7 deletions lib/MFAPlugin.php
Original file line number Diff line number Diff line change
@@ -17,15 +17,15 @@
use Sabre\HTTP\ResponseInterface;

class MFAPlugin extends ServerPlugin {
private Server $server;
/** @var ISystemTagObjectMapper */
private $tagMapper;

public const VERSION_LABEL = '{http://nextcloud.org/ns}requires-mfa';
public const ATTR_NAME = '{http://nextcloud.org/ns}requires-mfa';

public function __construct(
private IRequest $request,
private IPreview $previewManager,
ISystemTagObjectMapper $tagMapper
) {
$this->request = $request;
$this->tagMapper = $tagMapper;
}

public function initialize(Server $server) {
@@ -34,7 +34,14 @@ public function initialize(Server $server) {
}

public function propFind(PropFind $propFind, INode $node): void {
$propFind->handle(self::VERSION_LABEL, fn() => 'ponder3source');
// $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => 'ponder2source');
$propFind->handle(self::ATTR_NAME, function() {
$tagId = Application::getOurTagId();
if ($tagId === false) {
return false;
}
$type = Application::castObjectType($node->getType());
// FIXME: check parents too
return $this->tagMapper->haveTag($node->getId(), $type, $tagId);
});
}
}

0 comments on commit 0f2c1fd

Please sign in to comment.