-
-
Notifications
You must be signed in to change notification settings - Fork 5k
feat(share): add ShareReviewAccessCheckEvent to OCP public API #61543
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
Open
AndyScherzinger
wants to merge
1
commit into
master
Choose a base branch
from
feat/noid/shareReviewDeleteEvent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−0
Open
Changes from all commits
Commits
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
130 changes: 130 additions & 0 deletions
130
lib/public/Share/Events/ShareReviewAccessCheckEvent.php
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,130 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCP\Share\Events; | ||
|
|
||
| use OCP\AppFramework\Attribute\Consumable; | ||
| use OCP\EventDispatcher\Event; | ||
|
|
||
| /** | ||
| * Authorization gate event dispatched by a ShareReview source before deleting | ||
| * an app-managed share on behalf of a ShareReview operator. | ||
| * | ||
| * Usage — dispatch and check: | ||
| * | ||
| * $event = new ShareReviewAccessCheckEvent('MyApp', $shareId); | ||
| * $dispatcher->dispatchTyped($event); | ||
| * if (!$event->isHandled() || !$event->isGranted()) { | ||
| * return false; // default-deny: no listener means no access | ||
| * } | ||
| * | ||
| * Semantics: | ||
| * - Default-deny: an unhandled event blocks the deletion. | ||
| * - Deny wins: once denyAccess() is called, further grantAccess() calls are | ||
| * ignored and propagation is stopped immediately. | ||
| * - Multiple grants are harmless; the last listener to deny is authoritative. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| #[Consumable(since: '34.0.2')] | ||
| class ShareReviewAccessCheckEvent extends Event { | ||
|
|
||
| private bool $handled = false; | ||
| private bool $granted = false; | ||
| private ?string $reason = null; | ||
|
|
||
| /** | ||
| * @param string $sourceName Stable, non-translated identifier for the app | ||
| * registering the share source (e.g. 'Deck', 'Tables'). | ||
| * @param string $shareId App-internal identifier of the share being deleted. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function __construct( | ||
| private readonly string $sourceName, | ||
| private readonly string $shareId, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * Stable, non-translated identifier of the app that owns this share source. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function getSourceName(): string { | ||
| return $this->sourceName; | ||
| } | ||
|
|
||
| /** | ||
| * App-internal identifier of the share being deleted. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function getShareId(): string { | ||
| return $this->shareId; | ||
| } | ||
|
|
||
| /** | ||
| * Grant access to delete the share. | ||
| * | ||
| * Has no effect if denyAccess() was already called on this event — deny wins. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function grantAccess(): void { | ||
| if ($this->handled && !$this->granted) { | ||
| return; // deny wins — a prior denyAccess() cannot be escalated to a grant | ||
| } | ||
| $this->handled = true; | ||
| $this->granted = true; | ||
| } | ||
|
|
||
| /** | ||
| * Deny access and provide a human-readable reason. | ||
| * | ||
| * Stops event propagation immediately — no further listeners will run. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function denyAccess(string $reason): void { | ||
| $this->handled = true; | ||
| $this->granted = false; | ||
| $this->reason = $reason; | ||
| $this->stopPropagation(); | ||
| } | ||
|
|
||
| /** | ||
| * Whether any listener has responded to this event. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function isHandled(): bool { | ||
| return $this->handled; | ||
| } | ||
|
|
||
| /** | ||
| * Whether access was granted. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function isGranted(): bool { | ||
| return $this->granted; | ||
| } | ||
|
|
||
| /** | ||
| * Human-readable denial reason, or null if access was granted or the event | ||
| * has not been handled yet. | ||
| * | ||
| * @since 34.0.2 | ||
| */ | ||
| public function getReason(): ?string { | ||
| return $this->reason; | ||
| } | ||
| } | ||
96 changes: 96 additions & 0 deletions
96
tests/lib/Share20/Events/ShareReviewAccessCheckEventTest.php
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,96 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace lib\Share20\Events; | ||
|
|
||
| use OCP\Share\Events\ShareReviewAccessCheckEvent; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| final class ShareReviewAccessCheckEventTest extends TestCase { | ||
|
|
||
| private function makeEvent(): ShareReviewAccessCheckEvent { | ||
| return new ShareReviewAccessCheckEvent('MyApp', '42'); | ||
| } | ||
|
|
||
| public function testInitialState(): void { | ||
| $event = $this->makeEvent(); | ||
|
|
||
| $this->assertFalse($event->isHandled()); | ||
| $this->assertFalse($event->isGranted()); | ||
| $this->assertNull($event->getReason()); | ||
| } | ||
|
|
||
| public function testConstructorPayload(): void { | ||
| $event = new ShareReviewAccessCheckEvent('Deck', '99'); | ||
|
|
||
| $this->assertSame('Deck', $event->getSourceName()); | ||
| $this->assertSame('99', $event->getShareId()); | ||
| } | ||
|
|
||
| public function testGrantAccess(): void { | ||
| $event = $this->makeEvent(); | ||
| $event->grantAccess(); | ||
|
|
||
| $this->assertTrue($event->isHandled()); | ||
| $this->assertTrue($event->isGranted()); | ||
| $this->assertNull($event->getReason()); | ||
| $this->assertFalse($event->isPropagationStopped()); | ||
| } | ||
|
|
||
| public function testDenyAccess(): void { | ||
| $event = $this->makeEvent(); | ||
| $event->denyAccess('not in group'); | ||
|
|
||
| $this->assertTrue($event->isHandled()); | ||
| $this->assertFalse($event->isGranted()); | ||
| $this->assertSame('not in group', $event->getReason()); | ||
| } | ||
|
|
||
| public function testDenyStopsPropagation(): void { | ||
| $event = $this->makeEvent(); | ||
| $event->denyAccess('no access'); | ||
|
|
||
| $this->assertTrue($event->isPropagationStopped()); | ||
| } | ||
|
|
||
| public function testGrantDoesNotStopPropagation(): void { | ||
| $event = $this->makeEvent(); | ||
| $event->grantAccess(); | ||
|
|
||
| $this->assertFalse($event->isPropagationStopped()); | ||
| } | ||
|
|
||
| public function testGrantThenDenyIsDenied(): void { | ||
| $event = $this->makeEvent(); | ||
| $event->grantAccess(); | ||
| $event->denyAccess('revoked'); | ||
|
|
||
| $this->assertFalse($event->isGranted()); | ||
| $this->assertSame('revoked', $event->getReason()); | ||
| $this->assertTrue($event->isPropagationStopped()); | ||
| } | ||
|
|
||
| public function testDenyThenGrantRemainesDenied(): void { | ||
| $event = $this->makeEvent(); | ||
| $event->denyAccess('not allowed'); | ||
| $event->grantAccess(); // must be ignored — deny wins | ||
|
|
||
| $this->assertFalse($event->isGranted()); | ||
| $this->assertSame('not allowed', $event->getReason()); | ||
| } | ||
|
|
||
| public function testMultipleGrantsAreIdempotent(): void { | ||
| $event = $this->makeEvent(); | ||
| $event->grantAccess(); | ||
| $event->grantAccess(); | ||
|
|
||
| $this->assertTrue($event->isGranted()); | ||
| $this->assertFalse($event->isPropagationStopped()); | ||
| } | ||
| } |
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.