Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/AddShareRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function configure(): void {
->addArgument('class', InputArgument::REQUIRED, 'Recipient class')
->addArgument('value', InputArgument::REQUIRED, 'Recipient value')
->addArgument('instance', InputArgument::OPTIONAL, 'Recipient instance');
parent::configure();
}

#[\Override]
Expand All @@ -40,7 +41,7 @@ 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): Share {
return $this->wrapExecution($input, $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));
});
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/AddShareSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function configure(): void {
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
->addArgument('class', InputArgument::REQUIRED, 'Source class')
->addArgument('value', InputArgument::REQUIRED, 'Source value');
parent::configure();
}

#[\Override]
Expand All @@ -36,7 +37,7 @@ 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): Share {
return $this->wrapExecution($input, $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));
});
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/CreateShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function configure(): void {
->setName('sharing:create-share')
->setDescription('Create a new share.')
->addArgument('owner', InputArgument::REQUIRED, 'User ID of the owner');
parent::configure();
}

#[\Override]
Expand All @@ -37,6 +38,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 (): Share => $this->manager->createShare(new ShareAccessContext($owner)));
return $this->wrapExecution($input, $output, fn (): Share => $this->manager->createShare(new ShareAccessContext($owner)));
}
}
2 changes: 2 additions & 0 deletions apps/sharing/lib/Command/DeleteShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public function configure(): void {
->setName('sharing:delete-share')
->setDescription('Delete a share.')
->addArgument('id', InputArgument::REQUIRED, 'Share ID');
parent::configure();
}

#[\Override]
public function execute(InputInterface $input, OutputInterface $output): int {
/** @var string $id */
$id = $input->getArgument('id');
$this->applyActor($input);

try {
try {
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 @@ -21,13 +21,14 @@ public function configure(): void {
->setName('sharing:get-share')
->setDescription('Get a share.')
->addArgument('id', InputArgument::REQUIRED, 'Share ID');
parent::configure();
}

#[\Override]
public function execute(InputInterface $input, OutputInterface $output): int {
/** @var string $id */
$id = $input->getArgument('id');

return $this->wrapExecution($output, fn (): Share => $this->manager->getShare($this->accessContext, $id));
return $this->wrapExecution($input, $output, fn (): Share => $this->manager->getShare($this->accessContext, $id));
}
}
3 changes: 3 additions & 0 deletions apps/sharing/lib/Command/GetShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public function configure(): void {
->addOption('filter-source-type-value', '', InputOption::VALUE_REQUIRED, 'Source type value to filter by')
->addOption('last-share-id', '', InputOption::VALUE_REQUIRED, 'Share ID to use as an offset')
->addOption('limit', '', InputOption::VALUE_REQUIRED, 'Maximum number of shares to return');
parent::configure();
}

#[\Override]
public function execute(InputInterface $input, OutputInterface $output): int {
$this->applyActor($input);

/** @var ?class-string<IShareSourceType> $filterSourceTypeClass */
$filterSourceTypeClass = $input->getOption('filter-source-type-class');
/** @var ?class-string<IShareSourceType> $filterSourceTypeValue */
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/RemoveShareRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function configure(): void {
->addArgument('class', InputArgument::REQUIRED, 'Recipient class')
->addArgument('value', InputArgument::REQUIRED, 'Recipient value')
->addArgument('instance', InputArgument::OPTIONAL, 'Recipient instance');
parent::configure();
}

#[\Override]
Expand All @@ -39,7 +40,7 @@ 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): Share {
return $this->wrapExecution($input, $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));
});
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/RemoveShareSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function configure(): void {
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
->addArgument('class', InputArgument::REQUIRED, 'Source class')
->addArgument('value', InputArgument::REQUIRED, 'Source value');
parent::configure();
}

#[\Override]
Expand All @@ -36,7 +37,7 @@ 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): Share {
return $this->wrapExecution($input, $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));
});
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/SelectSharePermissionPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function configure(): void {
->setDescription('Select a permission preset for a share.')
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
->addArgument('permission-preset', InputArgument::REQUIRED, 'Permission preset');
parent::configure();
}

#[\Override]
Expand All @@ -32,7 +33,7 @@ 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): Share {
return $this->wrapExecution($input, $output, function () use ($id, $permissionPresetClass): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->selectSharePermissionPreset($this->accessContext, $share, $permissionPresetClass);
});
Expand Down
22 changes: 21 additions & 1 deletion apps/sharing/lib/Command/SharingBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use OCP\IUserManager;
use OCP\L10N\IFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -40,10 +42,28 @@ public function __construct(
$this->accessContext = new ShareAccessContext(overrideChecks: true);
}

#[\Override]
public function configure(): void {
$this
->addOption('actor', null, InputOption::VALUE_REQUIRED, 'User ID to use as the actor for any share modification');
parent::configure();
}

protected function applyActor(InputInterface $input): void {
/** @var ?string $actorId */
$actorId = $input->getOption('actor');

if ($actorId !== null) {
$actor = $this->userManager->get($actorId);
$this->accessContext = new ShareAccessContext(currentUser: $actor, overrideChecks: true);
}
}

/**
* @param Closure():Share $closure
*/
protected function wrapExecution(OutputInterface $output, Closure $closure): int {
protected function wrapExecution(InputInterface $input, OutputInterface $output, Closure $closure): int {
$this->applyActor($input);

try {
try {
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/UpdateSharePermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function configure(): void {
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
->addArgument('class', InputArgument::REQUIRED, 'Permission class')
->addArgument('enabled', InputArgument::REQUIRED, 'Permission enabled. Only takes "true" or "false".');
parent::configure();
}

#[\Override]
Expand All @@ -37,7 +38,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$enabled = $input->getArgument('enabled');
$enabled = $enabled === 'true';

return $this->wrapExecution($output, function () use ($id, $class, $enabled): Share {
return $this->wrapExecution($input, $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));
});
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/UpdateShareProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function configure(): void {
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
->addArgument('class', InputArgument::REQUIRED, 'Property class')
->addArgument('value', InputArgument::OPTIONAL, 'Property value. Omitting it will remove the value.');
parent::configure();
}

#[\Override]
Expand All @@ -36,7 +37,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
/** @var ?string $value */
$value = $input->getArgument('value');

return $this->wrapExecution($output, function () use ($id, $class, $value): Share {
return $this->wrapExecution($input, $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));
});
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/UpdateShareRecipientSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function configure(): void {
->addArgument('class', InputArgument::REQUIRED, 'Recipient class')
->addArgument('value', InputArgument::REQUIRED, 'Recipient value')
->addArgument('instance', InputArgument::OPTIONAL, 'Recipient instance');
parent::configure();
}

#[\Override]
Expand All @@ -42,7 +43,7 @@ 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): Share {
return $this->wrapExecution($input, $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);
});
Expand Down
3 changes: 2 additions & 1 deletion apps/sharing/lib/Command/UpdateShareState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function configure(): void {
->setDescription('Update the state of a share.')
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
->addArgument('state', InputArgument::REQUIRED, 'State');
parent::configure();
}

#[\Override]
Expand All @@ -33,7 +34,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$state = $input->getArgument('state');
$state = ShareState::from($state);

return $this->wrapExecution($output, function () use ($id, $state): Share {
return $this->wrapExecution($input, $output, function () use ($id, $state): Share {
$share = $this->manager->getShare($this->accessContext, $id);
return $this->manager->updateShareState($this->accessContext, $share, $state);
});
Expand Down
1 change: 1 addition & 0 deletions apps/sharing/tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private function runCommand(ShareAccessContext $accessContext, string $class, ar
throw new RuntimeException('Command class ' . $class . ' is not allowed to be used unless added to the array.');
}

$options[] = ['actor', null];
$input = $this->createMock(Input::class);
$input
->expects($this->exactly(count($arguments)))
Expand Down
Loading