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

EZP-29734: As an Administrator I want to add Content Type limitation for Section/Assign policy #696

Merged
merged 1 commit into from
Oct 30, 2018

Conversation

mikadamczyk
Copy link
Contributor

Question Answer
Tickets https://jira.ez.no/browse/EZP-29734
Bug fix? no
New feature? yes
BC breaks? no
Tests pass? yes
Doc needed? no
License GPL-2.0

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

public function onUdwConfigResolve(ConfigResolveEvent $event): void
{
$configName = $event->getConfigName();
if ('single' !== $configName && 'multiple' !== $configName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need to check for single - I think we have only multiple.

$allowedContentTypesIds = array_unique(array_merge(...$allowedContentTypesIds));
foreach ($allowedContentTypesIds as $allowedContentTypeId) {
try {
$identifier = $this->contentTypeService->loadContentType($allowedContentTypeId)->identifier;
Copy link
Contributor

@andrerom andrerom Oct 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be very efficient, better if you can use ContentTypeService->loadContentTypeList($allowedContentTypesIds), to do that we need a second review of ezsystems/ezpublish-kernel#2444

Besides repeated loads that would avoid the loop and the try block (invalid content type id's will simply not be returned, just like the logic here already does)

*
* @return array
*/
public function flattenArrayOfLimitations(array $hasAccess): array

This comment was marked as resolved.

$this->permissionUtil = $permissionUtil;
$this->contentTypeService = $contentTypeService;
$hasAccess = $permissionResolver->hasAccess('section', 'assign');
$this->allowedContentTypesIdentifiers = is_array($hasAccess) ? $this->checkAllowedContentTypes($hasAccess) : [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be filled with all content types if $hasAccess is true? otherwise layer above would need to second guess if empty array means false or true, or?

foreach ($this->permissionUtil->flattenArrayOfLimitations($hasAccess) as $limitation) {
if ($limitation instanceof NewSectionLimitation) {
// If one of user limitation is NewSectionLimitation we check if user can assign Content to $section
return in_array($section->id, $limitation->limitationValues);
Copy link
Contributor

@andrerom andrerom Oct 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is iterating several roles and policies, this should not return here unless value is true.

Afaik you can do like in checkAllowedContentTypes() and collect all allowed sections before you do a in_array.

@@ -490,9 +507,25 @@ private function getSectionsNumbers(array $sections): array
* @param \eZ\Publish\API\Repository\Values\Content\Section $section
*
* @return bool
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
private function canUserAssignSectionToAnyContent(Section $section): bool
Copy link
Contributor

@andrerom andrerom Oct 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming, but something like canUserAssignSectionToSomeContent might be more fitting, given a true here is more like a "maybe", while a false is pretty accurate.

@mikadamczyk
Copy link
Contributor Author

@adamwojs can you take a look at it?

@barbaragr
Copy link

barbaragr commented Oct 30, 2018

  1. Add policies to the Editor role:
  • Setup/Administrate
  • Section/View
  • User/Login
  • Content/*
  • Section/Assign with Content Type: Article limitations
  1. Log in as an Editor
  2. Go to Content/Structure and create an Article
  3. Go to Admin/Sections, click assign button next to Design section
  4. Select created article, click (+) button and click Confirm

Actual result: Error 403 is show: Access denied

@barbaragr barbaragr self-assigned this Oct 30, 2018
@barbaragr
Copy link

barbaragr commented Oct 30, 2018

For Admin user after publishing an Article error 500 is thrown:

  1. Go to Content/Content structure
  2. Click Create and select Article
  3. Fill Title and Intro, click Publish

Actual result: Error 500 is thrown: None of the routers in the chain matched url '/admin/content/location/61' but article was published. For editor user (with policies mentioned above) everything works fine.

@mikadamczyk mikadamczyk force-pushed the EZP-29734 branch 3 times, most recently from a27a265 to 01b629e Compare October 30, 2018 13:34
@lserwatka
Copy link
Member

@mikadamczyk could you rebase here, as I merged #695

@mikadamczyk
Copy link
Contributor Author

@lserwatka done

@lserwatka lserwatka merged commit 74a82b5 into ezsystems:master Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

7 participants