-
-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(sharing): set STATUS_ACCEPTED when creating USERGROUP subshare on… #59813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
miaulalala
wants to merge
1
commit into
master
Choose a base branch
from
fix/noid/fix-owncloud-group-share-rename
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
apps/files_sharing/lib/Command/FixOwncloudGroupSubshareStatus.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Files_Sharing\Command; | ||
|
|
||
| use OC\Core\Command\Base; | ||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
| use OCP\IDBConnection; | ||
| use OCP\Share\IShare; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| /** | ||
| * Fixes USERGROUP subshares that were created without `accepted = STATUS_ACCEPTED` | ||
| * by a rename on an ownCloud-migrated instance. | ||
| * | ||
| * When an OC-migrated group share (which has no per-user USERGROUP subshare) is | ||
| * renamed for the first time, DefaultShareProvider::move() inserted a new USERGROUP | ||
| * row without setting `accepted`. The column defaulted to 0 (STATUS_PENDING), causing | ||
| * MountProvider to skip the share on the next login — the file disappeared for the | ||
| * recipient. | ||
| * | ||
| * USERGROUP subshares with permissions = 0 were explicitly declined by the user | ||
| * and are left untouched. | ||
| */ | ||
| class FixOwncloudGroupSubshareStatus extends Base { | ||
|
|
||
| public function __construct( | ||
| private IDBConnection $connection, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| #[\Override] | ||
| protected function configure(): void { | ||
| $this | ||
| ->setName('sharing:fix-owncloud-group-shares') | ||
| ->setDescription('Fix group share subshares left pending after renaming on an ownCloud-migrated instance') | ||
| ->addOption( | ||
| 'dry-run', | ||
| null, | ||
| InputOption::VALUE_NONE, | ||
| 'Show how many shares would be fixed without making any changes', | ||
| ); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function execute(InputInterface $input, OutputInterface $output): int { | ||
| $dryRun = $input->getOption('dry-run'); | ||
|
|
||
| $qb = $this->connection->getQueryBuilder(); | ||
| $count = (int)$qb->select($qb->func()->count('id')) | ||
| ->from('share') | ||
| ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP, IQueryBuilder::PARAM_INT))) | ||
| ->andWhere($qb->expr()->eq('accepted', $qb->createNamedParameter(IShare::STATUS_PENDING, IQueryBuilder::PARAM_INT))) | ||
| ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))) | ||
| ->executeQuery() | ||
| ->fetchOne(); | ||
|
|
||
| if ($count === 0) { | ||
| $output->writeln('No affected group share subshares found.'); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| if ($dryRun) { | ||
| $output->writeln("Would fix <info>$count</info> group share subshare(s) (dry-run, no changes made)."); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| $qb = $this->connection->getQueryBuilder(); | ||
| $qb->update('share') | ||
| ->set('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED, IQueryBuilder::PARAM_INT)) | ||
| ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP, IQueryBuilder::PARAM_INT))) | ||
| ->andWhere($qb->expr()->eq('accepted', $qb->createNamedParameter(IShare::STATUS_PENDING, IQueryBuilder::PARAM_INT))) | ||
| ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))) | ||
| ->executeStatement(); | ||
|
|
||
| $output->writeln("Fixed <info>$count</info> group share subshare(s)."); | ||
| return self::SUCCESS; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
apps/files_sharing/tests/Command/FixOwncloudGroupSubshareStatusTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Files_Sharing\Tests\Command; | ||
|
|
||
| use OCA\Files_Sharing\Command\FixOwncloudGroupSubshareStatus; | ||
| use OCA\Files_Sharing\Tests\TestCase; | ||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
| use OCP\IDBConnection; | ||
| use OCP\Server; | ||
| use OCP\Share\IShare; | ||
| use Symfony\Component\Console\Tester\CommandTester; | ||
|
|
||
| #[\PHPUnit\Framework\Attributes\Group(name: 'DB')] | ||
| class FixOwncloudGroupSubshareStatusTest extends TestCase { | ||
|
|
||
| private IDBConnection $connection; | ||
| private CommandTester $commandTester; | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
| $this->connection = Server::get(IDBConnection::class); | ||
| $this->commandTester = new CommandTester(new FixOwncloudGroupSubshareStatus($this->connection)); | ||
| $this->cleanDB(); | ||
| } | ||
|
|
||
| protected function tearDown(): void { | ||
| $this->cleanDB(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function cleanDB(): void { | ||
| $this->connection->getQueryBuilder()->delete('share')->executeStatement(); | ||
| } | ||
|
|
||
| private function insertShare(int $shareType, int $accepted, int $permissions): int { | ||
| $qb = $this->connection->getQueryBuilder(); | ||
| $qb->insert('share') | ||
| ->values([ | ||
| 'share_type' => $qb->createNamedParameter($shareType, IQueryBuilder::PARAM_INT), | ||
| 'share_with' => $qb->createNamedParameter('user1'), | ||
| 'uid_owner' => $qb->createNamedParameter('owner'), | ||
| 'uid_initiator' => $qb->createNamedParameter('owner'), | ||
| 'parent' => $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT), | ||
| 'item_type' => $qb->createNamedParameter('file'), | ||
| 'item_source' => $qb->createNamedParameter('42'), | ||
| 'item_target' => $qb->createNamedParameter('/file'), | ||
| 'file_source' => $qb->createNamedParameter(42, IQueryBuilder::PARAM_INT), | ||
| 'file_target' => $qb->createNamedParameter('/file'), | ||
| 'permissions' => $qb->createNamedParameter($permissions, IQueryBuilder::PARAM_INT), | ||
| 'stime' => $qb->createNamedParameter(time(), IQueryBuilder::PARAM_INT), | ||
| 'accepted' => $qb->createNamedParameter($accepted, IQueryBuilder::PARAM_INT), | ||
| ]) | ||
| ->executeStatement(); | ||
| return (int)$this->connection->lastInsertId('*PREFIX*share'); | ||
| } | ||
|
|
||
| private function getAccepted(int $id): int { | ||
| $qb = $this->connection->getQueryBuilder(); | ||
| return (int)$qb->select('accepted') | ||
| ->from('share') | ||
| ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) | ||
| ->executeQuery() | ||
| ->fetchOne(); | ||
| } | ||
|
|
||
| public function testFixesPendingSubshareWithPermissions(): void { | ||
| $id = $this->insertShare(IShare::TYPE_USERGROUP, IShare::STATUS_PENDING, 31); | ||
|
|
||
| $this->commandTester->execute([]); | ||
|
|
||
| $this->assertSame(IShare::STATUS_ACCEPTED, $this->getAccepted($id)); | ||
| $this->assertStringContainsString('Fixed', $this->commandTester->getDisplay()); | ||
| } | ||
|
|
||
| public function testDryRunShowsCountWithoutChanging(): void { | ||
| $id = $this->insertShare(IShare::TYPE_USERGROUP, IShare::STATUS_PENDING, 31); | ||
|
|
||
| $this->commandTester->execute(['--dry-run' => true]); | ||
|
|
||
| $this->assertSame(IShare::STATUS_PENDING, $this->getAccepted($id)); | ||
| $this->assertStringContainsString('dry-run', $this->commandTester->getDisplay()); | ||
| } | ||
|
|
||
| public function testDoesNotTouchDeclinedSubshare(): void { | ||
| // permissions = 0 means the user explicitly declined the share | ||
| $id = $this->insertShare(IShare::TYPE_USERGROUP, IShare::STATUS_PENDING, 0); | ||
|
|
||
| $this->commandTester->execute([]); | ||
|
|
||
| $this->assertSame(IShare::STATUS_PENDING, $this->getAccepted($id)); | ||
| $this->assertStringContainsString('No affected', $this->commandTester->getDisplay()); | ||
| } | ||
|
|
||
| public function testDoesNotTouchAlreadyAcceptedSubshare(): void { | ||
| $id = $this->insertShare(IShare::TYPE_USERGROUP, IShare::STATUS_ACCEPTED, 31); | ||
|
|
||
| $this->commandTester->execute([]); | ||
|
|
||
| $this->assertSame(IShare::STATUS_ACCEPTED, $this->getAccepted($id)); | ||
| $this->assertStringContainsString('No affected', $this->commandTester->getDisplay()); | ||
| } | ||
|
|
||
| public function testDoesNotTouchNonUsergroupShares(): void { | ||
| $id = $this->insertShare(IShare::TYPE_GROUP, IShare::STATUS_PENDING, 31); | ||
|
|
||
| $this->commandTester->execute([]); | ||
|
|
||
| $this->assertSame(IShare::STATUS_PENDING, $this->getAccepted($id)); | ||
| $this->assertStringContainsString('No affected', $this->commandTester->getDisplay()); | ||
| } | ||
|
|
||
| public function testFixesMultipleAffectedRows(): void { | ||
| $id1 = $this->insertShare(IShare::TYPE_USERGROUP, IShare::STATUS_PENDING, 31); | ||
| $id2 = $this->insertShare(IShare::TYPE_USERGROUP, IShare::STATUS_PENDING, 17); | ||
| $idDeclined = $this->insertShare(IShare::TYPE_USERGROUP, IShare::STATUS_PENDING, 0); | ||
|
|
||
| $this->commandTester->execute([]); | ||
|
|
||
| $this->assertSame(IShare::STATUS_ACCEPTED, $this->getAccepted($id1)); | ||
| $this->assertSame(IShare::STATUS_ACCEPTED, $this->getAccepted($id2)); | ||
| $this->assertSame(IShare::STATUS_PENDING, $this->getAccepted($idDeclined)); | ||
| $this->assertStringContainsString('2', $this->commandTester->getDisplay()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this will only match those broken shares? There must not be any false positives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to give admins the option to restore already broken shares. Some admins may not want to have that.
And yes, any oC share will have a permission other than
0if it wasn't rejected. So only oC shares that were accepted but haven't had the update for the new column will be in that state.