Skip to content
Open
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
8 changes: 8 additions & 0 deletions lib/private/Sharing/SharingBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,10 @@ public function ensureDefaults(array $shares): array {

$defaultSet = false;
foreach ($shares as &$share) {
if ($share->owner->instance !== null) {
continue;
}

$shareSourceTypeClasses = array_map(fn (ShareSource $source): string => $source->class, $share->sources);
$shareRecipientTypeClasses = array_map(fn (ShareRecipient $recipient): string => $recipient->class, $share->recipients);
$shareCompatiblePropertyClasses = $this->registry->getCompatiblePropertyTypeClasses($shareSourceTypeClasses, $shareRecipientTypeClasses);
Expand All @@ -1272,6 +1276,10 @@ public function ensureDefaults(array $shares): array {
}

foreach ($shares as &$share) {
if ($share->owner->instance !== null) {
continue;
}

$shareCompatiblePermissionTypeClasses = $this->getShareCompatiblePermissionTypeClasses($share->sources);

foreach ($shareCompatiblePermissionTypeClasses as $permissionTypeClass) {
Expand Down
32 changes: 29 additions & 3 deletions lib/private/Sharing/SharingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public function onOwnerDeleted(ShareAccessContext $accessContext, ShareUser $own

#[\Override]
public function updateShareState(ShareAccessContext $accessContext, Share $share, ShareState $state): Share {
$this->assertLocalShare($share);

$time = $this->getTime();
$this->backend->setLastUpdated([$share->id], $time);

Expand Down Expand Up @@ -232,6 +234,8 @@ public function updateShareState(ShareAccessContext $accessContext, Share $share

#[\Override]
public function updateShareUserStatus(ShareAccessContext $accessContext, Share $share, ShareUserStatus $userStatus): Share {
$this->assertLocalShare($share);

if (!($currentUser = $accessContext->currentUser) instanceof IUser) {
throw new RuntimeException('No user present to update share status for.');
}
Expand Down Expand Up @@ -269,9 +273,7 @@ public function updateShareUserStatus(ShareAccessContext $accessContext, Share $

#[\Override]
public function addShareSource(ShareAccessContext $accessContext, Share $share, ShareSource $source): Share {
if ($share->owner->instance !== null) {
throw new ShareOperationForbiddenException();
}
$this->assertLocalShare($share);

// only the owner can add sources, otherwise a user could add sources others don't have access to, which would remove their access
$this->validateShareEditPermissions($accessContext, $share, true);
Expand Down Expand Up @@ -328,6 +330,8 @@ public function addShareSource(ShareAccessContext $accessContext, Share $share,

#[\Override]
public function removeShareSource(ShareAccessContext $accessContext, Share $share, ShareSource $source): Share {
$this->assertLocalShare($share);

// only the owner can remove sources, to mirror the "add source" permissions
$this->validateShareEditPermissions($accessContext, $share, true);

Expand Down Expand Up @@ -389,6 +393,8 @@ public function onSourceDeleted(ShareAccessContext $accessContext, ShareSource $

#[\Override]
public function addShareRecipient(ShareAccessContext $accessContext, Share $share, ShareRecipient $recipient): Share {
$this->assertLocalShare($share);

if (!($currentUser = $accessContext->currentUser) instanceof IUser) {
throw new RuntimeException('No current user provided in access context.');
}
Expand Down Expand Up @@ -477,6 +483,8 @@ public function addShareRecipient(ShareAccessContext $accessContext, Share $shar

#[\Override]
public function removeShareRecipient(ShareAccessContext $accessContext, Share $share, ShareRecipient $recipient): Share {
$this->assertLocalShare($share);

try {
$this->validateShareEditPermissions($accessContext, $share);
} catch (ShareOperationForbiddenException) {
Expand Down Expand Up @@ -566,6 +574,8 @@ private function validateShareSecret(string $secret): bool {

#[\Override]
public function updateShareRecipientSecret(ShareAccessContext $accessContext, Share $share, ShareRecipient $recipient, string $secret): Share {
$this->assertLocalShare($share);

try {
$this->validateShareEditPermissions($accessContext, $share);
} catch (ShareOperationForbiddenException) {
Expand Down Expand Up @@ -629,6 +639,8 @@ public function updateShareRecipientSecret(ShareAccessContext $accessContext, Sh

#[\Override]
public function updateShareProperty(ShareAccessContext $accessContext, Share $share, ShareProperty $property): Share {
$this->assertLocalShare($share);

$this->validateShareEditPermissions($accessContext, $share);

if (($propertyType = $this->registry->getPropertyTypes()[$property->class] ?? null) === null) {
Expand Down Expand Up @@ -679,6 +691,8 @@ public function updateShareProperty(ShareAccessContext $accessContext, Share $sh

#[\Override]
public function updateSharePermission(ShareAccessContext $accessContext, Share $share, SharePermission $permission): Share {
$this->assertLocalShare($share);

$this->validateShareEditPermissions($accessContext, $share);

if (!isset($this->registry->getPermissionTypes()[$permission->class])) {
Expand Down Expand Up @@ -722,6 +736,8 @@ public function updateSharePermission(ShareAccessContext $accessContext, Share $

#[\Override]
public function updateShareRecipientPermission(ShareAccessContext $accessContext, Share $share, ShareRecipient $recipient, SharePermission $permission): Share {
$this->assertLocalShare($share);

$time = $this->getTime();
$this->backend->setLastUpdated([$share->id], $time);

Expand Down Expand Up @@ -786,6 +802,8 @@ public function updateShareRecipientPermission(ShareAccessContext $accessContext

#[\Override]
public function selectSharePermissionPreset(ShareAccessContext $accessContext, Share $share, string $permissionPresetClass): Share {
$this->assertLocalShare($share);

$this->validateShareEditPermissions($accessContext, $share);

if (($this->registry->getPermissionPresetCompatiblePermissionTypeClasses()[$permissionPresetClass] ?? null) === null) {
Expand Down Expand Up @@ -829,6 +847,8 @@ public function selectSharePermissionPreset(ShareAccessContext $accessContext, S

#[\Override]
public function deleteShare(ShareAccessContext $accessContext, Share $share): void {
// Deleting a remote share is allowed.

// No need to update the last updated timestamp, because the share will be deleted anyway.

$this->validateShareEditPermissions($accessContext, $share);
Expand Down Expand Up @@ -1088,4 +1108,10 @@ public static function timeToMs(\DateTimeImmutable $time): string {

throw new \RuntimeException('invalid date-time');
}

private function assertLocalShare(Share $share): void {
if ($share->owner->instance !== null) {
throw new RuntimeException('The SharingManager can only modify local shares.');
}
}
}
12 changes: 1 addition & 11 deletions tests/lib/Sharing/AbstractSharingManagerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,17 +767,7 @@ public function testCreateShareRemoteOwner(): void {
'sources' => [],
'recipients' => [],
'properties' => [],
'permissions' => [
[
'class' => ReshareSharePermissionType::class,
'source_class' => null,
'display_name' => 'Share with others',
'hint' => null,
'presets' => [],
'enabled' => false,
'priority' => 90,
],
],
'permissions' => [],
'permission_preset' => null,
], $share);
}
Expand Down
Loading