webform_group module access check assumes that source node param is always present in the current request

Created on 13 February 2020, almost 5 years ago
Updated 25 November 2023, about 1 year ago

I'm using groups and on my form I have element that should be only visible to the members of this group. This all works if I access the form using node/%node path. Elements are shown according to the group roles I've set to them.

If I render the webform using views (in my case in a block, but I don't think it matters here) then group members do not see this group-only element I've created.

I think this selection should also apply to access.

I tried to workaround this by rendering the full content node in this view but this does not include the webform (that is visible on node node/%node).

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇮Finland mikran

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy maurizio.ganovelli Arezzo

    I have a similar problem in 2.x version too; i'm trying to give access to a specific group role to all submissions of a specific webform.
    In Drupal\webform_group\WebformGroupManager the function getCurrentGroupRelationship return always FALSE due to:
    $source_entity = $this->requestHandler->getCurrentSourceEntity(['webform_submission']);
    returning always a NULL value fot paths like "node/X/webform/results/submissions".
    I tried to extract node parameter from current route but without luck (i found no route name nor route parameters in request using \Drupal::routeMatch()).
    As a temporary quick & dirty fix (for nodes only) i use:

        $source_entity = $this->requestHandler->getCurrentSourceEntity(['webform_submission']);
        if (!$source_entity) {
          if (preg_match("/^(\/.*)?\/node\/([1-9][0-9]*)\/webform\/results\/(submissions|download)$/", \Drupal::service('path.current')->getPath(), $matches)) {
            $source_entity = $this->getEntityStorage('node')->load($matches[2]);
          }
          if (!$source_entity) {
            return $this->currentGroupRelationship;
          }
        }
    

    I'm sure that there is a better solution than raw url pattern matching .. any idea is welcome!

Production build 0.71.5 2024