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
Pulp AdminModels for just about every pulp object #838
Conversation
|
WARNING!!! This PR is not attached to an issue. In most cases this is not advisable. Please see our PR docs for more information about how to attach this PR to an issue. |
|
I wrote this issue up, can you add If you can do all that I can test, review and merge. |
I'm not sure I understand the motivation for making the admin read-only. I'm assuming it will only be accessible to django 'admin' users (or whatever auth/authz mechanism is involved). Read only loses a lot of the utility of the tool. |
Django-admin bypasses the drf serializers. Pulp heavily relies on those serializes for data correctness. I agree it's not as useful, but it's also not safe and so it's a no go for us to merge anything that isn't read-only for the model data itself. |
|
Note: Currently the 'PulpModelAdmin' base class sets But that also means all subclasses have some fields / read_only_fields defined, so the "edit view" pages are usually not often. Alternatively, PulpModelAdmin could provide a clever get_fields() and get_readonly_fields() to let the subclasses still autopopulate. (and arguably, the PulpModelAdmin base class is unnecessary at the moment, but I'd leave it as is (even empty) just as an abstraction point and since likely there will shared methods for PulpModel derived classes needed in the future) |
Use pulpcore.admin.BaseModel for guardian obj perms Use pulpcore AdminModels from plugins package. Utility formatters for collection import for use in admin. Issue: #370 Required PR: pulp/pulpcore#838 Required PR: pulp/pulp_ansible#341
|
|
||
|
|
||
| class PulpModelAdmin(BaseModelAdmin): | ||
| pulp_readonly_fields = ("pulp_id", "pulp_created", "pulp_last_updated") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the PulpModelAdmin I think is a fine idea.
We need to take this further though, we can't merge it until all the fields are read-only is the current agreement within various folks in the pulp community.
I tried using django-read-only-admin and I don't recommend it, their code 500 errored for me so I think that option is out.
One option is to have PuplModelAdmin provide a metaclass that sets readonly_fields for all fields on the model. I think that would be pretty straightforward actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried putting together a metclass implementation and I hope to continue on it tomorrow. If we had that I think this PR would be pretty much good-to-go. Without that though, it isn't.
|
After a slack convo, my understanding is your use case really is to have a writeable version which we can't release in pulpcore due to it bypassing the DRF serializers. One option discussed is for galaxy_NG as a plugin to carry such a PR, so I think closing this here and reopening against galaxy_ng is the next step. |
That was my initial plan, but split the admin.py models to live in their traditional places (ie, pulpcore models in pulpcore/app/admin.py instead of in galaxy_ng/app/admin.py). Since django-admin is the easiest way to check and verify the guardian per class / per instance permissions I was under the impression that having django-admin for pulp objects was a requirement for pulpcore itself. |
Add BaseModelAdmin inherited from GuardedModelAdmin BaseModelAdmin add's object permission editing to evey model admin. Also add PulpModelAdmin for subclasses of the Pulp base Model. Add AdminModels for use in plugins to pulpcore.plugins.admin Mostly generated with django-extensions admin_generator closes #7336
|
re model validation and drf one option may be to use a custom MyDRFModelForm for the base ModelAdmin class. For the latter, that assumes there is an obvious path from django/drf Model to the DRF serializer that should https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#admin-custom-validation |
I will read through this more, but overall if we can get it working with DRF validation this would be hella great. |
|
@alikins Pulp at startup for all plugin builds a mapping of model names to corresponding Viewsets here and each viewset concretely declares its serializer. So while it's possible there are some gotchas.
If "raw database fixup" is a requirement then I think deploying an app on the platform that provides that feature set would be ideal. Otherwise I think sticking to the API usage is my recommendation. All data in pulp_ansible for example has endpoints for the models that back it, so I can't think of anything you'd want to fix via django-admin that you couldn't fix via the API. As an aside, we do want to use django-admin for the object-level RBAC, but that is data around the models not the model data itself. |
|
The DRF folks on IRC say that we should consider using this https://www.django-rest-framework.org/api-guide/renderers/#adminrenderer |
|
After more slack discussion my understanding is that the interest is to actually have it writeable and meanwhile we require it to be read-only. To summarize the two concerns about why writable django-admin is not safe for Pulp users:
Since what you'll get isn't actually what you need if galaxy_ng really needs this, here is what I recommend
For all these reasons I'm closing for now. |




Pulp AdminModels for just about every pulp object