Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Read Only Fields Based on User Group #1389

Open
wants to merge 6 commits into
base: next
Choose a base branch
from

Conversation

jnterry
Copy link

@jnterry jnterry commented Jan 9, 2021

Summary of Changes

  • Add acl_ro (access control list read only) parameter to fields within a collection
  • Displays accessible read-only fields in entries table and entry editor
  • Prevents interaction with read only fields by applying uk-disabled css class
  • Add server side validation on collection/save_entry endpoint to ensure user cannot edit fields they do not have access to by manipulating the JSON payload sent to server

Motivation

Currently, the per field acl in a collection can be used to hide fields from certain groups of users. For our use case of cockpit, we would like to mark some basic fields about an entry (such as name, slug, etc) as only editable by admins, but allow volenteers to contribute to content within other fields of an entry.

Marking the "basic" fields as only accessible to admins completely hides them from the UI, meaning volenteers cannot see which entry they are editing.

This PR adds seperate access control lists for read/write (the current ACL) and read only - allowing users to see, but not modify fields marked as read only.

Implementation

Split ACL

The per-field access control list is now split into two parts:

access-control-lists

The read write list is stored with the acl parameter as before, ensuring backwards compatbility with existing cockpit deployments. The new readonly list is stored in a acl_ro parameter

Entries Table

Entries table now displays columns for any field the user can see based on the union of acl and acl_ro.

The "bulk edit" interface on the entires table uses only the acl list to avoid allowing bulk edits of fields which the user can only see in a read-only capacity.

(this would be a good use case for the upcoming HTML "inert" attribute - but since it is not yet supported by any browser (without enabling experimental support), I've used custom javascript. An alternative would be to add the "inert" polyfill to cockpit and use that attribute for a more robust solution.

Entry Editor

The disabled option is passed into the cp-field for readonly fields to render them partially translucent and prevent cursor interaction.

I have also added code to prevent a user gaining focus into a disabled cp-field by pressing tab on the keyboard to move between inputs.

Server Side Validation

The existing ACL is not validated server side, meaning a user can reply a http request to collection/save_entry, modifying the JSON payload to overwrite a field they do not have access to.

This PR additionally adds server side validation to the Collection's Admin controller to use the old value for any read only fields.

@jnterry
Copy link
Author

jnterry commented Jan 9, 2021

While this PR was developed for my own use of cockpit, looking at open issues, it may help as a base towards solving:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant