Skip to content

[fix:ux] Fixed rendering of JSON fields in readonly mode #848#1102

Open
pandafy wants to merge 3 commits into
masterfrom
issues/848-readonly-config-field
Open

[fix:ux] Fixed rendering of JSON fields in readonly mode #848#1102
pandafy wants to merge 3 commits into
masterfrom
issues/848-readonly-config-field

Conversation

@pandafy
Copy link
Copy Markdown
Member

@pandafy pandafy commented Jul 29, 2025

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Fixes #848

Screenshot

image

@pandafy pandafy moved this from To do (general) to In progress in OpenWISP Contributor's Board Jul 29, 2025
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 29, 2025

Coverage Status

coverage: 98.78% (+0.02%) from 98.758%
when pulling 27f544f on issues/848-readonly-config-field
into 6ae8103 on master.

@pandafy pandafy force-pushed the issues/848-readonly-config-field branch 2 times, most recently from 27f544f to 728ab65 Compare July 31, 2025 09:29
@pandafy pandafy force-pushed the issues/848-readonly-config-field branch from 728ab65 to c28442a Compare August 7, 2025 12:06
Copy link
Copy Markdown
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pandafy, this is the proper fix for #848. The ReadOnlyJsonFieldMixin approach, swapping JSON field widgets to a ReadOnlyJsonWidget (with disabled=True) for users who lack change permission, is the right way around Django's limitation that a single widget cannot serve both editable and read-only contexts. Handling both models.JSONField and jsonfield.JSONField, covering the inline path via get_formset, and including tests all make this a clean, mergeable change.

Note: there is a competing PR for the same issue (#1327) which is full of accidentally committed artifacts (a db.sqlite3, an anti_gravity.py script that disables GIS, etc.). This PR is the correct one; #1327 should be closed in its favor.

A couple of things to confirm before merge:

  1. Make sure this plays well with the advanced JSON editor: a view-only user should get the read-only rendering, and the change is scoped so it never downgrades the editable widget for users who do have change permission.
  2. Confirm coverage extends to all the JSON fields users actually see read-only (device config, context, DeviceGroup context, template config), so the fix is complete rather than only on one form.
  3. Docs box is unchecked; a short note is fine since this is mostly transparent.

Good work, this is close to ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

[fix:ux] Read only view for JSON/dict fields in admin is not user friendly

3 participants