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-29742: Implement permissions for Content/Create in Content item view #713

Merged
merged 5 commits into from
Nov 20, 2018

Conversation

mikadamczyk
Copy link
Contributor

@mikadamczyk mikadamczyk commented Nov 13, 2018

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

This PR adds additional checks when a user tries to add new content. If the user has no permission to create content in location than "create button" is disabled. When user can create content only in some of languages or CT those lists are limited.

https://github.com/ezsystems/ezplatform-page-builder/pull/262

Checklist:

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

Copy link
Contributor

@webhdx webhdx left a comment

Choose a reason for hiding this comment

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

A few remarks + my initial comments reported via Slack.

use EzSystems\EzPlatformAdminUi\Util\PermissionUtilInterface;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;

class PermissionAwareContentTypeChoiceListProvider implements ChoiceListProviderInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to provide your own interface: Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface


use eZ\Publish\API\Repository\Values\Content\Location;

interface PermissionUtilInterface
Copy link
Contributor

@webhdx webhdx Nov 14, 2018

Choose a reason for hiding this comment

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

Utility class with an interface is bad by a design. This is clearly more than a utility class thus it can be renamed to e.g. PermissionChecker. Also I'd think about extracting some parts to other classes i.e. part related to user groups.

@@ -18,8 +141,14 @@ class PermissionUtil
*
* @return array
*/
public function flattenArrayOfLimitations(array $hasAccess): array
private function flattenArrayOfLimitationsForCurrentUser(array $hasAccess): array
Copy link
Contributor

Choose a reason for hiding this comment

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

If you go as far as changing class name please leave original PermissionUtil in place to avoid breaking changes (here you are changing method visibility).


EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\ContentTypeChoiceListProvider: ~

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\LanguageChoiceListProvider:
Copy link
Contributor

Choose a reason for hiding this comment

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

Idea behind services/ directory was that we put service definitions there to avoid services.yml getting bloated.

@mikadamczyk mikadamczyk force-pushed the EZP-29742-wip branch 3 times, most recently from 7fe4dae to 6c703dd Compare November 15, 2018 08:42
@ezsystems ezsystems deleted a comment from ezrobot Nov 15, 2018
}

/**
* @return array
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return array
{@inheritdoc}

}

/**
* @return array
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return array
* {@inheritdoc}

}

public function buildForm(FormBuilderInterface $builder, array $options)
{
dump($this->languageChoiceLoader);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dump($this->languageChoiceLoader);

}

/**
* @return array
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return array
* {@inheritdoc}

/** @var \eZ\Publish\API\Repository\LanguageService */
protected $languageService;

/** @var array */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/** @var array */
/** @var string[] */

return strpos($location->pathString, $restrictedSubtree) === 0;
}));

return $canCreateInParentContentType
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to check further criterions if $canCreateInParentContentType fails, etc. so we should return false immediately without further checks.

public: false

EzSystems\EzPlatformAdminUi\Permission\:
resource: "../../../lib/Permission"
Copy link
Contributor

Choose a reason for hiding this comment

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

Quite risky. Given Permission is a broad namespace you might not want every class to become a service.


return $contentTypes;
}),
'choice_loader' => $this->contentTypeChoiceLoader,
Copy link
Contributor

@webhdx webhdx Nov 15, 2018

Choose a reason for hiding this comment

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

Does it need to be registered as a service? I'm pretty sure in Symfony's codebase they are initializing ChoiceLoaders on demand which for me makes sense as ChoiceLoader living in the container wastes memory. Large number of services makes your application slower.

Okay it would make Type class bloated with dependencies so I'm fine with your code.


class PermissionChecker implements PermissionCheckerInterface
{
private const USER_GROUPS_LIMIT = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Limit of one will make large number of queries to the database.

*
* @return bool
*/
public function canCreateInLocation(Location $location, $hasAccess): bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to hear others opinion on this but for me Permission namespace is very broad so PermissionCheckerInterface having canCreateInLocation method makes it badly designed. It should has more specific name i.e. LocationBasedPermissionCheckerInterface or the method should be a part of completely different interface.

Copy link
Member

Choose a reason for hiding this comment

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

You might be right, but for now, it's fine. If this class will begin to gain weight then we will refactor it by splitting into more specific classes.

@mikadamczyk mikadamczyk changed the title [WiP] EZP-29742: Implement permissions for Content/Create in Content item view EZP-29742: Implement permissions for Content/Create in Content item view Nov 15, 2018
@barbaragr barbaragr self-assigned this Nov 16, 2018
@barbaragr
Copy link

Works fine. After rebasing and retesting https://github.com/ezsystems/ezplatform-page-builder/pull/262#issuecomment-439427895 it can be approved by QA.

@lserwatka lserwatka merged commit deb399f into ezsystems:master Nov 20, 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.

6 participants