Skip to content
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
2 changes: 0 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use OCA\Libresign\Listener\MailNotifyListener;
use OCA\Libresign\Listener\NotificationListener;
use OCA\Libresign\Listener\RevokeClickToSignCertificateListener;
use OCA\Libresign\Listener\SignedCallbackListener;
use OCA\Libresign\Listener\TwofactorGatewayListener;
use OCA\Libresign\Listener\UserDeletedListener;
use OCA\Libresign\Middleware\GlobalInjectionMiddleware;
Expand Down Expand Up @@ -67,7 +66,6 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadSidebar::class, TemplateLoader::class);
$context->registerEventListener(BeforeNodeDeletedEvent::class, BeforeNodeDeletedListener::class);
$context->registerEventListener(CacheEntryRemovedEvent::class, BeforeNodeDeletedListener::class);
$context->registerEventListener(SignedEvent::class, SignedCallbackListener::class);

// Files newFile listener
$context->registerEventListener('OCA\\Files\\Event\\LoadAdditionalScriptsEvent', LoadAdditionalListener::class);
Expand Down
4 changes: 0 additions & 4 deletions lib/Controller/RequestSignatureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function __construct(
* @param LibresignFolderSettings $settings Settings to define how and where the file should be stored
* @param LibresignNewFile $file File object. Supports nodeId (a non-negative integer or its canonical decimal string, as Nextcloud node ids can exceed a JavaScript number), url, base64 or path.
* @param list<LibresignNewFile> $files Multiple files to create an envelope (optional, use either file or files). Each file supports nodeId, url, base64 or path.
* @param string|null $callback URL that will receive a POST after the document is signed
* @param integer|null $status Numeric code of status * 0 - no signers * 1 - signed * 2 - pending
* @param LibresignRequestPolicy|null $policy Structured policy payload with request-level overrides and active context.
* @return DataResponse<Http::STATUS_OK, LibresignDetailedFileResponse, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, LibresignMessageResponse|LibresignActionErrorResponse, array{}>
Expand All @@ -84,7 +83,6 @@ public function requestSignature(
array $settings = [],
array $file = [],
array $files = [],
?string $callback = null,
?int $status = 1,
?array $policy = null,
): DataResponse {
Comment thread
vitormattos marked this conversation as resolved.
Resolved
Expand All @@ -98,7 +96,6 @@ public function requestSignature(
$settings,
$signers,
$status,
$callback,
$policy,
);

Expand Down Expand Up @@ -176,7 +173,6 @@ public function updateSignatureRequest(
$settings,
$signers,
$status,
null,
$policy,
$visibleElements
);
Expand Down
4 changes: 0 additions & 4 deletions lib/Db/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
* @method \DateTime getCreatedAt()
* @method void setName(string $name)
* @method non-falsy-string getName()
* @method void setCallback(string $callback)
* @method ?string getCallback()
* @method void setStatus(int $status)
* @method int getStatus()
* @method void setMetadata(array $metadata)
Expand All @@ -57,7 +55,6 @@ class File extends Entity {
protected ?string $userId = null;
protected ?int $signedNodeId = null;
protected ?string $signedHash = null;
protected ?string $callback = null;
protected ?array $metadata = null;
protected int $modificationStatus = 0;
protected int $signatureFlow = SignatureFlow::NUMERIC_NONE;
Expand All @@ -79,7 +76,6 @@ public function __construct() {
$this->addType('uuid', Types::STRING);
$this->addType('createdAt', Types::DATETIME);
$this->addType('name', Types::STRING);
$this->addType('callback', Types::STRING);
$this->addType('status', Types::INTEGER);
$this->addType('metadata', Types::JSON);
$this->addType('modificationStatus', Types::SMALLINT);
Expand Down
3 changes: 0 additions & 3 deletions lib/Db/IdDocsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ private function getQueryBuilder(array $filter = [], bool $count = false): IQuer
'f.id',
'f.uuid',
'f.name',
'f.callback',
'f.status',
'f.node_id',
'f.user_id',
Expand Down Expand Up @@ -217,7 +216,6 @@ private function getQueryBuilder(array $filter = [], bool $count = false): IQuer
'f.id',
'f.uuid',
'f.name',
'f.callback',
'f.status',
'f.node_id',
'f.user_id',
Expand Down Expand Up @@ -314,7 +312,6 @@ private function formatListRow(array $row, string $url): array {
'signedNodeId' => (int)$row['node_id'],
'url' => $url . $row['uuid'],
],
'callback' => $row['callback'],
'uuid' => $row['uuid'],
'signers' => [],
],
Expand Down
35 changes: 0 additions & 35 deletions lib/Listener/SignedCallbackListener.php

This file was deleted.

156 changes: 156 additions & 0 deletions lib/Migration/Version19005Date20261109110000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

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

namespace OCA\Libresign\Migration;

use Closure;
use OCA\Libresign\AppInfo\Application;
use OCP\DB\ISchemaWrapper;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\IAppData;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Remove legacy callback destinations after preserving any configured values.
*/
final class Version19005Date20261109110000 extends SimpleMigrationStep {
private const FILE_BACKUP = 'backup-table-libresign_file_callback_Version19005Date20261109110000.csv';
private const CONFIG_BACKUP = 'backup-config-webhook_sign_url_Version19005Date20261109110000.json';

private IAppData $appData;

public function __construct(
private IAppConfig $appConfig,
private IDBConnection $connection,
IAppDataFactory $appDataFactory,
) {
$this->appData = $appDataFactory->get(Application::APP_ID);
}

/** @param Closure(): ISchemaWrapper $schemaClosure */
#[\Override]
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$schema = $schemaClosure();
if ($schema->hasTable('libresign_file') && $schema->getTable('libresign_file')->hasColumn('callback')) {
$this->backupFileCallbacks($output);
}

$this->backupLegacyWebhookUrl($output);
}

private function backupFileCallbacks(IOutput $output): void {
$query = $this->connection->getQueryBuilder();
$query->select('id', 'callback')
->from('libresign_file')
->where($query->expr()->nonEmptyString('callback'))
->orderBy('id');

$result = $query->executeQuery();
try {
$row = $result->fetchAssociative();
if ($row === false) {
return;
}

// Build the CSV before creating AppData, so CSV write failures cannot
// persist a partial backup and leave the migration free to drop data.
$handle = fopen('php://temp', 'w+');
if ($handle === false) {
throw new \RuntimeException('Could not open LibreSign callback backup buffer');
}

try {
if (fputcsv($handle, ['id', 'callback'], ',', '"', '') === false) {
throw new \RuntimeException('Could not write LibreSign callback backup header');
}

do {
if (fputcsv($handle, [$row['id'], $row['callback']], ',', '"', '') === false) {
throw new \RuntimeException('Could not write LibreSign callback backup row');
}
} while (($row = $result->fetchAssociative()) !== false);

$bytes = ftell($handle);
if ($bytes === false || !rewind($handle)) {
throw new \RuntimeException('Could not prepare LibreSign callback backup for storage');
}

$csv = stream_get_contents($handle);
if ($csv === false || strlen($csv) !== $bytes) {
throw new \RuntimeException('Could not read LibreSign callback backup buffer');
}

// Nextcloud closes resources passed to newFile(); pass a string instead
// so this method retains ownership of the buffer until finally.
$folder = $this->appData->getFolder('/');
$file = $folder->newFile(self::FILE_BACKUP, $csv);
if ($file->getSize() != $bytes) {
throw new \RuntimeException('Could not verify LibreSign callback backup size');
}
$output->info(
'Legacy callback destinations saved to appdata_<instanceid>/libresign/'
. self::FILE_BACKUP . ' (may contain credentials; restrict access).',
);
} finally {
fclose($handle);
}
} finally {
$result->closeCursor();
}
}

private function backupLegacyWebhookUrl(IOutput $output): void {
if (!in_array('webhook_sign_url', $this->appConfig->getKeys(Application::APP_ID), true)) {
return;
}

$url = $this->appConfig->getValueString(Application::APP_ID, 'webhook_sign_url');
if ($url === '') {
return;
}

$content = json_encode(['webhook_sign_url' => $url], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$folder = $this->appData->getFolder('/');
$file = $folder->newFile(self::CONFIG_BACKUP, $content);
if ($file->getSize() != strlen($content)) {
throw new \RuntimeException('Could not verify LibreSign webhook URL backup size');
}
$output->info(
'Legacy webhook URL saved to appdata_<instanceid>/libresign/'
. self::CONFIG_BACKUP . ' (may contain credentials; restrict access).',
);
}

/** @param Closure(): ISchemaWrapper $schemaClosure */
#[\Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();
if (!$schema->hasTable('libresign_file')) {
return null;
}

$table = $schema->getTable('libresign_file');
if (!$table->hasColumn('callback')) {
return null;
}

$table->dropColumn('callback');
return $schema;
}

/** @param Closure(): ISchemaWrapper $schemaClosure */
#[\Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
if (in_array('webhook_sign_url', $this->appConfig->getKeys(Application::APP_ID), true)) {
$this->appConfig->deleteKey(Application::APP_ID, 'webhook_sign_url');
}
}
}
1 change: 0 additions & 1 deletion lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@
* signedNodeId: non-negative-int,
* url: string,
* },
* callback: ?string,
* uuid: string,
* signers: list<LibresignSignerDetail>,
* },
Expand Down
4 changes: 0 additions & 4 deletions lib/Service/RequestSignatureService.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ private function createFileForEnvelope(
* userManager?: IUser,
* signRequest?: SignRequestEntity,
* name?: string,
* callback?: string,
* uuid?: ?string,
* status?: int,
* parentFileId?: int,
Expand Down Expand Up @@ -481,9 +480,6 @@ private function persistFile(array $data, ?Node $createdNode = null): array {
}
$file->setName($this->removeExtensionFromName($name, $metadata));
$file->setMetadata($metadata);
if (!empty($data['callback'])) {
$file->setCallback($data['callback']);
}
if (isset($data['status'])) {
$file->setStatus($data['status']);
} else {
Expand Down
2 changes: 0 additions & 2 deletions lib/Service/RequestSignatureWorkflowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function createRequest(
array $settings,
array $signers,
?int $status,
?string $callback,
?array $policy = null,
?array $visibleElements = null,
): array {
Expand All @@ -75,7 +74,6 @@ public function createRequest(
'file' => $file,
'name' => $name,
'signers' => $signers,
'callback' => $callback,
'userManager' => $user,
'policyOverrides' => $resolvedPolicy['policyOverrides'],
'policyActiveContext' => $resolvedPolicy['policyActiveContext'],
Expand Down
31 changes: 0 additions & 31 deletions lib/Service/SignFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Exception;
use InvalidArgumentException;
use OC\AppFramework\Http as AppFrameworkHttp;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\BackgroundJob\SignSingleFileJob;
use OCA\Libresign\DataObjects\VisibleElementAssoc;
use OCA\Libresign\Db\File as FileEntity;
Expand Down Expand Up @@ -63,7 +62,6 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\NotPermittedException;
use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IDateTimeZone;
use OCP\IL10N;
Expand Down Expand Up @@ -105,7 +103,6 @@ public function __construct(
private IdDocsMapper $idDocsMapper,
private FooterHandler $footerHandler,
protected FolderService $folderService,
private IClientService $client,
protected LoggerInterface $logger,
private IAppConfig $appConfig,
protected IdentityDocumentValidator $identityDocumentValidator,
Expand Down Expand Up @@ -179,34 +176,6 @@ public function canDeleteRequestSignature(array $data): void {
});
}

public function notifyCallback(File $file): void {
$uri = $this->libreSignFile->getCallback();
if (!$uri) {
$uri = $this->appConfig->getValueString(Application::APP_ID, 'webhook_sign_url');
if (!$uri) {
return;
}
}
$options = [
'multipart' => [
[
'name' => 'uuid',
'contents' => $this->libreSignFile->getUuid(),
],
[
'name' => 'status',
'contents' => $this->libreSignFile->getStatus(),
],
[
'name' => 'file',
'contents' => $file->fopen('r'),
'filename' => $file->getName()
]
]
];
$this->client->newClient()->post($uri, $options);
}

/**
* @return static
*/
Expand Down
Loading
Loading