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

Merge branch '1.3' of ezsystems/ezplatform-kernel into 4.5 #346

Merged
merged 2 commits into from
Mar 8, 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
25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -34730,11 +34730,6 @@ parameters:
count: 4
path: tests/integration/Core/Repository/LocationServiceTest.php

-
message: "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: tests/integration/Core/Repository/LocationServiceTest.php

-
message: "#^Cannot call method getContentInfo\\(\\) on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location\\|null\\.$#"
count: 2
Expand Down Expand Up @@ -44685,11 +44680,6 @@ parameters:
count: 1
path: tests/lib/FieldType/Url/Gateway/DoctrineStorageTest.php

-
message: "#^Cannot call method fetchAllAssociative\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 4
path: tests/lib/FieldType/Url/Gateway/DoctrineStorageTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\FieldType\\\\Url\\\\Gateway\\\\DoctrineStorageTest\\:\\:testGetIdUrlMap\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -51545,11 +51535,6 @@ parameters:
count: 1
path: tests/lib/Persistence/Legacy/Content/FieldValueConverterRegistryTest.php

-
message: "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 5
path: tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Persistence\\\\Legacy\\\\Content\\\\Gateway\\\\DoctrineDatabaseTest\\:\\:assertContentVersionAttributesLanguages\\(\\) has parameter \\$expectation with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -52155,11 +52140,6 @@ parameters:
count: 1
path: tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTest.php

-
message: "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: tests/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabaseTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Persistence\\\\Legacy\\\\Content\\\\Location\\\\Gateway\\\\DoctrineDatabaseTest\\:\\:assertLoadLocationProperties\\(\\) has parameter \\$locationData with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -54575,11 +54555,6 @@ parameters:
count: 4
path: tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php

-
message: "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: tests/lib/Persistence/Legacy/Content/UrlAlias/UrlAliasHandlerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Persistence\\\\Legacy\\\\Content\\\\UrlAlias\\\\UrlAliasHandlerTest\\:\\:assertVirtualUrlAliasValid\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
14 changes: 10 additions & 4 deletions src/lib/Limitation/UserGroupLimitationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Ibexa\Core\Limitation;

use Ibexa\Contracts\Core\Limitation\Type as SPILimitationTypeInterface;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct;
Expand Down Expand Up @@ -190,10 +191,15 @@ public function getCriterion(APILimitationValue $value, APIUserReference $curren
}

$groupIds = [];
$currentUserLocations = $this->persistence->locationHandler()->loadLocationsByContent($currentUser->getUserId());
if (!empty($currentUserLocations)) {
foreach ($currentUserLocations as $currentUserLocation) {
$groupIds[] = $currentUserLocation->parentId;
$locationHandler = $this->persistence->locationHandler();
$currentUserLocations = $locationHandler->loadLocationsByContent($currentUser->getUserId());
foreach ($currentUserLocations as $currentUserLocation) {
try {
$parentLocation = $locationHandler->load($currentUserLocation->parentId);
$groupIds[] = $parentLocation->contentId;
} catch (NotFoundException $e) {
// there is no need for any action - carrying on with checking other user locations
continue;
}
}

Expand Down
96 changes: 96 additions & 0 deletions tests/integration/Core/Limitation/UserGroupLimitationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Core\Limitation;

use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\ContentTypeLimitation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\LocationLimitation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\UserGroupLimitation;
use Ibexa\Tests\Integration\Core\Repository\Limitation\PermissionResolver\BaseLimitationIntegrationTest;

final class UserGroupLimitationTest extends BaseLimitationIntegrationTest
{
private const FOLDER_CONTENT_TYPE_ID = 1;

public function testHasUserWithUserGroupLimitationAccessToCreatedLocations(): void
{
$repository = $this->getRepository();

$user = $this->createUserWithPolicies('test_user', $this->getPermissions());
$userGroups = $repository->getUserService()->loadUserGroupsOfUser($user);
$userGroupIds = [];
foreach ($userGroups as $userGroup) {
$userGroupIds[] = $userGroup->id;
}

$repository->getPermissionResolver()->setCurrentUserReference($user);

$parentFolder = $this->createFolder(
['eng-US' => 'Parent folder'],
2
);
$childFolder = $this->createFolder(
['eng-US' => 'Child folder'],
$parentFolder->contentInfo->getMainLocationId()
);

$this->refreshSearch($repository);

$query = new LocationQuery();
$query->filter = new Criterion\LogicalAnd([
new Criterion\ContentTypeId(self::FOLDER_CONTENT_TYPE_ID),
new Criterion\UserMetadata('group', 'in', $userGroupIds),
]);

$results = $repository->getSearchService()->findLocations($query)->searchHits;
$resultLocationIds = array_map(static function (SearchHit $hit): int {
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */
$location = $hit->valueObject;

return $location->id;
}, $results);

self::assertContains($parentFolder->contentInfo->getMainLocationId(), $resultLocationIds);
self::assertContains($childFolder->contentInfo->getMainLocationId(), $resultLocationIds);
}

/**
* @return array<array<string, mixed>>
*/
private function getPermissions(): array
{
return [
[
'module' => 'content',
'function' => 'create',
],
[
'module' => 'content',
'function' => 'publish',
],
[
'module' => 'content',
'function' => 'read',
'limitations' => [
new LocationLimitation(['limitationValues' => [2]]),
],
],
[
'module' => 'content',
'function' => 'read',
'limitations' => [
new ContentTypeLimitation(['limitationValues' => [self::FOLDER_CONTENT_TYPE_ID]]),
new UserGroupLimitation(['limitationValues' => [1]]),
],
],
];
}
}
Loading