Skip to content
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

Revert "[stable28] Apply group limit on remove from group" #47326

Merged
merged 1 commit into from
Aug 19, 2024
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
107 changes: 0 additions & 107 deletions cypress/e2e/files_sharing/limit_to_same_group.cy.ts

This file was deleted.

45 changes: 2 additions & 43 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
use OCP\Mail\IMailer;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IAttributes;
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
use function str_starts_with;
Expand Down Expand Up @@ -103,7 +102,6 @@ public function __construct(
IFactory $l10nFactory,
IURLGenerator $urlGenerator,
ITimeFactory $timeFactory,
private IManager $shareManager,
) {
$this->dbConn = $connection;
$this->userManager = $userManager;
Expand Down Expand Up @@ -1306,7 +1304,6 @@ public function groupDeleted($gid) {
*
* @param string $uid
* @param string $gid
* @return void
*/
public function userDeletedFromGroup($uid, $gid) {
/*
Expand All @@ -1318,7 +1315,7 @@ public function userDeletedFromGroup($uid, $gid) {
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));

$cursor = $qb->executeQuery();
$cursor = $qb->execute();
$ids = [];
while ($row = $cursor->fetch()) {
$ids[] = (int)$row['id'];
Expand All @@ -1335,45 +1332,7 @@ public function userDeletedFromGroup($uid, $gid) {
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
$qb->executeStatement();
}
}

if ($this->shareManager->shareWithGroupMembersOnly()) {
$user = $this->userManager->get($uid);
if ($user === null) {
return;
}
$userGroups = $this->groupManager->getUserGroupIds($user);

// Delete user shares received by the user from users in the group.
$userReceivedShares = $this->shareManager->getSharedWith($uid, IShare::TYPE_USER, null, -1);
foreach ($userReceivedShares as $share) {
$owner = $this->userManager->get($share->getSharedBy());
if ($owner === null) {
continue;
}
$ownerGroups = $this->groupManager->getUserGroupIds($owner);
$mutualGroups = array_intersect($userGroups, $ownerGroups);

if (count($mutualGroups) === 0) {
$this->shareManager->deleteShare($share);
}
}

// Delete user shares from the user to users in the group.
$userEmittedShares = $this->shareManager->getSharesBy($uid, IShare::TYPE_USER, null, true, -1);
foreach ($userEmittedShares as $share) {
$recipient = $this->userManager->get($share->getSharedWith());
if ($recipient === null) {
continue;
}
$recipientGroups = $this->groupManager->getUserGroupIds($recipient);
$mutualGroups = array_intersect($userGroups, $recipientGroups);

if (count($mutualGroups) === 0) {
$this->shareManager->deleteShare($share);
}
$qb->execute();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ protected function defaultShareProvider() {
$this->serverContainer->getL10NFactory(),
$this->serverContainer->getURLGenerator(),
$this->serverContainer->query(ITimeFactory::class),
$this->serverContainer->get(IManager::class),
);
}

Expand Down
23 changes: 6 additions & 17 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;

Expand Down Expand Up @@ -83,9 +82,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
/** @var ITimeFactory|MockObject */
protected $timeFactory;

/** @var IShareManager&MockObject */
protected $shareManager;

protected function setUp(): void {
$this->dbConn = \OC::$server->getDatabaseConnection();
$this->userManager = $this->createMock(IUserManager::class);
Expand All @@ -97,7 +93,6 @@ protected function setUp(): void {
$this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->shareManager = $this->createMock(IShareManager::class);

$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
$this->timeFactory->expects($this->any())->method('now')->willReturn(new \DateTimeImmutable("2023-05-04 00:00 Europe/Berlin"));
Expand All @@ -114,8 +109,7 @@ protected function setUp(): void {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->timeFactory,
$this->shareManager,
$this->timeFactory
);
}

Expand Down Expand Up @@ -476,8 +470,7 @@ public function testDeleteSingleShare() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->timeFactory,
$this->shareManager,
$this->timeFactory
])
->setMethods(['getShareById'])
->getMock();
Expand Down Expand Up @@ -572,8 +565,7 @@ public function testDeleteGroupShareWithUserGroupShares() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->timeFactory,
$this->shareManager,
$this->timeFactory
])
->setMethods(['getShareById'])
->getMock();
Expand Down Expand Up @@ -2533,8 +2525,7 @@ public function testGetSharesInFolder() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->timeFactory,
$this->shareManager,
$this->timeFactory
);

$password = md5(time());
Expand Down Expand Up @@ -2632,8 +2623,7 @@ public function testGetAccessListNoCurrentAccessRequired() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->timeFactory,
$this->shareManager,
$this->timeFactory
);

$u1 = $userManager->createUser('testShare1', 'test');
Expand Down Expand Up @@ -2729,8 +2719,7 @@ public function testGetAccessListCurrentAccessRequired() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->timeFactory,
$this->shareManager,
$this->timeFactory
);

$u1 = $userManager->createUser('testShare1', 'test');
Expand Down
Loading