Skip to content

Conversation

@adriendupuis
Copy link
Contributor

@adriendupuis adriendupuis commented Sep 6, 2023

Question Answer
JIRA Ticket N/A
Versions 2.5, 3.3, 4.5+
Edition All

Tested with a controller extending Ibexa\Core\MVC\Symfony\Controller\Controller:

$this->getRepository()->getPermissionResolver()->canUser('content', 'read', $content, $location);
$this->isGranted(new Attribute('content', 'read', ['valueObject' => $content, 'targets' => $location]));

In both case, it ends with error "Ibexa\Core\Repository\Permission\CachedPermissionService::canUser(): Argument #4 ($targets) must be of type array, Ibexa\Core\Repository\Values\Content\Location given" (isGranted uses canUser)

The fix seems to be to wrap the "target" into an array, at least according to https://github.com/ibexa/core/blob/main/src/contracts/Repository/PermissionResolver.php#L71

The example was already wrong in ezsystems/ezpublish-kernel@7e71008#diff-99575a283389178639446fcd29841d374d98f628338e9607339e24eedeb86915R46-R67
See ibexa/core#273 fix for 4.5 and future versions.

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Redirects cover removed/moved pages
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

In both case, it ended with error "Ibexa\Core\Repository\Permission\CachedPermissionService::canUser(): Argument #4 ($targets) must be of type array, Ibexa\Core\Repository\Values\Content\Location given"
@adriendupuis adriendupuis marked this pull request as ready for review September 6, 2023 12:12
@adriendupuis adriendupuis requested a review from a team September 6, 2023 12:12
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>
@adriendupuis adriendupuis merged commit 3d3483c into master Sep 8, 2023
@adriendupuis adriendupuis deleted the fix-permission-check branch September 8, 2023 07:27
adriendupuis added a commit that referenced this pull request Sep 8, 2023
* permission_overview.md: Fix canUser 4th argument

In both case, it ended with error "Ibexa\Core\Repository\Permission\CachedPermissionService::canUser(): Argument #4 ($targets) must be of type array, Ibexa\Core\Repository\Values\Content\Location given"

* permission_overview.md: array() → []

Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>

---------

Co-authored-by: Adrien Dupuis <adrien.dupuis@ibexa.co>
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>
(cherry picked from commit 3d3483c)
adriendupuis added a commit that referenced this pull request Sep 8, 2023
* permission_overview.md: Fix canUser 4th argument

In both case, it ended with error "Ibexa\Core\Repository\Permission\CachedPermissionService::canUser(): Argument #4 ($targets) must be of type array, Ibexa\Core\Repository\Values\Content\Location given"

* permission_overview.md: array() → []

Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>

---------

Co-authored-by: Adrien Dupuis <adrien.dupuis@ibexa.co>
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>

(cherry picked from commit 3d3483c)
adriendupuis added a commit that referenced this pull request Sep 8, 2023
* permission_overview.md: Fix canUser 4th argument

In both case, it ended with error "Ibexa\Core\Repository\Permission\CachedPermissionService::canUser(): Argument #4 ($targets) must be of type array, Ibexa\Core\Repository\Values\Content\Location given"

* permission_overview.md: array() → []

Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>

---------

Co-authored-by: Adrien Dupuis <adrien.dupuis@ibexa.co>
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>

(cherry picked from commit 3d3483c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants