-
Notifications
You must be signed in to change notification settings - Fork 203
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
EZP-30997: Fixed permission checks when copying translations during publishing #2858
Conversation
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.
Overall looks good, some minor adjustments are required:
eZ/Publish/API/Repository/Tests/Limitation/LanguageLimitationTest.php
Outdated
Show resolved
Hide resolved
While reviewing once again #2846 I've discovered yet another bug here. Consider the following use case: public function testPublishVersionTranslationIsNotAllowed(): void
{
$repository = $this->getRepository();
$contentService = $repository->getContentService();
$permissionResolver = $repository->getPermissionResolver();
$britishEditor = $this->createEditorUserWithLanguageLimitation(['eng-GB'], 'editor-uk');
$americanEditor = $this->createEditorUserWithLanguageLimitation(['eng-US'], 'editor-us');
// British editor publishes BrE content
$permissionResolver->setCurrentUserReference($britishEditor);
$folder = $this->createFolder(['eng-GB' => 'BrE Folder'], 2);
// American editor creates and saves AmE draft
$permissionResolver->setCurrentUserReference($americanEditor);
$folder = $contentService->loadContent($folder->id);
$folderDraft = $contentService->createContentDraft($folder->contentInfo);
$folderUpdateStruct = $contentService->newContentUpdateStruct();
$folderUpdateStruct->setField('name', 'AmE Folder', 'eng-US');
$folderDraft = $contentService->updateContent(
$folderDraft->versionInfo,
$folderUpdateStruct
);
// British editor tries to publish AmE translation
$permissionResolver->setCurrentUserReference($britishEditor);
$folderDraftVersionInfo = $contentService->loadVersionInfo(
$folderDraft->contentInfo,
$folderDraft->versionInfo->versionNo
);
self::assertTrue($folderDraftVersionInfo->isDraft());
$this->expectException(UnauthorizedException::class);
$this->expectExceptionMessage("User does not have access to 'publish' 'content'");
$contentService->publishVersion($folderDraftVersionInfo, ['eng-US']);
}
private function createEditorUserWithLanguageLimitation(
array $allowedTranslationsList,
string $login = 'editor'
): User {
$limitations = [
// limitation for specific translations
new LanguageLimitation(['limitationValues' => $allowedTranslationsList]),
];
return $this->createUserWithPolicies(
$login,
[
['module' => 'content', 'function' => 'read'],
['module' => 'content', 'function' => 'versionread'],
['module' => 'content', 'function' => 'view_embed'],
['module' => 'content', 'function' => 'create', 'limitations' => $limitations],
['module' => 'content', 'function' => 'edit', 'limitations' => $limitations],
['module' => 'content', 'function' => 'publish', 'limitations' => $limitations],
]
);
} I'm not sure if this is reproducible with AdminUI (depends if ATM it's possible to edit someone else's draft - don't remember). However for the API it's an issue. |
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.
Almost ok ;)
eZ/Publish/API/Repository/Tests/Values/User/Limitation/LanguageLimitationTest.php
Show resolved
Hide resolved
eZ/Publish/API/Repository/Tests/Values/User/Limitation/LanguageLimitationTest.php
Show resolved
Hide resolved
eZ/Publish/API/Repository/Tests/Values/User/Limitation/LanguageLimitationTest.php
Show resolved
Hide resolved
eZ/Publish/API/Repository/Tests/Values/User/Limitation/LanguageLimitationTest.php
Show resolved
Hide resolved
@mikadamczyk one more request - could you incorporate #2846 here as well, as it touches the same portion of code? Would be easier to test. |
Sure @alongosz I thought that they ware divided by some purpose, but definitely it touches the same part of code |
Yes, initially they were, but given the changes here it no longer makes sense :) |
Co-Authored-By: Andrew Longosz <alongosz@users.noreply.github.com>
eZ/Publish/API/Repository/Tests/Values/User/Limitation/LanguageLimitationTest.php
Show resolved
Hide resolved
eZ/Publish/API/Repository/Tests/Values/User/Limitation/LanguageLimitationTest.php
Show resolved
Hide resolved
Failure was caused by wrong conflict resolution when merging #2858 into master
7.5
TODO:
$ composer fix-cs
).