Problem/Motivation

As a survey author, I want to create fields that require a higher level of permission to view, so I can have a better control on how results are rendered.

For example, say I have a calculated field based off of a user response that we populate via hook_form_alter(). I don't want the user to see the results and I may not want other users who have access to tables results to see the data.

Proposed resolution

New property for field, "hide results"

Remaining tasks

User interface changes

Field would be added to edit field.
Remove any field that was true for "hide results" from table result configure dropdown and view results page.

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robpowell created an issue. See original summary.

jrockowitz’s picture

Maybe we just need to get the results table to respect the element's access controls.

You could use the Webform Views module to build a custom results table,

robpowell’s picture

Maybe we just need to get the results table to respect the element's access controls.

That would be great. Is there a ticket you can refer to me to see how to call that access method? Or if you point me in the right direction in the code to start wrapping my head around it.

Thanks

jrockowitz’s picture

I guess this is the ticket to "Add field access control the submission entity list builder"

  • jrockowitz committed ecd9944 on 2848223-hide-element
    Issue #2848223 by jrockowitz: Admin only fields hidden on view...

  • jrockowitz committed 5656e2c on 2848223-hide-element
    Issue #2848223 by jrockowitz: Admin only fields hidden on view...

  • jrockowitz committed 30c3063 on 2848223-hide-element
    Issue #2848223: Admin only fields hidden on view submission data
    
jrockowitz’s picture

Status: Active » Needs review
FileSize
12.62 KB

Status: Needs review » Needs work

The last submitted patch, 8: admin_only_fields-2848223-8.patch, failed testing.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
12.67 KB

Status: Needs review » Needs work

The last submitted patch, 10: admin_only_fields-2848223-10.patch, failed testing.

  • jrockowitz committed 9b9f91d on 2848223-hide-element
    Issue #2848223: Admin only fields hidden on view submission data.
    
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
16.06 KB

  • jrockowitz committed 823ea4d on 2848223-hide-element
    Issue #2848223: Admin only fields hidden on view submission data.
    

  • jrockowitz committed 5180d7e on 2848223-hide-element
    Issue #2848223: Admin only fields hidden on view submission data.
    
robpowell’s picture

FileSize
95.38 KB
54.61 KB

I reviewed your changes yet I am not sure how to implement this to do what I want.

I am trying to achieve this,

As a survey author, I want to create fields that require a higher level of permission to view, so I can have a better control on how results are rendered.

So thinking about this, I want users to have access to view/edit submissions but some fields should require a higher level access. This means that on the following pages and features, users without this escalated permission would not be able to interact with the fields:

  1. All submission pages (submission/submission_id/*)
  2. Results table (results/table)
    1. including customizations button to select hiding and showing fields/columns
  3. csv exports

So I have played around with the different level access permissions and field access. This was done while testing example masking fields. First, I created a test user with no roles. For the field zip_code, I granted them view access. However, since they do not have the webform permission to view results this gives you a 403 forbidden. Now, if you add the user to a role with view access, that role is assigned view access to all fields. This checkbox is also disabled so you cannot remove view access per field for a given role. Finally, I tried making the zip_code field "private" via the checkbox under Administration. However, the helptext doesn't really explain what it basis this permission off of

Private elements are shown only to users with results access.

There are no field result access nor explicit result role permissions. Possibly, it means it will show it to user with edit access, but my role does not have that permission and the test user can still see the zip_code field on the submission page.

Here are the settings on the field:
zip code field properties

Here is the display of the results:
results of the field masking example

jrockowitz’s picture

@robpowell All I am trying to do in the patch is fix element access controls when viewing a submission in the Results Table and exporting the submission data.

The private property is somewhat deprecated because you can achieve similar functionality using element access controls.

I am very doubtful that I can immediately address your use case but I think you can use the Webform Views module to build a completely custom results and details view.

The attached view illustrates the concept using the default Contact form.

/admin/structure/webform/manage/contact/results/view

/admin/structure/webform/manage/contact/results/view/{SID}

The key secret to the above detail view display is I am using the serial number/sid as a Contextual Filter.

jrockowitz’s picture

@robpowell When we get this working you are going to owe me a recipe.

robpowell’s picture

All I am trying to do in the patch is fix element access controls when viewing a submission in the Results Table and exporting the submission data.

That sounds great.

I am very doubtful that I can immediately address your use case but I think you can use the Webform Views module to build a completely custom results and details view.

Yea that's fine I just wanted to give enough detail to understand the request and to help troubleshoot if anything didn't behave as expected. The one issue I have with with Webform Views is I can't display the machine name of the field. I put this issue in earlier this week #2851017: use machine_name instead of human field name for column/fields. Basically, my questions are too long to be used as column headers so I would prefer the shorter machine names.

When we get this working you are going to owe me a recipe

consider it done.

Thanks for pushing through this.

  • jrockowitz committed e6184b1 on 2848223-hide-element
    Issue #2848223 by jrockowitz, robpowell: Admin only fields hidden on...

  • jrockowitz committed 5d79d2d on 2848223-hide-element
    Issue #2848223 by jrockowitz, robpowell: Admin only fields hidden on...
jrockowitz’s picture

  • jrockowitz committed fea00cb on 8.x-5.x
    Issue #2848223 by jrockowitz, robpowell: Admin only fields hidden on...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the attached patch which just makes sure that element access rules are respected by 'Results' table, 'Customize' columns, and the Download columns.

@Robpowell I think your specific requirements maybe better addressed using a custom Webform Submission View which should be handled in a new ticket.

robpowell’s picture

access rules are respected by 'Results' table, 'Customize' columns, and the Download columns.

Cool. So how do I go about testing? Any user with view access permission will have defaulted view access to all fields, similar to my test condition in #16.

I think your specific requirements may be better addressed using a custom Webform Submission View

That seems right. I think the only request not solved by your above solution is removing the fields from all submission pages (submission/submission_id/*). Any reason reason why we shouldn't? In general, I think my confusion about field access is because my requirements need more granular control of permissions. Similar to setting a block, where you have the the option of making an inclusive list (white list) or excluded (blacklist) access.

jrockowitz’s picture

If you set an element's view access, it will be hidden from the Results, Customize, and Download pages based on which roles or users have access.

Status: Fixed » Closed (fixed)

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