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
1 change: 1 addition & 0 deletions apps/sharing/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
'OCA\\Sharing\\Migration\\Version1000Date20260826073021' => $baseDir . '/../lib/Migration/Version1000Date20260826073021.php',
'OCA\\Sharing\\Migration\\Version1000Date20260826115938' => $baseDir . '/../lib/Migration/Version1000Date20260826115938.php',
'OCA\\Sharing\\Migration\\Version1000Date20260826122228' => $baseDir . '/../lib/Migration/Version1000Date20260826122228.php',
'OCA\\Sharing\\Migration\\Version2000Date20261013142538' => $baseDir . '/../lib/Migration/Version2000Date20261013142538.php',
'OCA\\Sharing\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
);
1 change: 1 addition & 0 deletions apps/sharing/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ComposerStaticInitSharing
'OCA\\Sharing\\Migration\\Version1000Date20260826073021' => __DIR__ . '/..' . '/../lib/Migration/Version1000Date20260826073021.php',
'OCA\\Sharing\\Migration\\Version1000Date20260826115938' => __DIR__ . '/..' . '/../lib/Migration/Version1000Date20260826115938.php',
'OCA\\Sharing\\Migration\\Version1000Date20260826122228' => __DIR__ . '/..' . '/../lib/Migration/Version1000Date20260826122228.php',
'OCA\\Sharing\\Migration\\Version2000Date20261013142538' => __DIR__ . '/..' . '/../lib/Migration/Version2000Date20261013142538.php',
'OCA\\Sharing\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
);

Expand Down
49 changes: 49 additions & 0 deletions apps/sharing/lib/Migration/Version2000Date20261013142538.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Sharing\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

final class Version2000Date20261013142538 extends SimpleMigrationStep {
#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();
$shareTable = $schema->getTable('sharing_share');
$userStatusTable = $schema->getTable('sharing_share_user_status');
$changed = false;

if ($shareTable->hasColumn('state')) {
$shareTable->dropColumn('state');
$changed = true;
}

if (!$shareTable->hasColumn('state_id')) {
$shareTable->addColumn('state_id', Types::INTEGER);
$changed = true;
}

if ($userStatusTable->hasColumn('status')) {
$userStatusTable->dropColumn('status');
$changed = true;
}

if (!$userStatusTable->hasColumn('status_id')) {
$userStatusTable->addColumn('status_id', Types::INTEGER);
$changed = true;
}

return $changed ? $schema : null;
}
}
29 changes: 14 additions & 15 deletions lib/private/Sharing/SharingBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function createShare(string $id, ShareUser $owner, \DateTimeImmutable $la
'owner_user_id' => $qb->createNamedParameter($owner->userId),
'owner_instance' => $qb->createNamedParameter($owner->instance),
'last_updated' => $qb->createNamedParameter(SharingManager::timeToMs($lastUpdated)),
'state' => $qb->createNamedParameter(ShareState::Draft->value),
'state_id' => $qb->createNamedParameter(ShareState::Draft->encode(), IQueryBuilder::PARAM_INT),
])
->executeStatement();
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public function updateShareState(string $id, ShareState $state): void {
$qb = $this->connection->getQueryBuilder();
$rowCount = $qb
->update('sharing_share')
->set('state', $qb->createNamedParameter($state->value))
->set('state_id', $qb->createNamedParameter($state->encode(), IQueryBuilder::PARAM_INT))
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->executeStatement();
if ($rowCount === 0) {
Expand All @@ -134,7 +134,7 @@ public function updateShareUserStatus(string $id, string $userId, ShareUserStatu
$qb = $this->connection->getQueryBuilder();
$rowCount = $qb
->update('sharing_share_user_status')
->set('status', $qb->createNamedParameter($userStatus->value))
->set('status_id', $qb->createNamedParameter($userStatus->encode(), IQueryBuilder::PARAM_INT))
->where($qb->expr()->eq('share_id', $qb->createNamedParameter($id)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
->executeStatement();
Expand All @@ -145,7 +145,7 @@ public function updateShareUserStatus(string $id, string $userId, ShareUserStatu
->values([
'share_id' => $qb->createNamedParameter($id),
'user_id' => $qb->createNamedParameter($userId),
'status' => $qb->createNamedParameter($userStatus->value),
'status_id' => $qb->createNamedParameter($userStatus->encode(), IQueryBuilder::PARAM_INT),
])
->executeStatement();
}
Expand Down Expand Up @@ -695,7 +695,7 @@ private function list(
$qb = $this->connection->getQueryBuilder();
$qb->innerJoin(
's', 'sharing_share_recipients', 'sr', $qb->expr()->andX(
$qb->expr()->eq('s.state', $qb->createNamedParameter(ShareState::Active->value)),
$qb->expr()->eq('s.state_id', $qb->createNamedParameter(ShareState::Active->encode())),
$qb->expr()->eq('s.id', 'sr.share_id'),
)
);
Expand All @@ -721,7 +721,7 @@ private function list(
$qb = $this->connection->getQueryBuilder();
$qb->innerJoin(
's', 'sharing_share_recipients', 'sr', $qb->expr()->andX(
$qb->expr()->eq('s.state', $qb->createNamedParameter(ShareState::Active->value)),
$qb->expr()->eq('s.state_id', $qb->createNamedParameter(ShareState::Active->encode())),
$qb->expr()->eq('s.id', 'sr.share_id'),
$qb->expr()->eq('sr.recipient_secret', $qb->createNamedParameter($accessContext->secret)),
)
Expand All @@ -741,7 +741,7 @@ private function list(
's.owner_user_id',
's.owner_instance',
's.last_updated',
's.state',
's.state_id',
)
->from('sharing_share', 's')
->orderBy('s.id', 'ASC');
Expand All @@ -766,7 +766,7 @@ private function list(
}

if ($filterState instanceof \NCU\Sharing\ShareState) {
$qb->andWhere($qb->expr()->eq('s.state', $qb->createNamedParameter($filterState->value)));
$qb->andWhere($qb->expr()->eq('s.state_id', $qb->createNamedParameter($filterState->encode())));
}

if ($lastShareID !== null) {
Expand Down Expand Up @@ -796,13 +796,12 @@ private function list(
$shareId = (string)$row['id'];
/** @var numeric-string $lastUpdated */
$lastUpdated = (string)$row['last_updated'];
/** @var string $state */
$state = $row['state'];
$state = (int)$row['state_id'];
$shares[$shareId] ??= [
'id' => $shareId,
'owner' => new ShareUser($ownerUserId, $ownerInstance),
'last_updated' => $lastUpdated,
'state' => ShareState::from($state),
'state' => ShareState::decode($state),
'user_status' => null,
'sources' => [],
'recipients' => [],
Expand Down Expand Up @@ -831,18 +830,18 @@ private function list(

$qb = $this->connection->getQueryBuilder();
$qb
->select('share_id', 'status')
->select('share_id', 'status_id')
->from('sharing_share_user_status')
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($accessContext->currentUser->getUID())))
->andWhere($qb->expr()->in('share_id', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)));

$result = $qb->executeQuery();
/** @var list<array{share_id: int|string, status: string}> $rows */
/** @var list<array{share_id: int|string, status_id: int|string}> $rows */
$rows = $result->fetchAll();
foreach ($rows as $row) {
$id = $row['share_id'];
$userStatus = $row['status'];
$shares[$id]['user_status'] = ShareUserStatus::from($userStatus);
$userStatus = (int)$row['status_id'];
$shares[$id]['user_status'] = ShareUserStatus::decode($userStatus);
}

foreach ($chunk as $id) {
Expand Down
23 changes: 23 additions & 0 deletions lib/unstable/Sharing/ShareState.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,27 @@ enum ShareState: string {
* @experimental 35.0.0
*/
case Deleted = 'deleted';

/**
* @experimental 35.0.0
*/
public function encode(): int {
return match ($this) {
self::Active => 1,
self::Draft => 2,
self::Deleted => 3,
};
}

/**
* @experimental 35.0.0
*/
public static function decode(int $value): self {
return match ($value) {
1 => self::Active,
2 => self::Draft,
3 => self::Deleted,
default => throw new \ValueError('Invalid share state ' . $value)
};
}
}
23 changes: 23 additions & 0 deletions lib/unstable/Sharing/ShareUserStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,27 @@ enum ShareUserStatus: string {
* @experimental 35.0.0
*/
case Rejected = 'rejected';

/**
* @experimental 35.0.0
*/
public function encode(): int {
return match ($this) {
self::Pending => 1,
self::Accepted => 2,
self::Rejected => 3,
};
}

/**
* @experimental 35.0.0
*/
public static function decode(int $value): self {
return match ($value) {
1 => self::Pending,
2 => self::Accepted,
3 => self::Rejected,
default => throw new \ValueError('Invalid user share status ' . $value)
};
}
}
Loading