Skip to content

Commit d3aba32

Browse files
authored
Merge pull request #63190 from nextcloud/unified-sharing-cli-actor
feat: allow specifying the actor in unified sharing cli
2 parents 07d9904 + ce2e782 commit d3aba32

15 files changed

Lines changed: 49 additions & 12 deletions

apps/sharing/lib/Command/AddShareRecipient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function configure(): void {
2727
->addArgument('class', InputArgument::REQUIRED, 'Recipient class')
2828
->addArgument('value', InputArgument::REQUIRED, 'Recipient value')
2929
->addArgument('instance', InputArgument::OPTIONAL, 'Recipient instance');
30+
parent::configure();
3031
}
3132

3233
#[\Override]
@@ -40,7 +41,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
4041
/** @var ?non-empty-string $instance */
4142
$instance = $input->getArgument('instance');
4243

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

apps/sharing/lib/Command/AddShareSource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function configure(): void {
2525
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
2626
->addArgument('class', InputArgument::REQUIRED, 'Source class')
2727
->addArgument('value', InputArgument::REQUIRED, 'Source value');
28+
parent::configure();
2829
}
2930

3031
#[\Override]
@@ -36,7 +37,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3637
/** @var non-empty-string $value */
3738
$value = $input->getArgument('value');
3839

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

apps/sharing/lib/Command/CreateShare.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function configure(): void {
2626
->setName('sharing:create-share')
2727
->setDescription('Create a new share.')
2828
->addArgument('owner', InputArgument::REQUIRED, 'User ID of the owner');
29+
parent::configure();
2930
}
3031

3132
#[\Override]
@@ -37,6 +38,6 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3738
throw new ShareInvalidException('The owner does not exist: ' . $ownerUid, Server::get(IFactory::class)->get('sharing')->t('The owner does not exist: %s', [$ownerUid]));
3839
}
3940

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

apps/sharing/lib/Command/DeleteShare.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public function configure(): void {
2424
->setName('sharing:delete-share')
2525
->setDescription('Delete a share.')
2626
->addArgument('id', InputArgument::REQUIRED, 'Share ID');
27+
parent::configure();
2728
}
2829

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

3436
try {
3537
try {

apps/sharing/lib/Command/GetShare.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ public function configure(): void {
2121
->setName('sharing:get-share')
2222
->setDescription('Get a share.')
2323
->addArgument('id', InputArgument::REQUIRED, 'Share ID');
24+
parent::configure();
2425
}
2526

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

31-
return $this->wrapExecution($output, fn (): Share => $this->manager->getShare($this->accessContext, $id));
32+
return $this->wrapExecution($input, $output, fn (): Share => $this->manager->getShare($this->accessContext, $id));
3233
}
3334
}

apps/sharing/lib/Command/GetShares.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ public function configure(): void {
2727
->addOption('filter-source-type-value', '', InputOption::VALUE_REQUIRED, 'Source type value to filter by')
2828
->addOption('last-share-id', '', InputOption::VALUE_REQUIRED, 'Share ID to use as an offset')
2929
->addOption('limit', '', InputOption::VALUE_REQUIRED, 'Maximum number of shares to return');
30+
parent::configure();
3031
}
3132

3233
#[\Override]
3334
public function execute(InputInterface $input, OutputInterface $output): int {
35+
$this->applyActor($input);
36+
3437
/** @var ?class-string<IShareSourceType> $filterSourceTypeClass */
3538
$filterSourceTypeClass = $input->getOption('filter-source-type-class');
3639
/** @var ?class-string<IShareSourceType> $filterSourceTypeValue */

apps/sharing/lib/Command/RemoveShareRecipient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function configure(): void {
2626
->addArgument('class', InputArgument::REQUIRED, 'Recipient class')
2727
->addArgument('value', InputArgument::REQUIRED, 'Recipient value')
2828
->addArgument('instance', InputArgument::OPTIONAL, 'Recipient instance');
29+
parent::configure();
2930
}
3031

3132
#[\Override]
@@ -39,7 +40,7 @@ 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): Share {
43+
return $this->wrapExecution($input, $output, function () use ($id, $class, $value, $instance): Share {
4344
$share = $this->manager->getShare($this->accessContext, $id);
4445
return $this->manager->removeShareRecipient($this->accessContext, $share, new ShareRecipient($class, $value, $instance));
4546
});

apps/sharing/lib/Command/RemoveShareSource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function configure(): void {
2525
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
2626
->addArgument('class', InputArgument::REQUIRED, 'Source class')
2727
->addArgument('value', InputArgument::REQUIRED, 'Source value');
28+
parent::configure();
2829
}
2930

3031
#[\Override]
@@ -36,7 +37,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3637
/** @var non-empty-string $value */
3738
$value = $input->getArgument('value');
3839

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

apps/sharing/lib/Command/SelectSharePermissionPreset.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function configure(): void {
2323
->setDescription('Select a permission preset for a share.')
2424
->addArgument('id', InputArgument::REQUIRED, 'Share ID')
2525
->addArgument('permission-preset', InputArgument::REQUIRED, 'Permission preset');
26+
parent::configure();
2627
}
2728

2829
#[\Override]
@@ -32,7 +33,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
3233
/** @var class-string<ISharePermissionPreset> $permissionPresetClass */
3334
$permissionPresetClass = $input->getArgument('permission-preset');
3435

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

apps/sharing/lib/Command/SharingBase.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use OCP\IUserManager;
2323
use OCP\L10N\IFactory;
2424
use Symfony\Component\Console\Command\Command;
25+
use Symfony\Component\Console\Input\InputInterface;
26+
use Symfony\Component\Console\Input\InputOption;
2527
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2628
use Symfony\Component\Console\Output\OutputInterface;
2729

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

45+
#[\Override]
46+
public function configure(): void {
47+
$this
48+
->addOption('actor', null, InputOption::VALUE_REQUIRED, 'User ID to use as the actor for any share modification');
49+
parent::configure();
50+
}
51+
52+
protected function applyActor(InputInterface $input): void {
53+
/** @var ?string $actorId */
54+
$actorId = $input->getOption('actor');
55+
56+
if ($actorId !== null) {
57+
$actor = $this->userManager->get($actorId);
58+
$this->accessContext = new ShareAccessContext(currentUser: $actor, overrideChecks: true);
59+
}
60+
}
61+
4362
/**
4463
* @param Closure():Share $closure
4564
*/
46-
protected function wrapExecution(OutputInterface $output, Closure $closure): int {
65+
protected function wrapExecution(InputInterface $input, OutputInterface $output, Closure $closure): int {
66+
$this->applyActor($input);
4767

4868
try {
4969
try {

0 commit comments

Comments
 (0)