Skip to content

Commit c85f755

Browse files
committed
refactor: use Share for most SharingManager parameters instead of just the id
Signed-off-by: Robin Appelman <robin@icewind.nl> # Conflicts: # tests/lib/Sharing/AbstractSharingManagerTests.php # Conflicts: # apps/sharing/tests/Controller/ApiV1ControllerTest.php # tests/lib/Sharing/AbstractSharingManagerTests.php
1 parent cbbb991 commit c85f755

31 files changed

Lines changed: 1249 additions & 892 deletions

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,21 @@ public function testDelete(): void {
108108
$accessContext = new ShareAccessContext(currentUser: $this->user1);
109109

110110
$this->dbConnection->beginTransaction();
111-
$id = $this->manager->createShare($accessContext);
112-
$this->manager->addShareSource($accessContext, $id, new ShareSource($this->sourceType::class, (string)$this->node->getId()));
111+
$share = $this->manager->createShare($accessContext);
112+
$this->manager->addShareSource($accessContext, $share, new ShareSource($this->sourceType::class, (string)$this->node->getId()));
113113
$this->dbConnection->commit();
114114

115115
$before = $this->manager->getTime();
116116
$this->node->delete();
117117
$after = $this->manager->getTime();
118118

119119
$this->dbConnection->beginTransaction();
120-
$share = $this->manager->getShare($accessContext, $id);
120+
$share = $this->manager->getShare($accessContext, $share->id);
121121
$this->assertGreaterThanOrEqual(SharingManager::timeToMs($before), SharingManager::timeToMs($share->lastUpdated));
122122
$this->assertLessThanOrEqual(SharingManager::timeToMs($after), SharingManager::timeToMs($share->lastUpdated));
123123
$this->assertEquals([], $share->sources);
124124

125-
$this->manager->deleteShare($accessContext, $id);
125+
$this->manager->deleteShare($accessContext, $share);
126126
$this->dbConnection->commit();
127127
$registry->clear();
128128
}

apps/sharing/lib/Command/AddShareRecipient.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use NCU\Sharing\Recipient\IShareRecipientType;
1313
use NCU\Sharing\Recipient\ShareRecipient;
14+
use NCU\Sharing\Share;
1415
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Output\OutputInterface;
@@ -39,9 +40,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3940
/** @var ?non-empty-string $instance */
4041
$instance = $input->getArgument('instance');
4142

42-
return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): string {
43-
$this->manager->addShareRecipient($this->accessContext, $id, new ShareRecipient($class, $value, $instance));
44-
return $id;
43+
return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): Share {
44+
$share = $this->manager->getShare($this->accessContext, $id);
45+
return $this->manager->addShareRecipient($this->accessContext, $share, new ShareRecipient($class, $value, $instance));
4546
});
4647
}
4748
}

apps/sharing/lib/Command/AddShareSource.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OCA\Sharing\Command;
1111

12+
use NCU\Sharing\Share;
1213
use NCU\Sharing\Source\IShareSourceType;
1314
use NCU\Sharing\Source\ShareSource;
1415
use Symfony\Component\Console\Input\InputArgument;
@@ -35,9 +36,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3536
/** @var non-empty-string $value */
3637
$value = $input->getArgument('value');
3738

38-
return $this->wrapExecution($output, function () use ($id, $class, $value): string {
39-
$this->manager->addShareSource($this->accessContext, $id, new ShareSource($class, $value));
40-
return $id;
39+
return $this->wrapExecution($output, function () use ($id, $class, $value): Share {
40+
$share = $this->manager->getShare($this->accessContext, $id);
41+
return $this->manager->addShareSource($this->accessContext, $share, new ShareSource($class, $value));
4142
});
4243
}
4344
}

apps/sharing/lib/Command/CreateShare.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCA\Sharing\Command;
1111

1212
use NCU\Sharing\Exception\ShareInvalidException;
13+
use NCU\Sharing\Share;
1314
use NCU\Sharing\ShareAccessContext;
1415
use OCP\IUserManager;
1516
use OCP\L10N\IFactory;
@@ -36,6 +37,6 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3637
throw new ShareInvalidException('The owner does not exist: ' . $ownerUid, Server::get(IFactory::class)->get('sharing')->t('The owner does not exist: %s', [$ownerUid]));
3738
}
3839

39-
return $this->wrapExecution($output, fn (): string => $this->manager->createShare(new ShareAccessContext($owner)));
40+
return $this->wrapExecution($output, fn (): Share => $this->manager->createShare(new ShareAccessContext($owner)));
4041
}
4142
}

apps/sharing/lib/Command/DeleteShare.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3535
try {
3636
$this->dbConnection->beginTransaction();
3737

38-
$this->manager->deleteShare($this->accessContext, $id);
38+
$share = $this->manager->getShare($this->accessContext, $id);
39+
$this->manager->deleteShare($this->accessContext, $share);
3940
$this->dbConnection->commit();
4041
return Base::SUCCESS;
4142
} catch (Exception $exception) {

apps/sharing/lib/Command/GetShare.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OCA\Sharing\Command;
1111

12+
use NCU\Sharing\Share;
1213
use Symfony\Component\Console\Input\InputArgument;
1314
use Symfony\Component\Console\Input\InputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
@@ -27,6 +28,6 @@ public function execute(InputInterface $input, OutputInterface $output): int {
2728
/** @var string $id */
2829
$id = $input->getArgument('id');
2930

30-
return $this->wrapExecution($output, fn (): string => $id);
31+
return $this->wrapExecution($output, fn (): Share => $this->manager->getShare($this->accessContext, $id));
3132
}
3233
}

apps/sharing/lib/Command/RemoveShareRecipient.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use NCU\Sharing\Recipient\IShareRecipientType;
1313
use NCU\Sharing\Recipient\ShareRecipient;
14+
use NCU\Sharing\Share;
1415
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,9 +39,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3839
/** @var ?non-empty-string $instance */
3940
$instance = $input->getArgument('instance');
4041

41-
return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): string {
42-
$this->manager->removeShareRecipient($this->accessContext, $id, new ShareRecipient($class, $value, $instance));
43-
return $id;
42+
return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): Share {
43+
$share = $this->manager->getShare($this->accessContext, $id);
44+
return $this->manager->removeShareRecipient($this->accessContext, $share, new ShareRecipient($class, $value, $instance));
4445
});
4546
}
4647
}

apps/sharing/lib/Command/RemoveShareSource.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OCA\Sharing\Command;
1111

12+
use NCU\Sharing\Share;
1213
use NCU\Sharing\Source\IShareSourceType;
1314
use NCU\Sharing\Source\ShareSource;
1415
use Symfony\Component\Console\Input\InputArgument;
@@ -35,9 +36,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3536
/** @var non-empty-string $value */
3637
$value = $input->getArgument('value');
3738

38-
return $this->wrapExecution($output, function () use ($id, $class, $value): string {
39-
$this->manager->removeShareSource($this->accessContext, $id, new ShareSource($class, $value));
40-
return $id;
39+
return $this->wrapExecution($output, function () use ($id, $class, $value): Share {
40+
$share = $this->manager->getShare($this->accessContext, $id);
41+
return $this->manager->removeShareSource($this->accessContext, $share, new ShareSource($class, $value));
4142
});
4243
}
4344
}

apps/sharing/lib/Command/SelectSharePermissionPreset.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCA\Sharing\Command;
1111

1212
use NCU\Sharing\Permission\ISharePermissionPreset;
13+
use NCU\Sharing\Share;
1314
use Symfony\Component\Console\Input\InputArgument;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
@@ -31,9 +32,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3132
/** @var class-string<ISharePermissionPreset> $permissionPresetClass */
3233
$permissionPresetClass = $input->getArgument('permission-preset');
3334

34-
return $this->wrapExecution($output, function () use ($id, $permissionPresetClass): string {
35-
$this->manager->selectSharePermissionPreset($this->accessContext, $id, $permissionPresetClass);
36-
return $id;
35+
return $this->wrapExecution($output, function () use ($id, $permissionPresetClass): Share {
36+
$share = $this->manager->getShare($this->accessContext, $id);
37+
return $this->manager->selectSharePermissionPreset($this->accessContext, $share, $permissionPresetClass);
3738
});
3839
}
3940
}

apps/sharing/lib/Command/SharingBase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use NCU\Sharing\Exception\AShareException;
1515
use NCU\Sharing\ISharingManager;
1616
use NCU\Sharing\ISharingRegistry;
17+
use NCU\Sharing\Share;
1718
use NCU\Sharing\ShareAccessContext;
1819
use OC\Core\Command\Base;
1920
use OCP\IDBConnection;
@@ -40,16 +41,15 @@ public function __construct(
4041
}
4142

4243
/**
43-
* @param Closure():string $closure
44+
* @param Closure():Share $closure
4445
*/
4546
protected function wrapExecution(OutputInterface $output, Closure $closure): int {
4647

4748
try {
4849
try {
4950
$this->dbConnection->beginTransaction();
5051

51-
$id = $closure();
52-
$share = $this->manager->getShare($this->accessContext, $id);
52+
$share = $closure();
5353
$this->dbConnection->commit();
5454
$output->writeln(json_encode($share->format($this->registry, $this->l10nFactory, $this->urlGenerator, $this->userManager), JSON_THROW_ON_ERROR));
5555
return Base::SUCCESS;

0 commit comments

Comments
 (0)