Skip to content

Return partially populated OgRole entities when gathering default roles#237

Merged
amitaibu merged 12 commits into8.x-1.xfrom
return-partial-og-roles
Jun 17, 2016
Merged

Return partially populated OgRole entities when gathering default roles#237
amitaibu merged 12 commits into8.x-1.xfrom
return-partial-og-roles

Conversation

@pfrenssen
Copy link
Collaborator

In #217 (comment) @amitaibu suggested that we should return partially populated OgRole entities instead of dumb arrays containing role properties when retrieving the default roles that are created when saving a new group.

As a side effect this also fixes #232 and #216 and obsoletes #235.

/**
* {@inheritdoc}
*/
public function getName() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems slightly limited. Maybe it would be better to explode, but pop off the last element and use that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There should always be three elements in the current implementation. But I think you're on to something, this is indeed a bug. I don't think there is anything stopping people to use dashes in their entity type IDs and bundle IDs, which means that counting the dashes is not going to cut it.

I'll change it to match exactly "{$this->getGroupEntityTypeId()}-{$this->getGroupBundleId()}-$role_name", then we'll eliminate any dash-related problems.

@pfrenssen
Copy link
Collaborator Author

Addressed everything.

Now that the OgRole entities are created in the event subscriber I was able to remove a lot of the complexity from the event listener, just as @amitaibu predicted. A very nice bonus is also that we no longer need to inject the OgRole entity storage in the listener, meaning it doesn't need to be a service any more, meaning that the ugly ::reset() method could be removed!

If tests come back green this is ready for a fresh look.

@@ -187,6 +222,10 @@ public function save() {
throw new ConfigValueException('The group bundle can not be empty.');
}
Copy link
Owner

Choose a reason for hiding this comment

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

we seem to have a similar check in validate, however that one throws a different exception. Maybe consolidate it, and call validate() from here instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had a look at this but it is not really possible I think. The DefaultRoleEvent::validate() method is used to validate only the data that is necessary for the event listener to gather the default roles. This one is in OgRole::save() and validates everything required to successfully store the entity.

These are different use cases, and calling validate() from here will make OgRole depend on DefaultRoleEvent.

@amitaibu
Copy link
Owner

@pfrenssen , the recent changes have indeed cleaned up a lot, and it's much easier to follow the logic.

I've added a few comments, mostly about naming. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting a default OgRole as "is_admin"

3 participants