Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8d291d7
refactor(files_sharing): Set expiration date time to 23:59:59 only in…
provokateurin Sep 30, 2026
1d635ea
feat(IShare): Add getProviderId()
provokateurin Sep 2, 2026
6bd5479
feat(Share20): Dispatch ShareUpdatedEvent and ShareRestoredEvent
provokateurin Sep 2, 2026
8c623ef
feat(OCP\Share\Events): Add setters for the share property
provokateurin Sep 23, 2026
b47f7a8
feat(SharingManager): Dispatch SharesUpdatedEvent and SharesDeletedEvent
provokateurin Sep 2, 2026
41d9b26
feat(DefaultShareProvider): Allow fetching shares of TYPE_USERGROUP
provokateurin Sep 23, 2026
71e492a
feat(ITeamManager): Allow calling getMembersOfTeam() without a user
provokateurin Sep 10, 2026
21af94c
feat(IShareRecipientType): Add getUsers()
provokateurin Sep 10, 2026
7968c10
feat(Sharing): Add node source target management
provokateurin Sep 10, 2026
91c5008
feat(APasswordSharePropertyType): Only hash the new value if it's not…
provokateurin Sep 23, 2026
839e375
refactor(ISharePropertyTypeModifyValue): Modify values on format inst…
provokateurin Sep 21, 2026
1f70c33
feat(Share): Add getCreatedAt() method
provokateurin Sep 23, 2026
417a326
feat(ISharingBackend): Add getUserStatuses() method
provokateurin Sep 23, 2026
5893022
feat(files): Add NodeNicknameSharePropertyType
provokateurin Oct 13, 2026
3ebaecf
fix(ShareByMailProvider): Set share status from DB
provokateurin Oct 13, 2026
3b0344c
fix(Share20): Fix restoring target after share was created
provokateurin Oct 27, 2026
78e001a
fix(FederatedShareProvider): Use existing share time and target if av…
provokateurin Oct 27, 2026
e024b2d
test(FederatedShareProvider): Don't send remote share notification in…
provokateurin Oct 27, 2026
ca742e8
refactor(Share): Allow checking effective enabled permissions for exp…
provokateurin Oct 27, 2026
84efc96
feat(Sharing): Implement bi-directional syncing with legacy sharing
provokateurin Sep 23, 2026
6f9a5ca
test(integration): Enable Unified Sharing legacy sync validation
provokateurin Sep 23, 2026
2279e86
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
41 changes: 24 additions & 17 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace OCA\FederatedFileSharing;

use DateTime;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Share;
use OCP\Constants;
Expand Down Expand Up @@ -135,7 +136,7 @@ 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);
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, $share->getToken() ?? ('tmp_token_' . time()), $shareType, $expirationDate, $share->getShareTime());
[$token, $remoteId] = $this->notifications->requestReShare(
$remoteShare['refresh_token'],
$remoteShare['remote_id'],
Expand Down Expand Up @@ -170,7 +171,7 @@ public function create(IShare $share): IShare {
* @throws \Exception
*/
protected function createFederatedShare(IShare $share): string {
$token = $this->tokenHandler->generateToken();
$token = $share->getToken() ?? $this->tokenHandler->generateToken();
$shareId = $this->addShareToDB(
$share->getNodeId(),
$share->getNodeType(),
Expand All @@ -180,7 +181,8 @@ protected function createFederatedShare(IShare $share): string {
$share->getPermissions(),
$token,
$share->getShareType(),
$share->getExpirationDate()
$share->getExpirationDate(),
$share->getShareTime(),
);

$failure = false;
Expand All @@ -192,18 +194,23 @@ protected function createFederatedShare(IShare $share): string {
$sharedByFederatedId = $cloudId->getId();
}
$ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL());
$send = $this->notifications->sendRemoteShare(
$token,
$share->getSharedWith(),
$share->getNode()->getName(),
$shareId,
$share->getShareOwner(),
$ownerCloudId->getId(),
$share->getSharedBy(),
$sharedByFederatedId,
$share->getShareType(),
$share->getPermissions()
);
if (defined('PHPUNIT_RUN')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo it's better to have a sendNotifications or something property and have the tests set that to false.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, maybe better, mock the $this->notifications

// Can't send OCM notifications during unit tests
$send = true;
} else {
$send = $this->notifications->sendRemoteShare(
$token,
$share->getSharedWith(),
$share->getNode()->getName(),
$shareId,
$share->getShareOwner(),
$ownerCloudId->getId(),
$share->getSharedBy(),
$sharedByFederatedId,
$share->getShareType(),
$share->getPermissions()
);
}

if ($send === false) {
$failure = true;
Expand Down Expand Up @@ -261,7 +268,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 @@ -274,7 +281,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
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 @@ -86,6 +86,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\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
'OCA\\Files\\Search\\FileAccountScopedSearchProvider' => $baseDir . '/../lib/Search/FileAccountScopedSearchProvider.php',
Expand All @@ -106,6 +107,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 @@ -101,6 +101,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\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
'OCA\\Files\\Search\\FileAccountScopedSearchProvider' => __DIR__ . '/..' . '/../lib/Search/FileAccountScopedSearchProvider.php',
Expand All @@ -121,6 +122,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
13 changes: 13 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 @@ -43,6 +44,8 @@
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 OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
Expand Down Expand Up @@ -106,6 +109,12 @@ public function register(IRegistrationContext $context): void {

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

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

$this->registerSharing();
}

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

$registry->registerSourceType(Server::get(NodeShareSourceType::class));
Expand All @@ -118,6 +127,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
37 changes: 37 additions & 0 deletions apps/files/lib/Migration/Version35000Date20260910082613.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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');
$sourceNodeTargetTable->addColumn('user_id', Types::TEXT, ['length' => 64]);
$sourceNodeTargetTable->addColumn('source_instance', Types::STRING, ['length' => 128, 'notnull' => false]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and any code using it will need to be adjusted once #65512 is in

$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', 'source_node_id']);

return $schema;
}
}
47 changes: 47 additions & 0 deletions apps/files/lib/Sharing/Property/NodeNicknameSharePropertyType.php
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';
}
}
76 changes: 76 additions & 0 deletions apps/files/lib/Sharing/SharesUpdatedListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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\ISharingManager;
use NCU\Sharing\ISharingRegistry;
use NCU\Sharing\ShareAccessContext;
use NCU\Sharing\ShareState;
use OCA\Files\Sharing\Source\NodeShareSourceType;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\NotFoundException;
use Override;
use RuntimeException;

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

#[Override]
public function handle(Event $event): void {
foreach ($event->shareIds as $shareId) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we send the share objects with the event to prevent having to re-fetch them here.

$share = $this->manager->getShare(new ShareAccessContext(overrideChecks: true), $shareId);
if ($share->state !== ShareState::Active) {
continue;
}

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

$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 $userId) {
$userIds[$userId] = true;
}
}

foreach (array_keys($userIds) as $userId) {
try {
if ($this->sourceNodeTargetManager->getTarget($userId, $share->owner, (int)$source->value) === null) {
$this->sourceNodeTargetManager->createDefaultTarget($userId, $share->owner, (int)$source->value);
}
} catch (NotFoundException) {
// The same exception will happen for the other users, because the source node is the same, so we can just stop here.
break;
}
}
Comment on lines +63 to +72

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use getTargets, which both fetches all existing targets at once instead of one by one, and has built-in "create default" handling.

}
}
}
}
Loading
Loading