Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b8ab84f
fix(Sharing): Fix event listeners with ghosts
provokateurin Nov 11, 2026
40869c5
refactor(Sharing): Tighten more types
provokateurin Nov 2, 2026
ac7453f
refactor(files_sharing): Set expiration date time to 23:59:59 only in…
provokateurin Sep 30, 2026
8582ba8
feat(IShare): Add getProviderId()
provokateurin Sep 2, 2026
c3ca67b
feat(Share20): Dispatch ShareUpdatedEvent and ShareRestoredEvent
provokateurin Sep 2, 2026
0780251
feat(OCP\Share\Events): Add setters for the share property
provokateurin Sep 23, 2026
2f4f3b8
feat(SharingManager): Dispatch SharesUpdatedEvent and SharesDeletedEvent
provokateurin Sep 2, 2026
891a8be
feat(DefaultShareProvider): Allow fetching shares of TYPE_USERGROUP
provokateurin Sep 23, 2026
b88c5b0
feat(ITeamManager): Allow calling getMembersOfTeam() without a user
provokateurin Sep 10, 2026
ad52e64
feat(IShareRecipientType): Add getUsers()
provokateurin Sep 10, 2026
4366fdb
feat(Sharing): Add node source target management
provokateurin Sep 10, 2026
07892c3
refactor(ISharePropertyTypeModifyValue): Modify values on format inst…
provokateurin Sep 21, 2026
d86be3b
refactor(ISharePropertyTypeModifyValue): Modify values on save in the…
provokateurin Nov 3, 2026
f070496
feat(Share): Add getCreatedAt() method
provokateurin Sep 23, 2026
e52ee50
feat(ISharingBackend): Add getUserStatuses() method
provokateurin Sep 23, 2026
90cb1d0
feat(files): Add NodeNicknameSharePropertyType
provokateurin Oct 13, 2026
930d76e
fix(ShareByMailProvider): Set share status from DB
provokateurin Oct 13, 2026
d2f4217
fix(Share20): Fix setting target before and after the share is create…
provokateurin Oct 27, 2026
ffdcc59
fix(FederatedShareProvider): Use existing share time and token if ava…
provokateurin Oct 27, 2026
2a5e238
refactor(Share): Allow checking effective enabled permissions for exp…
provokateurin Oct 27, 2026
f2bf3ec
feat(Sharing): Implement bi-directional syncing with legacy sharing
provokateurin Sep 23, 2026
54ed407
test(integration): Enable Unified Sharing legacy sync validation
provokateurin Sep 23, 2026
de07613
chore(Sharing): Remove outdated TODOs
provokateurin Oct 13, 2026
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
22 changes: 17 additions & 5 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

namespace OCA\FederatedFileSharing;

use DateTime;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Share;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Federation\ICloudFederationProviderManager;
Expand Down Expand Up @@ -61,6 +63,7 @@ public function __construct(
private \OCP\GlobalScale\IConfig $gsConfig,
private ICloudFederationProviderManager $cloudFederationProviderManager,
private LoggerInterface $logger,
private ITimeFactory $timeFactory,
) {
}

Expand Down Expand Up @@ -140,7 +143,11 @@ public function create(IShare $share): IShare {

if ($remoteShare) {
$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time(), $shareType, $expirationDate);
$token = $share->getToken();
if ($token === null || $token === '') {
$token = 'tmp_token_' . time();
}
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, $token, $shareType, $expirationDate, $share->getShareTime() ?? \DateTime::createFromImmutable($this->timeFactory->now()));
[$token, $remoteId] = $this->notifications->requestReShare(
$remoteShare['refresh_token'],
$remoteShare['remote_id'],
Expand Down Expand Up @@ -175,7 +182,11 @@ public function create(IShare $share): IShare {
* @throws \Exception
*/
protected function createFederatedShare(IShare $share): string {
$token = $this->tokenHandler->generateToken();
$token = $share->getToken();
if ($token === null || $token === '') {
$token = $this->tokenHandler->generateToken();
}

$shareId = $this->addShareToDB(
$share->getNodeId(),
$share->getNodeType(),
Expand All @@ -185,7 +196,8 @@ protected function createFederatedShare(IShare $share): string {
$share->getPermissions(),
$token,
$share->getShareType(),
$share->getExpirationDate()
$share->getExpirationDate(),
$share->getShareTime() ?? \DateTime::createFromImmutable($this->timeFactory->now()),
);

$failure = false;
Expand Down Expand Up @@ -266,7 +278,7 @@ protected function getShareFromExternalShareTable(string $owner, string $target)
* @param int $shareType
* @param \DateTime $expirationDate
*/
private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $shareType, $expirationDate): string {
private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $shareType, $expirationDate, DateTime $shareTime): string {
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter($shareType))
Expand All @@ -279,7 +291,7 @@ private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ui
->setValue('permissions', $qb->createNamedParameter($permissions))
->setValue('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATETIME_MUTABLE))
->setValue('token', $qb->createNamedParameter($token))
->setValue('stime', $qb->createNamedParameter(time()));
->setValue('stime', $qb->createNamedParameter($shareTime->getTimestamp()));

/*
* Added to fix https://github.com/owncloud/core/issues/22215
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
use OCP\DB\IResult;
use OCP\DB\QueryBuilder\IExpressionBuilder;
Expand All @@ -29,6 +30,7 @@
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\Server;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -77,6 +79,7 @@ protected function setUp(): void {
$this->gsConfig,
$this->cloudFederationProviderManager,
$this->logger,
Server::get(ITimeFactory::class),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
use OCP\Contacts\IManager as IContactsManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -104,6 +105,7 @@ protected function setUp(): void {
$this->gsConfig,
$this->cloudFederationProviderManager,
$this->logger,
Server::get(ITimeFactory::class),
);

$this->shareManager = Server::get(IManager::class);
Expand Down Expand Up @@ -482,6 +484,7 @@ public function testUpdate(string $owner, string $sharedBy, ?\DateTime $expirati
$this->gsConfig,
$this->cloudFederationProviderManager,
$this->logger,
Server::get(ITimeFactory::class),
]
)
->onlyMethods(['sendPermissionUpdate'])
Expand Down
2 changes: 1 addition & 1 deletion apps/files/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<name>Files</name>
<summary>File Management</summary>
<description>File Management</description>
<version>4.0.0-dev.0</version>
<version>4.0.0-dev.1</version>
<licence>agpl</licence>
<author>John Molakvoæ</author>
<author>Robin Appelman</author>
Expand Down
4 changes: 4 additions & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
'OCA\\Files\\Migration\\Version12101Date20221011153334' => $baseDir . '/../lib/Migration/Version12101Date20221011153334.php',
'OCA\\Files\\Migration\\Version2003Date20241021095629' => $baseDir . '/../lib/Migration/Version2003Date20241021095629.php',
'OCA\\Files\\Migration\\Version35000Date20260910082613' => $baseDir . '/../lib/Migration/Version35000Date20260910082613.php',
'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Files\\PublicCapabilities' => $baseDir . '/../lib/PublicCapabilities.php',
'OCA\\Files\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
Expand All @@ -109,6 +110,9 @@
'OCA\\Files\\Sharing\\Permission\\NodeReadSharePermissionType' => $baseDir . '/../lib/Sharing/Permission/NodeReadSharePermissionType.php',
'OCA\\Files\\Sharing\\Permission\\NodeUpdateSharePermissionType' => $baseDir . '/../lib/Sharing/Permission/NodeUpdateSharePermissionType.php',
'OCA\\Files\\Sharing\\Property\\NodeGridViewSharePropertyType' => $baseDir . '/../lib/Sharing/Property/NodeGridViewSharePropertyType.php',
'OCA\\Files\\Sharing\\Property\\NodeNicknameSharePropertyType' => $baseDir . '/../lib/Sharing/Property/NodeNicknameSharePropertyType.php',
'OCA\\Files\\Sharing\\SharesUpdatedListener' => $baseDir . '/../lib/Sharing/SharesUpdatedListener.php',
'OCA\\Files\\Sharing\\SourceNodeTargetManager' => $baseDir . '/../lib/Sharing/SourceNodeTargetManager.php',
'OCA\\Files\\Sharing\\Source\\NodeShareSourceMetadata' => $baseDir . '/../lib/Sharing/Source/NodeShareSourceMetadata.php',
'OCA\\Files\\Sharing\\Source\\NodeShareSourceType' => $baseDir . '/../lib/Sharing/Source/NodeShareSourceType.php',
'OCA\\Files\\TokenScopes' => $baseDir . '/../lib/TokenScopes.php',
Expand Down
4 changes: 4 additions & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__ . '/..' . '/../lib/Migration/Version12101Date20221011153334.php',
'OCA\\Files\\Migration\\Version2003Date20241021095629' => __DIR__ . '/..' . '/../lib/Migration/Version2003Date20241021095629.php',
'OCA\\Files\\Migration\\Version35000Date20260910082613' => __DIR__ . '/..' . '/../lib/Migration/Version35000Date20260910082613.php',
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Files\\PublicCapabilities' => __DIR__ . '/..' . '/../lib/PublicCapabilities.php',
'OCA\\Files\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
Expand All @@ -124,6 +125,9 @@ class ComposerStaticInitFiles
'OCA\\Files\\Sharing\\Permission\\NodeReadSharePermissionType' => __DIR__ . '/..' . '/../lib/Sharing/Permission/NodeReadSharePermissionType.php',
'OCA\\Files\\Sharing\\Permission\\NodeUpdateSharePermissionType' => __DIR__ . '/..' . '/../lib/Sharing/Permission/NodeUpdateSharePermissionType.php',
'OCA\\Files\\Sharing\\Property\\NodeGridViewSharePropertyType' => __DIR__ . '/..' . '/../lib/Sharing/Property/NodeGridViewSharePropertyType.php',
'OCA\\Files\\Sharing\\Property\\NodeNicknameSharePropertyType' => __DIR__ . '/..' . '/../lib/Sharing/Property/NodeNicknameSharePropertyType.php',
'OCA\\Files\\Sharing\\SharesUpdatedListener' => __DIR__ . '/..' . '/../lib/Sharing/SharesUpdatedListener.php',
'OCA\\Files\\Sharing\\SourceNodeTargetManager' => __DIR__ . '/..' . '/../lib/Sharing/SourceNodeTargetManager.php',
'OCA\\Files\\Sharing\\Source\\NodeShareSourceMetadata' => __DIR__ . '/..' . '/../lib/Sharing/Source/NodeShareSourceMetadata.php',
'OCA\\Files\\Sharing\\Source\\NodeShareSourceType' => __DIR__ . '/..' . '/../lib/Sharing/Source/NodeShareSourceType.php',
'OCA\\Files\\TokenScopes' => __DIR__ . '/..' . '/../lib/TokenScopes.php',
Expand Down
19 changes: 19 additions & 0 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Files\AppInfo;

use NCU\Sharing\Event\SharesUpdatedEvent;
use NCU\Sharing\ISharingRegistry;
use OC\Core\Sharing\Permission\EditSharePermissionPreset;
use OC\Core\Sharing\Permission\ViewSharePermissionPreset;
Expand Down Expand Up @@ -45,7 +46,10 @@
use OCA\Files\Sharing\Permission\NodeReadSharePermissionType;
use OCA\Files\Sharing\Permission\NodeUpdateSharePermissionType;
use OCA\Files\Sharing\Property\NodeGridViewSharePropertyType;
use OCA\Files\Sharing\Property\NodeNicknameSharePropertyType;
use OCA\Files\Sharing\SharesUpdatedListener;
use OCA\Files\Sharing\Source\NodeShareSourceType;
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
Expand All @@ -58,6 +62,7 @@
use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
use OCP\Files\Events\Node\NodeCopiedEvent;
use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Events\NodeAddedToFavorite;
use OCP\Files\Events\NodeRemovedFromFavorite;
use OCP\Interaction\RestrictInteractionEvent;
Expand Down Expand Up @@ -111,6 +116,16 @@ public function register(IRegistrationContext $context): void {

$context->registerEventListener(RestrictInteractionEvent::class, RestrictInteractionListener::class);

$context->registerEventListener(SharesUpdatedEvent::class, SharesUpdatedListener::class);

$this->registerSharing();

$context->registerEventListener(NodeDeletedEvent::class, NodeShareSourceType::class);
$context->registerEventListener(MoveToTrashEvent::class, NodeShareSourceType::class);
$context->registerEventListener(SharesUpdatedEvent::class, SharesUpdatedListener::class);
}

private function registerSharing(): void {
$registry = Server::get(ISharingRegistry::class);

$registry->registerSourceType(Server::get(NodeShareSourceType::class));
Expand All @@ -123,6 +138,10 @@ public function register(IRegistrationContext $context): void {
$registry->markPropertyTypeCompatibleWithSourceType(NodeGridViewSharePropertyType::class, NodeShareSourceType::class);
$registry->markPropertyTypeCompatibleWithRecipientType(NodeGridViewSharePropertyType::class, TokenShareRecipientType::class);

$registry->registerPropertyType(new NodeNicknameSharePropertyType());
$registry->markPropertyTypeCompatibleWithSourceType(NodeNicknameSharePropertyType::class, NodeShareSourceType::class);
$registry->markPropertyTypeCompatibleWithRecipientType(NodeNicknameSharePropertyType::class, TokenShareRecipientType::class);

$registry->registerPermissionType(NodeShareSourceType::class, Server::get(NodeCreateSharePermissionType::class));
$registry->markPermissionTypeCompatibleWithPermissionPreset(NodeCreateSharePermissionType::class, EditSharePermissionPreset::class);

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

declare(strict_types=1);

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

namespace OCA\Files\Migration;

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

final class Version35000Date20260910082613 extends SimpleMigrationStep {
/**
* @param Closure(): ISchemaWrapper $schemaClosure
*/
#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

$sourceNodeTargetTable = $schema->createTable('sharing_source_node_target');
Comment thread
provokateurin marked this conversation as resolved.
Resolved
$sourceNodeTargetTable->addColumn('user_id', Types::STRING, ['length' => 64]);
// Can't add a FK on sharing_instance_map here, because that table is created by the sharing app.
$sourceNodeTargetTable->addColumn('source_instance_id', Types::INTEGER, ['notnull' => false]);
$sourceNodeTargetTable->addColumn('source_node_id', Types::INTEGER);
$sourceNodeTargetTable->addColumn('target', Types::TEXT, ['length' => 255]);
// Primary key doesn't work, because that makes source_instance NOT NULL
$sourceNodeTargetTable->addUniqueIndex(['user_id', 'source_instance_id', 'source_node_id']);

return $schema;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

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

namespace OCA\Files\Sharing\Property;

use NCU\Sharing\Property\ABooleanSharePropertyType;
use NCU\Sharing\Share;
use OC\Core\AppInfo\Application;
use OCP\L10N\IFactory;

final class NodeNicknameSharePropertyType extends ABooleanSharePropertyType {
#[\Override]
public function getDisplayName(IFactory $l10nFactory): string {
return $l10nFactory->get(Application::APP_ID)->t('Always ask recipients for a nickname before uploading files.');
}

#[\Override]
public function getHint(IFactory $l10nFactory, Share $share): ?string {
return null;
}

#[\Override]
public function getPriority(): int {
return 75;
}

#[\Override]
public function isAdvanced(): bool {
return true;
}

#[\Override]
public function isRequired(Share $share): bool {
return false;
}

#[\Override]
public function getDefaultValue(Share $share): string {
return 'false';
}
}
75 changes: 75 additions & 0 deletions apps/files/lib/Sharing/SharesUpdatedListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

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

declare(strict_types=1);

namespace OCA\Files\Sharing;

use NCU\Sharing\Event\SharesUpdatedEvent;
use NCU\Sharing\ISharingRegistry;
use NCU\Sharing\ShareState;
use OCA\Files\Sharing\Source\NodeShareSourceType;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use Override;
use RuntimeException;

/**
* @implements IEventListener<SharesUpdatedEvent>
*/
final readonly class SharesUpdatedListener implements IEventListener {
public function __construct(
private ISharingRegistry $registry,
private SourceNodeTargetManager $sourceNodeTargetManager,
private IRootFolder $rootFolder,
) {
}

#[Override]
public function handle(Event $event): void {
foreach ($event->getShares() as $share) {
if ($share->state !== ShareState::Active) {
continue;
}

$ownerUserFolder = $this->rootFolder->getUserFolder($share->owner->userId);

foreach ($share->sources as $source) {
if ($source->class !== NodeShareSourceType::class) {
continue;
}

$sourceNode = $ownerUserFolder->getFirstNodeById((int)$source->value);
if (!$sourceNode instanceof Node) {
throw new NotFoundException();
}

/** @var array<int|string, true> */
$userIds = [];
foreach ($share->recipients as $recipient) {
if ($recipient->instance !== null) {
continue;
}

if (($recipientType = $this->registry->getRecipientTypes()[$recipient->class] ?? null) === null) {
throw new RuntimeException('The recipient type is not registered: ' . $recipient->class);
}

foreach ($recipientType->getUsers($recipient->value) as $user) {
$userIds[$user->getUID()] = true;
}
}

// Casting is needed, because using the user ID as the array key could convert it to an integer if it is numeric.
$this->sourceNodeTargetManager->getTargets(array_map(static fn (int|string $userId): string => (string)$userId, array_keys($userIds)), $share->owner, $sourceNode);
}
}
}
}
2 changes: 0 additions & 2 deletions apps/files/lib/Sharing/Source/NodeShareSourceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function __construct(
private ISharingManager $manager,
private IFileAccess $fileAccess,
) {
$eventDispatcher->addServiceListener(NodeDeletedEvent::class, self::class);
$eventDispatcher->addServiceListener(MoveToTrashEvent::class, self::class);
}

#[\Override]
Expand Down
Loading
Loading