Skip to content

Commit

Permalink
feat: request to sign from files
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Nov 14, 2024
1 parent 4c39bac commit bf6776d
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 128 deletions.
1 change: 1 addition & 0 deletions img/app-colored.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

namespace OCA\Libresign\AppInfo;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCA\Libresign\Activity\Listener as ActivityListener;
use OCA\Libresign\Events\SendSignNotificationEvent;
use OCA\Libresign\Events\SignedEvent;
use OCA\Libresign\Files\TemplateLoader as FilesTemplateLoader;
use OCA\Libresign\Listener\BeforeNodeDeletedListener;
use OCA\Libresign\Listener\LoadAdditionalListener;
use OCA\Libresign\Listener\LoadSidebarListener;
use OCA\Libresign\Listener\MailNotifyListener;
use OCA\Libresign\Listener\NotificationListener;
Expand Down Expand Up @@ -59,6 +61,9 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeNodeDeletedEvent::class, BeforeNodeDeletedListener::class);
$context->registerEventListener(SignedEvent::class, SignedListener::class);

// Files newFile listener
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);

// Activity listeners
$context->registerEventListener(SendSignNotificationEvent::class, ActivityListener::class);

Expand Down
45 changes: 45 additions & 0 deletions lib/Listener/LoadAdditionalListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Libresign\Listener;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Handler\CertificateEngine\Handler as CertificateEngineHandler;
use OCP\App\IAppManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

/**
* @template-implements IEventListener<LoadAdditionalScriptsEvent>
*/
class LoadAdditionalListener implements IEventListener {
public function __construct(
private IAppManager $appManager,
private CertificateEngineHandler $certificateEngineHandler,
) {
}
public function handle(Event $event): void {
if (!($event instanceof LoadAdditionalScriptsEvent)) {
return;
}

if (!$this->appManager->isEnabledForUser('libresign')) {
return;
}

if (!$this->certificateEngineHandler->getEngine()->isSetupOk()) {
return;
}

if (class_exists('\OCA\Files\App')) {
Util::addInitScript(Application::APP_ID, 'libresign-init');
}
}
}
10 changes: 10 additions & 0 deletions lib/Service/FolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public function getFolder(): Folder {
*/
public function getFileById(?int $nodeId = null): File {
if ($this->getUserId()) {
$mountsContainingFile = $this->userMountCache->getMountsForFileId($nodeId);
foreach ($mountsContainingFile as $fileInfo) {
$this->root->getByIdInPath($nodeId, $fileInfo->getMountPoint());
}
$file = $this->root->getById($nodeId);
if ($file) {
/** @var File */
return $file[0];
}

$folder = $this->root->getUserFolder($this->getUserId());
$file = $folder->getById($nodeId);
if ($file) {
Expand Down
Loading

0 comments on commit bf6776d

Please sign in to comment.