Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] feat: request to sign from files #3946

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,12 +24,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 @@ -75,6 +77,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
3 changes: 1 addition & 2 deletions lib/Db/SignRequestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

namespace OCA\Libresign\Db;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use OCA\Libresign\Helper\Pagination;
use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
use OCA\Libresign\Service\IdentifyMethodService;
Expand Down Expand Up @@ -475,7 +474,7 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, ?arra
// when the database is PostgreSQL. The problem is that the command
// addGroupBy add quotes over all text send as argument. With
// PostgreSQL json columns don't have problem if not added to group by.
if (!$qb->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
if ($qb->getConnection()->getDatabaseProvider() !== IDBConnection::PLATFORM_POSTGRES) {
$qb->addGroupBy('f.metadata');
}

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 @@ -84,6 +84,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
Loading