Skip to content

Commit c65d1f9

Browse files
Merge pull request #62613 from nextcloud/refactor/sharing/files_sharing-legacy-backend-preparations
Preparations for files_sharing legacy backend
2 parents 14b21d7 + f7ecd25 commit c65d1f9

21 files changed

Lines changed: 506 additions & 331 deletions

apps/files/tests/Sharing/Source/NodeShareSourceTypeTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use OC\Files\Filesystem;
1515
use OC\User\Database;
1616
use OCA\Files\Sharing\Source\NodeShareSourceType;
17-
use OCA\Sharing\SharingBackend;
1817
use OCP\EventDispatcher\IEventDispatcher;
1918
use OCP\Files\IRootFolder;
2019
use OCP\Files\Node;
@@ -95,7 +94,6 @@ public function testGetSourceIcon(): void {
9594
public function testDelete(): void {
9695
$registry = Server::get(ISharingRegistry::class);
9796
$registry->clear();
98-
$registry->registerSharingBackend(Server::get(SharingBackend::class));
9997
$registry->registerSourceType($this->sourceType);
10098

10199
$accessContext = new ShareAccessContext(currentUser: $this->user1);

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ protected function publishActivity(string $subject, array $parameters, string $a
224224
* @throws \Exception
225225
*/
226226
protected function createMailShare(IShare $share): string {
227-
$share->setToken($this->generateToken());
227+
if ($share->getToken() === '') {
228+
$share->setToken($this->generateToken());
229+
}
228230
return $this->addShareToDB(
229231
$share->getNodeId(),
230232
$share->getNodeType(),

apps/sharebymail/tests/ShareByMailProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public function testCreateFailed(): void {
670670
}
671671

672672
public function testCreateMailShare(): void {
673-
$this->share->expects($this->any())->method('getToken')->willReturn('token');
673+
$this->share->expects($this->any())->method('getToken')->willReturn('');
674674
$this->share->expects($this->once())->method('setToken')->with('token');
675675
$this->share->expects($this->any())->method('getSharedBy')->willReturn('validby@valid.com');
676676
$this->share->expects($this->any())->method('getSharedWith')->willReturn('validwith@valid.com');

apps/sharing/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@
2727
'OCA\\Sharing\\Middleware\\ShareApiEnabledMiddleware' => $baseDir . '/../lib/Middleware/ShareApiEnabledMiddleware.php',
2828
'OCA\\Sharing\\Migration\\Version1000Date20250929161325' => $baseDir . '/../lib/Migration/Version1000Date20250929161325.php',
2929
'OCA\\Sharing\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
30-
'OCA\\Sharing\\SharingBackend' => $baseDir . '/../lib/SharingBackend.php',
3130
);

apps/sharing/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class ComposerStaticInitSharing
4242
'OCA\\Sharing\\Middleware\\ShareApiEnabledMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ShareApiEnabledMiddleware.php',
4343
'OCA\\Sharing\\Migration\\Version1000Date20250929161325' => __DIR__ . '/..' . '/../lib/Migration/Version1000Date20250929161325.php',
4444
'OCA\\Sharing\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
45-
'OCA\\Sharing\\SharingBackend' => __DIR__ . '/..' . '/../lib/SharingBackend.php',
4645
);
4746

4847
public static function getInitializer(ClassLoader $loader)

apps/sharing/lib/AppInfo/Application.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99

1010
namespace OCA\Sharing\AppInfo;
1111

12-
use NCU\Sharing\ISharingRegistry;
1312
use OCA\Sharing\Capabilities;
1413
use OCA\Sharing\Middleware\ShareApiEnabledMiddleware;
15-
use OCA\Sharing\SharingBackend;
1614
use OCP\AppFramework\App;
1715
use OCP\AppFramework\Bootstrap\IBootContext;
1816
use OCP\AppFramework\Bootstrap\IBootstrap;
1917
use OCP\AppFramework\Bootstrap\IRegistrationContext;
20-
use OCP\Server;
2118

2219
final class Application extends App implements IBootstrap {
2320
public const string APP_ID = 'sharing';
@@ -30,9 +27,6 @@ public function __construct(array $urlParams = []) {
3027
public function register(IRegistrationContext $context): void {
3128
$context->registerCapability(Capabilities::class);
3229
$context->registerMiddleware(ShareApiEnabledMiddleware::class);
33-
34-
$registry = Server::get(ISharingRegistry::class);
35-
$registry->registerSharingBackend(Server::get(SharingBackend::class));
3630
}
3731

3832
#[\Override]

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,8 @@
22962296
'OC\\Share20\\UserDeletedListener' => $baseDir . '/lib/private/Share20/UserDeletedListener.php',
22972297
'OC\\Share20\\UserRemovedListener' => $baseDir . '/lib/private/Share20/UserRemovedListener.php',
22982298
'OC\\Share\\Constants' => $baseDir . '/lib/private/Share/Constants.php',
2299+
'OC\\Sharing\\ISharingLegacyBackend' => $baseDir . '/lib/private/Sharing/ISharingLegacyBackend.php',
2300+
'OC\\Sharing\\SharingBackend' => $baseDir . '/lib/private/Sharing/SharingBackend.php',
22992301
'OC\\Sharing\\SharingManager' => $baseDir . '/lib/private/Sharing/SharingManager.php',
23002302
'OC\\Sharing\\SharingRegistry' => $baseDir . '/lib/private/Sharing/SharingRegistry.php',
23012303
'OC\\Snowflake\\APCuSequence' => $baseDir . '/lib/private/Snowflake/APCuSequence.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
23372337
'OC\\Share20\\UserDeletedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserDeletedListener.php',
23382338
'OC\\Share20\\UserRemovedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserRemovedListener.php',
23392339
'OC\\Share\\Constants' => __DIR__ . '/../../..' . '/lib/private/Share/Constants.php',
2340+
'OC\\Sharing\\ISharingLegacyBackend' => __DIR__ . '/../../..' . '/lib/private/Sharing/ISharingLegacyBackend.php',
2341+
'OC\\Sharing\\SharingBackend' => __DIR__ . '/../../..' . '/lib/private/Sharing/SharingBackend.php',
23402342
'OC\\Sharing\\SharingManager' => __DIR__ . '/../../..' . '/lib/private/Sharing/SharingManager.php',
23412343
'OC\\Sharing\\SharingRegistry' => __DIR__ . '/../../..' . '/lib/private/Sharing/SharingRegistry.php',
23422344
'OC\\Snowflake\\APCuSequence' => __DIR__ . '/../../..' . '/lib/private/Snowflake/APCuSequence.php',

lib/private/Share20/Manager.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ protected function generalChecks(IShare $share): void {
268268
throw new GenericShareException($isRestricted, code: 403);
269269
}
270270
} catch (\Exception $exception) {
271-
throw new GenericShareException($exception->getMessage(), $exception instanceof HintException ? $exception->getHint() : '', code: 403);
271+
throw new GenericShareException($exception->getMessage(), $exception instanceof HintException ? $exception->getHint() : '', code: 403, previous: $exception);
272272
}
273273
}
274274
}
@@ -567,9 +567,11 @@ public function createShare(IShare $share): IShare {
567567
|| $share->getShareType() === IShare::TYPE_EMAIL) {
568568
$this->setLinkParent($share);
569569

570-
$token = $this->generateToken();
571-
// Set the unique token
572-
$share->setToken($token);
570+
if ($share->getToken() === '') {
571+
$token = $this->generateToken();
572+
// Set the unique token
573+
$share->setToken($token);
574+
}
573575

574576
// Verify the expiration date
575577
$share = $this->validateExpirationDateLink($share);

lib/private/Share20/Share.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Share implements IShare {
3131
private $fileId;
3232
/** @var string */
3333
private $nodeType;
34-
/** @var int */
34+
/** @var IShare::TYPE_* */
3535
private $shareType;
3636
/** @var string */
3737
private $sharedWith;
@@ -44,11 +44,11 @@ class Share implements IShare {
4444
private $sharedBy;
4545
/** @var string */
4646
private $shareOwner;
47-
/** @var int */
47+
/** @var int-mask-of<Constants::PERMISSION_*> */
4848
private $permissions;
4949
/** @var IAttributes */
5050
private $attributes;
51-
/** @var int */
51+
/** @var self::STATUS_* */
5252
private $status;
5353
/** @var string */
5454
private $note = '';
@@ -60,7 +60,7 @@ class Share implements IShare {
6060
/** @var bool */
6161
private $sendPasswordByTalk = false;
6262
/** @var string */
63-
private $token;
63+
private $token = '';
6464
private ?int $parent = null;
6565
/** @var string */
6666
private $target;
@@ -358,7 +358,7 @@ public function setStatus(int $status): IShare {
358358
* @inheritdoc
359359
*/
360360
#[\Override]
361-
public function getStatus(): int {
361+
public function getStatus(): ?int {
362362
return $this->status;
363363
}
364364

0 commit comments

Comments
 (0)