Closed (fixed)
Project:
Group
Version:
3.3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Apr 2020 at 11:55 UTC
Updated:
19 Mar 2024 at 14:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ginovski commentedComment #3
ginovski commentedComment #4
lobsterr commentedComment #5
ginovski commented1.A check for duplicate is missing, the role could already have been added before.
2.This method can be inserted in the test to check its functionality.
Comment #6
lobsterr commented@Ginovski I've added checks:
1) If a user has the role
2) if a role exists for the current group type
I will add tests later
Comment #7
kristiaanvandeneyndeThis looks great. Could you add a test perhaps? You have some safety checks in there and it would be nice for a test to confirm they work as expected. It can be as simple as a unit test with a few prophecy mocks.
Also:
This can save a few ms by not having to load the group type:
Thanks for working on this!
Comment #8
liquidcms commentedJust a somewhat related comment:
I guess most people want to run this code on a User entity? When i needed to make a view to be able to set/remove a role from members i created a Group content (membership) view; and then wrote a new VBO action to add as simply:
The entity in this case is "Group content" but not membership; even though i am filtering my group content on "group membership" content type. So even though i can see group_roles in my $entity values (and apparently set them); i never load the membership. There is also no need to check if already set. It is my only (real) role at the moment; so not sure how this works if i create a 2nd role. Maybe it doesn't and i could use these new methods in what would now require a somewhat convoluted approach:
Do I have this all correct? It does seem odd that i can set role by either modifying the group content entity or the membership entity.
Without your new remove method; not sure how to go about this as i am doing it now (against group content entities); possibly just set target_id = ''.
Comment #9
spokjeAddressed #7:
- Used
$this->groupContent->getGroup()->bundle()to save a few ms by not having to load the group type- Added some tests, couldn't think of a way to use a unit test, since I couldn't see any way to get this to work without using
getRoles(), so I used a KernelTest.- Updated some comments.
Comment #10
spokjeCoding Standard messages and 9.2 failure (looks like
expectExceptionMessageRegExp, which was already deprecated, has been removed from PHPUnit 9.5.8) are unrelated to this patch AFAICT.Comment #11
lobsterr commentedI agree, Unit tests are suitable in this case. I have tried to do it also, it didn't work for me.
I checked the tests everything looks ok. I have added some minor changes.
Just to improve code a bit.
I believe we can mark it as RTBTC
Comment #12
jordik commentedComment #13
jordik commentedIt would be awesome to also have a hasRole() method checking for a certain role. What do you think?
Comment #14
aporieRegarding the hasRole method I also needed something like that.
I've opened a child issue and will post the complete patch here.
Sorry, I'm not able to make an interdiff right now. I don't have patchutils installed and have an issue with my package manager.
Patch 11 + hasRole method in attachment.
Comment #15
aporieWell, maybe a patch not made in the rush would be better. Finally, got patchutils installed also, that helps.
Sorry for previous rushy patch.
Comment #16
sweetchuckChange back to "Needs work" because of the failing tests.
I think the roles added into the array in a reverse order.
Comment #17
sweetchuckWith the current solution every ::addRole() and ::removeRole() triggers an individual ::groupContent->save().
I think the following methods would be useful.
Comment #18
kristiaanvandeneyndeWill try to add this to next minor release.
Comment #19
jdleonardThe patches are not yet relevant to Group 3.x.
I found that I had to do the following to programmatically add a group role for a user with an existing membership:
Comment #20
jordik commentedRe-rolling the patch to 2.2.x-dev, using the proper groupRelationship instead of groupContent and omitting the changes to ChainGroupPermissionCalculatorTest.php.
Comment #21
jordik commentedComment #22
kristiaanvandeneyndeComment #24
kristiaanvandeneyndeThis needs test coverage for the new methods and I'm not sure if we can simply get away with calling the shared bundle class from the old wrapper like that. For new methods it would make sense, as there is nothing to keep BC for.
Comment #25
kristiaanvandeneyndeHiding patches in favor of MR
Comment #26
kristiaanvandeneyndeOkay, this looks ready to me now. Will add a follow-up for moving the role checking logic in a preSave() hook.
Comment #27
kristiaanvandeneyndeChange record here: https://www.drupal.org/node/3425776
Follow-up here: #3425781: Unify preSave and postSave logic for memberships.
Comment #29
kristiaanvandeneynde