Repository navigation
refactor: remove proprietary callbacks in favor of native Nextcloud webhooks #9426
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
Merged
vitormattos
merged 11 commits into
main
from
refactor/remove-legacy-callback-nextcloud-webhooks
Nov 14, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2981b23
refactor: remove proprietary signing callbacks from development API
vitormattos 5fb64c4
refactor: drop legacy callback storage and configuration on upgrade
vitormattos 17041cd
test: align removed callback with Nextcloud schema mocks and TypeScri…
vitormattos 9b9f8b4
test: align callback rejection tests with OpenAPI contract
vitormattos a005e8f
fix(migration): preserve legacy callback destinations before removal
vitormattos f3ff1b0
refactor(api): remove redundant legacy callback rejection
vitormattos 35ebfb2
fix(migration): back up only populated callback values and row IDs
vitormattos 7c10024
fix(migration): preserve callback backups across databases and verify…
vitormattos c01bf25
test(migration): cover synchronous backup storage and truncation
vitormattos 661fe46
fix: avoid double-closing callback backup stream
vitormattos 70ae26b
chore(openapi): regenerate callback-free API contracts on current main
vitormattos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.