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

JSONEditor not displayed when user doesn't have the permissions to edit the object #73

Open
haidaraM opened this issue Nov 22, 2023 · 3 comments

Comments

@haidaraM
Copy link

Hi,

First of all. Thanks for your work on this lib.

I disabled the change permission with this code in the model admin class:

    def has_change_permission(self, request, obj=None):
        return False

However, after doing that the JSONEditor is no longer displayed. Is this expected? My expectation was to see the JSONEditor in read only mode as well. It works if I put all fields in readonly_fields in the model admin class.

I compared the HTML file and noticed that this package static files (JS, CSS) are not included when the has_change_permission returns False.

Thanks in advance for your help

@nnseva
Copy link
Owner

nnseva commented Nov 25, 2023

As I could ensure, in both cases, for the readonly_fields attribute, as well as for the has_change_permissions method, the JSON field is not shown, and the JSON content is shown instead, like here:

image

It is a result of the Django code where a special class AdminReadonlyField is used when rendering readonly admin form fields. I didn't find any way to customize this behaviour yet. If you could implement such a feature, i.e. showing JSONEditor (and ACEEditor) in the readonly mode when the field is not editable for some reason (editable=False, has_change_permission, or readonly_fields) you are welcome to make a PR for this feature.

@haidaraM
Copy link
Author

Thanks for your reply. I will take a closer look at this then and raise a PR if I find a solution.

@nnseva
Copy link
Owner

nnseva commented Nov 26, 2023

You may try using diabled attribute somehow, as it was done by someone here:

#55

But notice that the field itself is yet really editable, and the POST will able to send a new value, till the field is not really readonly. For the full-featured solution the field itself should be read-only for one of the reasons listed before, but the widget should be rendered in the special readonly mode (disabled is an appropriate mode), instead of rendering content of the field, as the Admin Form does.

I suspect that if you will create ModelForm with readonly fields instead of using Admin Form provided by the admin application, you will get some appropriate result. The question is, how to provide this feature back to the Admin Form.

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

No branches or pull requests

2 participants