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
8 changes: 4 additions & 4 deletions apps/files/tests/Sharing/Source/NodeShareSourceTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,21 @@ public function testDelete(): void {
$accessContext = new ShareAccessContext(currentUser: $this->user1);

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

$before = $this->manager->getTime();
$this->node->delete();
$after = $this->manager->getTime();

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

$this->manager->deleteShare($accessContext, $id);
$this->manager->deleteShare($accessContext, $share);
$this->dbConnection->commit();
$registry->clear();
}
Expand Down
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/AddShareRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use NCU\Sharing\Recipient\IShareRecipientType;
use NCU\Sharing\Recipient\ShareRecipient;
use NCU\Sharing\Share;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -39,9 +40,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
/** @var ?non-empty-string $instance */
$instance = $input->getArgument('instance');

return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): string {
$this->manager->addShareRecipient($this->accessContext, $id, new ShareRecipient($class, $value, $instance));
return $id;
return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->addShareRecipient($this->accessContext, $share, new ShareRecipient($class, $value, $instance));
});
}
}
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/AddShareSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Sharing\Command;

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

return $this->wrapExecution($output, function () use ($id, $class, $value): string {
$this->manager->addShareSource($this->accessContext, $id, new ShareSource($class, $value));
return $id;
return $this->wrapExecution($output, function () use ($id, $class, $value): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->addShareSource($this->accessContext, $share, new ShareSource($class, $value));
});
}
}
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/CreateShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Sharing\Command;

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

return $this->wrapExecution($output, fn (): string => $this->manager->createShare(new ShareAccessContext($owner)));
return $this->wrapExecution($output, fn (): Share => $this->manager->createShare(new ShareAccessContext($owner)));
}
}
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/DeleteShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function execute(InputInterface $input, OutputInterface $output): int {
try {
$this->dbConnection->beginTransaction();

$this->manager->deleteShare($this->accessContext, $id);
$share = $this->manager->getShare($this->accessContext, $id);
$this->manager->deleteShare($this->accessContext, $share);
$this->dbConnection->commit();
return Base::SUCCESS;
} catch (Exception $exception) {
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/GetShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Sharing\Command;

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

return $this->wrapExecution($output, fn (): string => $id);
return $this->wrapExecution($output, fn (): Share => $this->manager->getShare($this->accessContext, $id));
}
}
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/RemoveShareRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use NCU\Sharing\Recipient\IShareRecipientType;
use NCU\Sharing\Recipient\ShareRecipient;
use NCU\Sharing\Share;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -38,9 +39,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
/** @var ?non-empty-string $instance */
$instance = $input->getArgument('instance');

return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): string {
$this->manager->removeShareRecipient($this->accessContext, $id, new ShareRecipient($class, $value, $instance));
return $id;
return $this->wrapExecution($output, function () use ($id, $class, $value, $instance): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->removeShareRecipient($this->accessContext, $share, new ShareRecipient($class, $value, $instance));
});
}
}
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/RemoveShareSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Sharing\Command;

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

return $this->wrapExecution($output, function () use ($id, $class, $value): string {
$this->manager->removeShareSource($this->accessContext, $id, new ShareSource($class, $value));
return $id;
return $this->wrapExecution($output, function () use ($id, $class, $value): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->removeShareSource($this->accessContext, $share, new ShareSource($class, $value));
});
}
}
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/SelectSharePermissionPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Sharing\Command;

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

return $this->wrapExecution($output, function () use ($id, $permissionPresetClass): string {
$this->manager->selectSharePermissionPreset($this->accessContext, $id, $permissionPresetClass);
return $id;
return $this->wrapExecution($output, function () use ($id, $permissionPresetClass): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->selectSharePermissionPreset($this->accessContext, $share, $permissionPresetClass);
});
}
}
6 changes: 3 additions & 3 deletions apps/sharing/lib/Command/SharingBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use NCU\Sharing\Exception\AShareException;
use NCU\Sharing\ISharingManager;
use NCU\Sharing\ISharingRegistry;
use NCU\Sharing\Share;
use NCU\Sharing\ShareAccessContext;
use OC\Core\Command\Base;
use OCP\IDBConnection;
Expand All @@ -40,16 +41,15 @@ public function __construct(
}

/**
* @param Closure():string $closure
* @param Closure():Share $closure
*/
protected function wrapExecution(OutputInterface $output, Closure $closure): int {

try {
try {
$this->dbConnection->beginTransaction();

$id = $closure();
$share = $this->manager->getShare($this->accessContext, $id);
$share = $closure();
$this->dbConnection->commit();
$output->writeln(json_encode($share->format($this->registry, $this->l10nFactory, $this->urlGenerator, $this->userManager), JSON_THROW_ON_ERROR));
return Base::SUCCESS;
Expand Down
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/UpdateSharePermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use NCU\Sharing\Permission\ISharePermissionType;
use NCU\Sharing\Permission\SharePermission;
use NCU\Sharing\Share;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -36,9 +37,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$enabled = $input->getArgument('enabled');
$enabled = $enabled === 'true';

return $this->wrapExecution($output, function () use ($id, $class, $enabled): string {
$this->manager->updateSharePermission($this->accessContext, $id, new SharePermission($class, $enabled));
return $id;
return $this->wrapExecution($output, function () use ($id, $class, $enabled): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->updateSharePermission($this->accessContext, $share, new SharePermission($class, $enabled));
});
}
}
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/UpdateShareProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use NCU\Sharing\Property\ISharePropertyType;
use NCU\Sharing\Property\ShareProperty;
use NCU\Sharing\Share;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -35,9 +36,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
/** @var ?string $value */
$value = $input->getArgument('value');

return $this->wrapExecution($output, function () use ($id, $class, $value): string {
$this->manager->updateShareProperty($this->accessContext, $id, new ShareProperty($class, $value));
return $id;
return $this->wrapExecution($output, function () use ($id, $class, $value): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->updateShareProperty($this->accessContext, $share, new ShareProperty($class, $value));
});
}
}
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/UpdateShareRecipientSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use NCU\Sharing\Recipient\IShareRecipientType;
use NCU\Sharing\Recipient\ShareRecipient;
use NCU\Sharing\Share;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -41,9 +42,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
/** @var non-empty-string $secret */
$secret = $input->getArgument('secret');

return $this->wrapExecution($output, function () use ($id, $class, $value, $instance, $secret): string {
$this->manager->updateShareRecipientSecret($this->accessContext, $id, new ShareRecipient($class, $value, $instance), $secret);
return $id;
return $this->wrapExecution($output, function () use ($id, $class, $value, $instance, $secret): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->updateShareRecipientSecret($this->accessContext, $share, new ShareRecipient($class, $value, $instance), $secret);
});
}
}
7 changes: 4 additions & 3 deletions apps/sharing/lib/Command/UpdateShareState.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Sharing\Command;

use NCU\Sharing\Share;
use NCU\Sharing\ShareState;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -32,9 +33,9 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$state = $input->getArgument('state');
$state = ShareState::from($state);

return $this->wrapExecution($output, function () use ($id, $state): string {
$this->manager->updateShareState($this->accessContext, $id, $state);
return $id;
return $this->wrapExecution($output, function () use ($id, $state): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->updateShareState($this->accessContext, $share, $state);
});
}
}
Loading
Loading