Problem/Motivation
To add support for revisions on Groups is needed first to implement this.
Proposed resolution
Add the "Published" field on groups in the same way as nodes and with the permissions to controls access based on that status.
User interface changes
New "Published" field will appear on groups and will be configurable from "Form display options"
Data model changes
New column on groups called "status".
Original issue by @sandeepguntaka
Adding a status to the group entity will be a good addition as making a group inaccessible by unpublishing will help.
Comments
Comment #2
sandeepguntaka commentedComment #3
sandeepguntaka commentedChanging the status
Comment #5
jidrone commentedI did a completely new patch, because the previous one was not following the right approach and did not pass the test.
I started to work on this because it is needed for #2829966: Support for Revisions on groups.
Comment #6
amateescu commentedThe patch looks good to me overall, but I didn't look in depth at the access control handler changes so I'll leave the final review/RTBC for a maintainer of the module.
Comment #7
berdirLooks pretty OK to me as well, I am wondering what exactly the meaning of the published flag for groups means for their related content.
We did implement our own status in our own project, where the group status does not affect really affect itself (they are all internal anyway) but actually makes the nodes of the group accessible or not.
I guess it is fine to limit to just to the group itself for now, but I assume it might cause some confusion/misunderstanding of how this works.
Comment #8
jidrone commentedHi @amateescu and @Berdir,
Added an access test.
Regarding the related content access I think the best way is first add support to make groups publish/unpublish and then maybe we can add a feature to limit group content access based on that.
Can you please help me reviewing the other child issues of #2829966: Support for Revisions on groups.
Comment #9
jidrone commentedI based the access test on Taxonomy test and I needed to change some comments I forgot in previous patch.
Comment #10
lobsterr commentedIt looks very good, I have tested all presented cases and couldn't find any issues
Comment #11
kingdutchIt would be great if this got into the Group module. We're looking to apply this patch to the Open Social distribution because we have a real need for it (in courses using the social_course module but also because some users want to be able to "stage" groups before sharing them with the platform).
We have a PR open here https://github.com/goalgorilla/open_social/pull/1319 to start using this code already, so we can remove some of our custom solutions (that replicate a large part of this but aren't able to alter the Group entity's interface).
Comment #12
scotwith1tJust wanted to chime in and say we're heavily depending on this patch to satisfy the need to "stage" groups as well. We will likely be working on some additional support of Workflow transitions and the like as well to satisfy the client's editorial requirements for groups and group_content.
Comment #13
jwilson3Patch works pretty well, but note that you can still end up showing unpublished groups to end users if you have a view of groups. The easy workaround is to just ensure you filter out unpublished content in your view.
Comment #14
kristiaanvandeneyndePatch looks good, will try and get a proper review in next week and add it to RC4.
If the change is too drastic, it may need to wait for 8.1.0 as a feature update. But given how it's fully BC, we should be fine. What would ease my mind given the recent RC3 update fiasco and help me commit this faster is an update test proving nothing breaks during the update hook.
Comment #15
taylormade415 commenteda heads up that
group_update_8016in #9 is also declared by https://www.drupal.org/files/issues/2019-07-04/group-3061321-37.patch in https://www.drupal.org/project/group/issues/3061321#37Comment #16
attiks commentedRerolled patch against 8.x-1.x
Comment #17
attiks commentedMissed a use statement
Comment #18
brooke_heaton commentedHow would one published/unpublish a group programmatically? Can we use the same method as nodes?
$group->setPublished(FALSE);
$group->setPublished(TRUE);
Comment #19
lobsterr commented@brooke_heaton ther is EntityPublishedTrait used, it provides
and
methods to check and set status
Comment #20
brooke_heaton commentedPatch #17 appears to no longer apply clean. :(
Comment #21
lobsterr commented@brooke_heaton I've just applied the patch to the latest dev version everything is applied correctly. No issues. Can you try one more time on the clean version. Maybe you have additional patches ?
Comment #22
laura.gatesI think this patch has broken with 1.x-rc-5. Composer no longer wants to install it. Can this be rerolled? I'd like to avoid going to a dev branch of the module if at all possible.
Comment #23
gorkagr commentedHi!
I can say that patch #17 works with the 1.0.0-rc5 and adds the 'published' checkbox in all the groups you have created so far.
By disabling it, access to the group page is forbidden (default settings, havent played yet with the permissions).
Comment #24
jwilson3Patch no longer applies to latest 8.x-1.x:
Comment #25
jwilson3Comment #26
jwilson3Automated re-roll of #17 on latest 8.x-1.x .
I applied #17 cleanly to 8.x-1.0-rc5.
Then committed into a branch, then rebased the branch on 8.x-1.x there were two small conflicts which I resolved manually. Therefore an interdiff is not really necessary or practical.
Comment #27
jwilson3Fix syntax error introduced accidentally in #26 with the manual conflict resolution after rebase on latest 8.x-1.x branch.
Comment #28
jellyburger commentedI apply the patch successfully, but a following drush cr results with this error:
PHP Fatal error: Class Drupal\group\Entity\Group contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods (Drupal\Core\Entity\EntityPublishedInterface::isPublished, Drupal\Core\Entity\EntityPublishedInterface::setPublished,
Comment #29
devkinetic commentedComment #30
ridhimaabrol24 commentedPatch #27 failed to apply on the latest head.
Uploading the correct one!
Comment #31
marty2081 commentedPatch #30 failed to apply correctly, because group_update_8021 has been added in release 1.0.0. This is a reroll to change the update hook to group_update_8022.
Comment #32
brooke_heaton commentedNone of the above patches are applying for me against 1.x-dev@dev.
Comment #33
brooke_heaton commentedComment #34
brooke_heaton commentedThis issue is over three years old. This is embarrassingly sad. This module needs more than one maintainer.
Comment #35
edysmp#31 is working for me and Views integration is just working!
Thanks!
Comment #36
heddnIt was missing a status column on the group listing page.
Comment #37
lahode commentedThanks heddn
Last patch #36 works great! I made a few bunch of tests, everything looks fine with Group 8.x-1.3.
As brooke_heaton said, it would be great to include this feature in the next release
Comment #38
jwilson3Thanks for the continued efforts here.
Just a small heads up that this issue is part of a larger effort to add proper revision support to groups module. While not required, it would be super helpful to update the patch on the parent issue #2829966: Support for Revisions on groups with the changes here, since there are integrations (including tests) in that issue that interact with the code here to properly cover the feature set that integrates published/unpublished state with permissions to access revisions.
From comment #52 on the parent issue:
It doesn't make sense to set this one back to NW, so that the parent ticket can be fixed, so I'm going to do that on the parent ticket instead.
Comment #39
zcht commentedthanks a lot for this patch, works fine with group 1.3 and drupal 8.9.11. i'm still missing an authorization, but it would be important to tell who is allowed to set the status.
so we only have two possibilities:
* group member takes out the publish and can't access the group anymore
* only administrator can republish the unpublished group
therefore, another authorization would be important, for example, that only administrators can see the status checkbox at all, or even a certain group role.
then this patch would be really perfect and should be included in the group core :)
Comment #40
kristiaanvandeneyndeAs soon as you start checking per user, the result needs to be cached per user.
Given the access implications when someone unpublishes a group, I'd too consider gating the toggle behind a separate permission (publish group/unpublish group) so that you can still assign editors without having to worry that they might lock themselves out. Having said that, core currently also behaves in a way that someone might unpublish content they too can no longer see when unpublished. So I'd like to hear some opinions on that matter.
Comment #41
jaypanI think adding an extra granularity of permission (A "(un)publish group" permission) only adds benefit, and doesn't come with cons, so it seems like a good permission to add to me, regardless of whether core does it. On that note, separately from this issue it may be a nice patch for core as well.
Comment #42
jnicola commented@kristian: Reviewed your comment re:cacheing
GroupAccessControlHandler::checkAccess is what you have in there and consequently GroupAccessResult::allowedIfHasGroupPermission being called. allowedIfHasGroupPermission seems to inherently add cache context via: addCacheContexts(['user.group_permissions'].
I may be missing some context, but it would seem this would cache most any cached situation for a user? May not have my memory right on cache tags though.
Comment #43
kristiaanvandeneyndeView own implies it's per user. Which the code shows when you check the UID. In that case, you need to add the user cache context.
Comment #44
kristiaanvandeneyndeThe current patch does not implement query access at all, leading to a security issue. Attached proof of concept fixes that. Also got rid of the browser test and will add in kernel and/or unit tests instead.
Comment #46
kristiaanvandeneyndeSmall mistake re tracking memberships, let's try again.
Comment #47
kristiaanvandeneyndeTrying to get testbot to run near end of day is always a sure bet for typos.
Comment #49
kristiaanvandeneyndeThis fixes tests and adds query tests for unpublished users. Now direct access tests and perhaps expanding query access test with an admin permission test and an update/delete only test.
Comment #50
kristiaanvandeneyndeThis massively expands query tests, also for previous functionality to ensure everything both new and old is working as intended. The only thing remaining that needs testing is non-query access stuff; i.e.: direct access checks.
Comment #51
zcht commentedThank you Kristian for looking at this in detail. The #50 patch still works very well, both for groups and subgroups the checkbox is displayed (Drupal 9.1.8, Group 1.3, Subgroup 1.0.2) . However, I have not been able to discover a new access authorisation option anywhere. Or has this not yet been taken into in the patch?
It would be ideal if, for example, you could give a group role permission in a group type. Let's say we have two roles: manager and editor. The manager is allowed to unpublish and republish the group, the editor should not see the checkbox at all.
When thinking about this, the question naturally arises as to what happens to the associated group content. But this is certainly not the issue with this patch.
Comment #52
kristiaanvandeneyndeRe #51 I still have the new permission in the back of my head, but this patch is being sponsored for approval right now and therefore we need to keep the scope to the work at hand. A follow-up for the new permission(s) would be perfect, though.
Associated group content is indeed out of scope, I've asked the question in this very issue before and no-one seems to have a good answer (yet?) so I'm not sticking my neck out for that one until we come up with a proper plan :)
Comment #53
kristiaanvandeneyndeThis should be the final version: Kernel tests, Unit tests, regular access, query access, update hook similar to the ones core has in place, etc.
Comment #54
jaypanSeems to me that this should be a setting, either for all groups, or for each given group.
That said, I think it would be a nice feature to look at after this one. Thanks for your awesome work on this one!
Comment #56
kristiaanvandeneyndeFixed, thanks so much to Global Game Jam for sponsoring this work!
Comment #57
jaypanThanks to you kristiaanvandeneynde, and thanks to Global Game Jam!
Comment #59
pianomansam commentedSorry if I missed it, but I haven't found any conversation on the next release. This feature is essential for a site, so I'd love to see a release with this in it soon.