Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Respectcan_read_model in DjangoModelPermissions#6325

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

paultiplady
Copy link

Django version 2.1 introduced thecan_read_model permission
to support read-only ModelAdmin views. Add support for this
permission to a DjangoModelPermissions subclass.

(A subclass is created in order to preserve
backwards-compatibility with versions of Django that don't
support this flag).

FIXES:#6324

TODO: design, tests.

johnthagen and igonro reacted with thumbs up emoji
@paultiplady
Copy link
Author

Two design options:

  1. Break backwards compatibility by updating theDjangoModelPermissionsGET check to require the new permission. This has the advantage of being more secure by default, but the major disadvantage of breaking backwards compatibility.
  2. Create a new subclass with the stricter permissions check. Advantage is it maintains compatibility, disadvantage is more auth classes to document/test/maintain.

As a user that expected the default behaviour to be to not grant read access to all users, I prefer 1, but I'm not sure how painful you consider a back-incompatible change to be.

@tomchristie
Copy link
Member

I'd suggest (1) but only merging it with the next major version change.

@paultipladypaultipladyforce-pushed thedjango-permissions-read-only branch 3 times, most recently from8bd001d toe879e8cCompareNovember 19, 2018 17:00
Django version 2.1 introduced the `can_read_model` permissionto support read-only ModelAdmin views. Add support for thispermission to a DjangoModelPermissions subclass.(A subclass is created in order to preservebackwards-compatibility with versions of Django that don'tsupport this flag).
@paultipladypaultipladyforce-pushed thedjango-permissions-read-only branch frome879e8c tob085754CompareNovember 19, 2018 17:02
@paultiplady
Copy link
Author

Sounds good. I've updated the code with this approach. The tests are currently failing because this permission doesn't exist on older versions by default; wonder what the approach should be for testing this? Is there precedent elsewhere that I could compare/copy?

Might be able to do something like adding the view permission only in the new has_view_permission test, and skipping these tests if version < nextversion?

@rpkilby
Copy link
Member

We plan on dropping Django 1.11 in April when the 2.2 LTS release is cut. This also coincides with the EOL for Django 2.0, meaning that the version differences won't matter since 2.1 will be the minimum supported version.

Basically, this PR will need to hang around until we're ready to prepare the next major DRF release.

Copy link
Member

@rpkilbyrpkilby left a comment

Choose a reason for hiding this comment

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

This will also need updated docs.

Copy link
Member

@rpkilbyrpkilby left a comment

Choose a reason for hiding this comment

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

Blocked until we drop Django 1.11 & 2.0 in ~April.

@paultiplady
Copy link
Author

Ah gotcha, that makes sense. Will hang tight on this changeset then.

@gregschmit
Copy link
Contributor

This is a welcome change.

@carltongibsoncarltongibson added this to the3.10 Release milestoneDec 19, 2018
@rpkilby
Copy link
Member

Moving this to 3.11, since we're not dropping Django 1.11 support until at least December.

@idoash4
Copy link

idoash4 commentedDec 31, 2019
edited
Loading

I am using this change in my project(by overriding DjangoObjectPermissions and setting the .perms_map property).
It is working as intended when listing objects using ModelViewSet. However when trying to retrieve a single item from the same view I am getting "detail": "Not found." error. This doesn't happen when the user making the request is a superuser. Adding all permission to the non-superuser testing user hasn't solved this as well.
@paultiplady have you tested this case?
I have spent a few hours on it and can't find anything wrong with my environment.

ManishShah120 reacted with thumbs up emoji

@marcosox
Copy link

Hello, any update on the status of this feature?

namoshizun reacted with thumbs up emoji

@namoshizun
Copy link

Hoping to see progress on this MR... I am already using it in my code but still would be nice to see it goes into the DRF codebase.

@@ -151,7 +151,7 @@ class DjangoModelPermissions(BasePermission):
# Override this if you need to also provide 'view' permissions,
# or if you want to provide custom permission codes.
perms_map = {
'GET': [],
'GET': ['%(app_label)s.view_%(model_name)s'],
'OPTIONS': [],
'HEAD': [],

Choose a reason for hiding this comment

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

I think theview_* permission check should be applied toHEAD requests as well.

Sure, the body isn't returned but having access tocontent-length could leak information about the page. Also, havingGET andHEAD return different status codes seems weird to me.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. We'd want the same permission onHEAD requests, yup.

Also the "Override this if you need to also provide 'view' permissions" part of the comment can be dropped.

@nemesifier
Copy link
Contributor

Hey there, can anyone give an update on what is missing from this PR so that some of us who are using DRF in@openwisp may help out in case it's doable for us? We will implement our own solution for this anyway so maybe it's worth to help here instead.

@tomchristie
Copy link
Member

@nemesisdesign Have added a comment above on a small tweak that'd be needed. Happy to take that either on this PR, on against a new one.

@nemesifier
Copy link
Contributor

@nemesisdesign Have added a comment above on a small tweak that'd be needed. Happy to take that either on this PR, on against a new one.

Cool, what about the OPTIONS method?

@namoshizun
Copy link

It is indeed a very useful addition.... hope it gets merged into the next release. We have been using this implementation for a long while, but it feels awkward each time when I have to explain why DRF doesn't include this solution..

Copy link
Contributor

@nemesifiernemesifier left a comment

Choose a reason for hiding this comment

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

I guess that if a user has the change permissions but not the view permissions, they should still be able to view, for backward compatibility reasons, since it's not guaranteed that old apps have view permissions created and assigned to users.

ManishShah120, namoshizun, and marcosox reacted with thumbs up emoji
@ManishShah120
Copy link
Contributor

I am using this change in my project(by overriding DjangoObjectPermissions and setting the .perms_map property).
It is working as intended when listing objects using ModelViewSet. However when trying to retrieve a single item from the same view I am getting "detail": "Not found." error. This doesn't happen when the user making the request is a superuser. Adding all permission to the non-superuser testing user hasn't solved this as well.
@paultiplady have you tested this case?
I have spent a few hours on it and can't find anything wrong with my environment.

Hi, @BlackXnt Yes there's an issue with this PR, I have opened#8009 to deal with this case, you can do a similar thing and see if it resolves your problem. 👍

nemesifier reacted with thumbs up emoji

@nemesifier
Copy link
Contributor

#8009 is based on work we're doing in OpenWISP:openwisp/openwisp-users#251. Would be great to see this handled directly in DRF. Let us know if it needs improvement. We'll put effort in helping out on this (me,@ManishShah120 and@atb00ker).

atb00ker reacted with thumbs up emoji

@tomchristietomchristie modified the milestones:3.13 Release,3.14Jan 10, 2022
@stale
Copy link

stalebot commentedApr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stalestalebot added the stale labelApr 16, 2022
@auvipyauvipy removed the stale labelJan 12, 2023
Copy link
Member

@auvipyauvipy left a comment

Choose a reason for hiding this comment

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

closing in favor of#6325

@auvipyauvipy removed this from the3.15 milestoneJan 12, 2023
@auvipyauvipy closed thisJan 12, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@emmceemooreemmceemooreemmceemoore left review comments

@tomchristietomchristietomchristie left review comments

@nemesifiernemesifiernemesifier left review comments

@rpkilbyrpkilbyrpkilby requested changes

@auvipyauvipyauvipy requested changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

DjangoModelPermissions does not respect Djangocan_read_model permissoin
12 participants
@paultiplady@tomchristie@rpkilby@gregschmit@idoash4@marcosox@namoshizun@nemesifier@ManishShah120@emmceemoore@auvipy@carltongibson

[8]ページ先頭

©2009-2025 Movatter.jp