-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(encryption): Migrate from hooks to events #48560
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
536ccf1
feat(encryption): Migrate from hooks to events
come-nc 38f341c
fix(tests): Unregister encryption modules in ViewTest to avoid side e…
come-nc 21233b7
fix(tests): Remove Encryption disabling in ViewTest to avoid side eff…
come-nc 8779ae3
fix(encryption): Fix filesize for part files in Encryption wrapper
come-nc 9bb0721
fix: Fix mtime preservation when moving a directory across storages w…
come-nc e35a8ed
fix(tests): Disable encryption wrapper when it makes sense
come-nc 14872c8
chore(files_versions): Only mock getSystemValue method to avoid probl…
come-nc 561b590
chore(trashbin): Fix configuration mocking in trashbin tests
come-nc f6f8343
chore: Update psalm baseline to remove fixed issue
come-nc 367c877
fix(tests): Avoid user login before a private key is setup
come-nc 08bff4c
fix(admin_audit): Survive if file change id after rename (it should not)
come-nc 27599ef
fix(encryption): Fix a PHP error in Encryption Util in specific situa…
come-nc e6275f8
fix: Preserve file id when moving from object store even if encryptio…
come-nc 2d8f6b3
chore: Assert rename success in versionning tests
come-nc a79b5de
fix(encryption): Improve Update class and event listenening
come-nc a86d917
fix(encryption): Only prevent cache deletion if target is not object …
come-nc 43418ee
fix(tests): Set encryption configuration even earlier so that all use…
come-nc 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 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| */ | ||
|
|
||
| namespace OC\Encryption; | ||
|
|
||
| use OC\Files\SetupManager; | ||
| use OC\Files\View; | ||
| use OCA\Files_Trashbin\Events\NodeRestoredEvent; | ||
| use OCP\Encryption\IFile; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventDispatcher; | ||
| use OCP\EventDispatcher\IEventListener; | ||
| use OCP\Files\Events\Node\NodeRenamedEvent; | ||
| use OCP\IUser; | ||
| use OCP\IUserSession; | ||
| use OCP\Share\Events\ShareCreatedEvent; | ||
| use OCP\Share\Events\ShareDeletedEvent; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| /** @template-implements IEventListener<NodeRenamedEvent|ShareCreatedEvent|ShareDeletedEvent|NodeRestoredEvent> */ | ||
| class EncryptionEventListener implements IEventListener { | ||
| private ?Update $updater = null; | ||
|
|
||
| public function __construct( | ||
| private IUserSession $userSession, | ||
| private SetupManager $setupManager, | ||
| private Manager $encryptionManager, | ||
| ) { | ||
| } | ||
|
|
||
| public static function register(IEventDispatcher $dispatcher): void { | ||
| $dispatcher->addServiceListener(NodeRenamedEvent::class, static::class); | ||
| $dispatcher->addServiceListener(ShareCreatedEvent::class, static::class); | ||
| $dispatcher->addServiceListener(ShareDeletedEvent::class, static::class); | ||
| $dispatcher->addServiceListener(NodeRestoredEvent::class, static::class); | ||
| } | ||
|
|
||
| public function handle(Event $event): void { | ||
| if (!$this->encryptionManager->isEnabled()) { | ||
| return; | ||
| } | ||
| if ($event instanceof NodeRenamedEvent) { | ||
| $this->getUpdate()->postRename($event->getSource(), $event->getTarget()); | ||
| } elseif ($event instanceof ShareCreatedEvent) { | ||
| $this->getUpdate()->postShared($event->getShare()->getNode()); | ||
| } elseif ($event instanceof ShareDeletedEvent) { | ||
| // In case the unsharing happens in a background job, we don't have | ||
| // a session and we load instead the user from the UserManager | ||
| $owner = $event->getShare()->getNode()->getOwner(); | ||
| $this->getUpdate($owner)->postUnshared($event->getShare()->getNode()); | ||
| } elseif ($event instanceof NodeRestoredEvent) { | ||
| $this->getUpdate()->postRestore($event->getTarget()); | ||
| } | ||
| } | ||
|
|
||
| private function getUpdate(?IUser $owner = null): Update { | ||
| if (is_null($this->updater)) { | ||
| $user = $this->userSession->getUser(); | ||
| if (!$user && ($owner !== null)) { | ||
| $user = $owner; | ||
| } | ||
| if (!$user) { | ||
| throw new \Exception('Inconsistent data, File unshared, but owner not found. Should not happen'); | ||
| } | ||
|
|
||
| $uid = $user->getUID(); | ||
|
|
||
| if (!$this->setupManager->isSetupComplete($user)) { | ||
| $this->setupManager->setupForUser($user); | ||
| } | ||
|
|
||
| $this->updater = new Update( | ||
| new Util( | ||
| new View(), | ||
| \OC::$server->getUserManager(), | ||
| \OC::$server->getGroupManager(), | ||
| \OC::$server->getConfig()), | ||
| \OC::$server->getEncryptionManager(), | ||
| \OC::$server->get(IFile::class), | ||
| \OC::$server->get(LoggerInterface::class), | ||
| $uid | ||
| ); | ||
| } | ||
|
|
||
| return $this->updater; | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
Server::get?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
But at this point I’m stuck on the failure of https://github.com/nextcloud/server/actions/runs/14195485740/job/39769612916?pr=48560
I do not understand what’s happening.
I pulled ed6e1ec to fix some other tests and it broke this one. I do not understand why it’s failing and why specifically for s3, while it was passing without encryption wrapper.