Problem/Motivation

The Groups module only works on content entities and not config entities. Webforms are config entities while webform nodes are content entities. Individual groups need a mechanism to control group role access to a group's webform (content) nodes.

Proposed resolution

Add Group roles to the Webform's Access tab (/admin/structure/webform/manage/{webform}/access) and the Webform Element Access group (/admin/structure/webform/manage/{webform}/element/{element_key}/edit). When a group's webform node is loaded we will check the current user's group roles against the current webform's operation's assigned group roles.

Remaining tasks

  • Create webform_demo_group.module to set up demo groups, roles, nodes, webforms, and submissions.
  • Create dedicate webform_group.module
  • Update webform.entity.webform.schema to support 'access.group_roles'. @see hook_config_schema_info_alter()
  • Create webform_groups access control element
  • Refactor and update Webform Access tab (/admin/structure/webform/manage/contact/access) @see \Drupal\webform\EntitySettings\WebformEntitySettingsAccessForm
  • Refactor and update Element access checker to support group roles.
  • Add hook support to webform_query_webform_submission_access_alter() via HOOK_webform_query_webform_submission_access_alter();

Notes

Webform Group Role Permissions

  • Create submissions
  • View any submissions
  • Update any submissions
  • Delete any submissions
  • Purge any submissions
  • View own submissions
  • Update own submissions
  • Delete own submissions
  • Administer submissions

Note: Access webform configuration permission is not applicable to group roles.

User interface changes

New group roles access element

API changes

New hooks.

Data model changes

N/A

Release notes snippet

TBD

User Acceptance Testing

Setup

  • Enable the Webform Demo Group module -/admin/modules
  • Confirm Webform Group module is marked as experimental /admin/reports/status

Form Builder

  • Create webform -/admin/structure/webform/add
  • Assign and remove Group Roles via the Access tab - /admin/structure/webform/manage/{webform}/access
  • Confirm warning message below group roles is displayed when Anonymous or Authenticated user roles are checked -/admin/structure/webform/manage/{webform}/access
  • Assign Group Roles via the Element edit tab. -/admin/structure/webform/manage/{webform}/element/{element_key}/edit

Email Handler and Token support

  • Confirm the email handler include Group token options - /admin/structure/webform/manage/{webform}/handlers/add/email

Member

  • Login as a A:1 member -/user/login (username: webform_group_a_1_member / password: webform_group_a_1_member)
  • Confirm A:1 member can access A:1 contact form -/webform/group/a/1/contact
  • Confirm A:1 member can NOT access A:2 contact form with an access denied message. - /webform/group/a/2/contact
  • Confirm that no reviewer, manager, or administrator elements are accessible -/webform/group/a/2/contact

Reviewer

  • Login as a A:1 reviewer -/user/login (username: webform_group_a_1_reviewer / password: webform_group_a_1_reviewer)
  • Confirm A:1 manager can review (view) A:1 contact form submission - /webform/group/a/1/contact
  • Confirm that reviewer element is accessible - /webform/group/a/2/contact

Manager

  • Login as a A:1 manager -/user/login (username: webform_group_a_1_manager / password: webform_group_a_1_manager)
  • Confirm A:1 manager can manage (view, update, and delete) A:1 contact form submission - /webform/group/a/1/contact
  • Confirm that manager element is accessible - /webform/group/a/2/contact

Administrator

  • Login as a A:1 administrator - /user/login (username: webform_group_a_1_administrator / password: webform_group_a_1_administrator)
  • Confirm A:1 administrator can administer A:1 contact form -/webform/group/a/1/contact
  • Confirm that administrator see all elements. -/webform/group/a/2/contact

Comments

jrockowitz created an issue. See original summary.

jrockowitz’s picture

Title: Add Group support webform and element access controls » Add Group support to Webform access controls
knopf21’s picture

Additionally it would be very helpful, if it were possible to add the group roles also to each single field.
At the moment there is only the possibility to add users and/or drupal roles.
It would be much easier for us to implement simple workflows in our organization.

  • 4e1380b committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls
    

  • 443ad4d committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls
    

  • 36cf299 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls
    

  • 0d58375 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Improve...

  • 6491b01 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Fix group...
  • 97c85b4 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Improve...

  • c0a04c1 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add...

  • f3f924a committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add...
jrockowitz’s picture

Issue summary: View changes

  • 704b3e9 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Tweaks
    

  • f542e34 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Restore...

  • 55e7424 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Token...

  • a46c04c committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add group...

  • 88a9b0d committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Code...

  • d6694c7 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Code...

  • e64eef9 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Setup base...

  • 2419e9f committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add group...

  • 1b15371 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add access...

  • 4d1486d committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add...

  • e7e21a4 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add...

  • d464e5a committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add...

  • e1ef3de committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add group...

  • 43397e4 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add...
jrockowitz’s picture

Issue summary: View changes
jrockowitz’s picture

Issue summary: View changes

  • 7c11aef committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Minor...

  • 481d5e6 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Add...

  • 24331ca committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Tweak demo...

  • e5c5e41 committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Fix token...

  • ce9d79d committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Fix token...

  • f499f5c committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Fix token...
jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new154.5 KB

  • b04135d committed on 3089026-webform-group
    Issue #3089026: Add Group support to Webform access controls. Fix token...
jrockowitz’s picture

StatusFileSize
new154.79 KB

  • 9cae297 committed on 3089026-webform-group
    Issue #3089026 by jrockowitz: Add Group support to Webform access...
jrockowitz’s picture

StatusFileSize
new154.75 KB
jrockowitz’s picture

This ticket is ready for review. You can also read this blog post to get a better understanding of the changes.

danchadwick’s picture

StatusFileSize
new31.62 KB

Working on merging this with the current dev branch and then the element access issue. Step one. Re-roll for current 8.x-5.x to resolve conflict in webform.api.php.

danchadwick’s picture

StatusFileSize
new165.36 KB

Trying again, this time bypassing a SourceTree bug when making working copy patches. Grrr.

Also, I corrected an incorrect docblock comment in hook_webform_element_access in webform.api.php. The $account argument is simply the account whose access should be checked. Patch 43 has some weird text about a format, suggesting that maybe the docblock was copied from some unrelated function.

Testing the reroll before proceeding further....

danchadwick’s picture

Status: Needs review » Active
StatusFileSize
new247.55 KB

This patch is element access #39 (element-access-3092634-39.patch + this issue's #46 (groups-3089026-46.patch), merged.

One additional change: I changed the hook_webform_element_access signature again to remove the = [] initializer for $context The context should always be provided with webform and webform_submission array entries; it is not optional.

If this patch passes tests, the I suggest we comment the element access patch individually and create another patch with just webform group.

danchadwick’s picture

StatusFileSize
new193.37 KB
danchadwick’s picture

Status: Active » Needs work
StatusFileSize
new192.37 KB

Other than a .rej file that snuck into #48, I'm at a loss as to why tests are failing. I have compared #49 to #46 (which passed) and the only difference I see are correctly attributable to the element access patch with this comment's patch includes.

jrockowitz’s picture

For anyone reviewing this ticket, the patch from #43 can be reviewed. @DanChadwick and I are just trying to improve the element access API but the UX still needs to be reviewed.

danchadwick’s picture

@jrockowitz - #46 is a re-roll of #43 that applies to the current 8.x-5.x. Probably want to review that one since #43 won't apply at this point.

brt’s picture

@jrockowitz Thanks for another great module.

Testing #46 against v 5.5:
1) The patch applies without problems using composer
2) The new webform_group can be activated using drush
3) On the access tab of a webform the group roles can be selected in the widget
4) Access to webforms on nodes linked to groups behave as expected
5) Access to submissions does correctly depend on the the selected group roles - FANTASTIC!!!

I've not yet tested element access

brt’s picture

For me, managing element access via group roles seems to be working fine with #46.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new154.07 KB

The attached patch must be applied to the latest dev release only.

jrockowitz’s picture

StatusFileSize
new153.87 KB
jrockowitz’s picture

WOOT! @DanChadwick and @brt This patch is ready for review.

danchadwick’s picture

I'm not using groups, but looking at webform_group_webform_element_access() as it relates to element access and the previous implementation in #46, that part looks good. Thanks for your work on this.

brt’s picture

Status: Needs review » Needs work

Thanks @jrockowitz we'll do some more detail testing with the new patch.

akerbel.dev’s picture

I have tested hook_webform_submission_query_access_alter(). Looks like it doesn't trigger on WebformSubmissionListBuilder page. Regarding its name, it should.

function MY_MODULE_webform_submission_query_access_alter(\Drupal\Core\Database\Query\AlterableInterface $query, array $webform_submission_tables) {
  dpm('test');
}
jrockowitz’s picture

You are right MY_MODULE_webform_submission_query_access_alter is only triggered for Views related queries.

brt’s picture

Status: Needs work » Reviewed & tested by the community

  • jrockowitz authored 0a7fd03 on 8.x-5.x
    Issue #3089026 by jrockowitz, DanChadwick: Add Group support to Webform...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • e15d9eb committed on 8.x-5.x
    Revert "Issue #3089026 by jrockowitz, DanChadwick: Add Group support to...
jrockowitz’s picture

Status: Fixed » Needs review
StatusFileSize
new153.87 KB

Merging group support may have broken the automated tests. Attached is the patch that was committed.

  • jrockowitz authored ded6f85 on 8.x-5.x
    Issue #3089026 by jrockowitz, DanChadwick: Add Group support to Webform...

  • f20f275 committed on 8.x-5.x
    Revert "Issue #3089026 by jrockowitz, DanChadwick: Add Group support to...
jrockowitz’s picture

StatusFileSize
new153.98 KB
jrockowitz’s picture

Status: Needs review » Fixed

  • jrockowitz authored 0e97b1b on 8.x-5.x
    Issue #3089026 by jrockowitz, DanChadwick: Add Group support to Webform...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.