-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
1435abc
to
51d7a63
Compare
ab69c5d
to
ac60882
Compare
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.
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 |
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.
No need to provide your own interface: Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface
|
||
use eZ\Publish\API\Repository\Values\Content\Location; | ||
|
||
interface PermissionUtilInterface |
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.
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.
src/lib/Util/PermissionUtil.php
Outdated
@@ -18,8 +141,14 @@ class PermissionUtil | |||
* | |||
* @return array | |||
*/ | |||
public function flattenArrayOfLimitations(array $hasAccess): array | |||
private function flattenArrayOfLimitationsForCurrentUser(array $hasAccess): array |
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.
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: |
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.
Idea behind services/
directory was that we put service definitions there to avoid services.yml
getting bloated.
7fe4dae
to
6c703dd
Compare
6c703dd
to
a3a4bd8
Compare
} | ||
|
||
/** | ||
* @return array |
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.
* @return array | |
{@inheritdoc} |
} | ||
|
||
/** | ||
* @return array |
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.
* @return array | |
* {@inheritdoc} |
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
dump($this->languageChoiceLoader); |
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.
dump($this->languageChoiceLoader); |
} | ||
|
||
/** | ||
* @return array |
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.
* @return array | |
* {@inheritdoc} |
/** @var \eZ\Publish\API\Repository\LanguageService */ | ||
protected $languageService; | ||
|
||
/** @var array */ |
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.
/** @var array */ | |
/** @var string[] */ |
return strpos($location->pathString, $restrictedSubtree) === 0; | ||
})); | ||
|
||
return $canCreateInParentContentType |
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.
There is no need to check further criterions if $canCreateInParentContentType
fails, etc. so we should return false immediately without further checks.
a3a4bd8
to
aa79e65
Compare
public: false | ||
|
||
EzSystems\EzPlatformAdminUi\Permission\: | ||
resource: "../../../lib/Permission" |
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.
Quite risky. Given Permission
is a broad namespace you might not want every class to become a service.
|
||
return $contentTypes; | ||
}), | ||
'choice_loader' => $this->contentTypeChoiceLoader, |
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.
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; |
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.
Limit of one will make large number of queries to the database.
* | ||
* @return bool | ||
*/ | ||
public function canCreateInLocation(Location $location, $hasAccess): bool; |
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.
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.
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.
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.
aa79e65
to
73943b8
Compare
Works fine. After rebasing and retesting https://github.com/ezsystems/ezplatform-page-builder/pull/262#issuecomment-439427895 it can be approved by QA. |
…iew - refactor for assign section
…iew - choice loaders
…iew - content create policy in UDW
73943b8
to
b169ec9
Compare
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:
$ composer fix-cs
)