#20642 closed Cleanup/optimization (fixed)
Deprecate `Option.get_(add|change|delete)_permission`.
Reported by: | Simon Charette | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the whole Clean Model Options process we should deprecate those methods in favor of contrib.auth
alternatives.
Even if those methods are undocumented it's no secret they are used in the wild. Django exclusively use them in contrib.admin
:
(django)simon@simon-laptop:~/workspace/django$ grep -E "get_(add|change|delete)_permission" django/ -Rn --include="*.py" django/db/models/options.py:416: def get_add_permission(self): django/db/models/options.py:419: def get_change_permission(self): django/db/models/options.py:422: def get_delete_permission(self): django/contrib/admin/options.py:355: return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission()) django/contrib/admin/options.py:369: return request.user.has_perm(opts.app_label + '.' + opts.get_change_permission()) django/contrib/admin/options.py:383: return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission()) django/contrib/admin/options.py:1671: self.opts.app_label + '.' + self.opts.get_add_permission()) django/contrib/admin/options.py:1683: opts.app_label + '.' + opts.get_change_permission()) django/contrib/admin/options.py:1693: self.opts.app_label + '.' + self.opts.get_delete_permission()) django/contrib/admin/util.py:122: opts.get_delete_permission())
Attachments (2)
Change History (10)
comment:1 by , 12 years ago
Has patch: | set |
---|
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
+1 much needed cleanup.
Tested it on a project that uses permissions and ModelAdmin.has_x_permission
overrides extensively and didn't notice any issue.
I'd go either ways for documenting get_permission_codename
, the methods it replaces weren't documented, so people that used them know where to look.
by , 12 years ago
Attachment: | 0001-Fixed-20642-Deprecated-Option.get_-add-change-delete.patch added |
---|
Patch with doc
comment:3 by , 12 years ago
Updated the RFC patch to use super
in InlineAdmin
instead of duplicating permission codename creation.
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
by , 11 years ago
Attachment: | 20642-tests.diff added |
---|
Added a patch that deprecates option permission methods and moves
contrib.auth.management._get_permission_codename
tocontrib.auth.get_permission_codename
and use it incontrib.admin
.Wondering if we should document
get_permission_codename
, it feels a bit odd to deprecate those methods while specifying no alternatives in the release notes.I still pointed to it in the raised deprecation warning.