#30334: extra option for InlineModelAdmin instances should be "0" if user is
lacking "add" permission
-----------------------------------------+------------------------
Reporter: direx | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
When a staff user only has `view` permissions for a particular model
displayed through an `InlineModelAdmin`, then `extra` should always be
`0`. Otherwise input fields are displayed, even if the user does not have
`add` permissions.
Sample:
{{{
class AuthorInline(admin.TabularInline):
extra = 1
model = Author
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
inlines = [AuthorInline, ]
}}}
When a user who only has `view` permission for `Author` opens the
ChangeView of `BookAdmin`, an extra input field for `AuthorInline` is
displayed. However the input field should not be displayed, as the user is
lacking permissions.
Workaround:
{{{
class AuthorInline(admin.TabularInline):
extra = 1
model = Author
def get_extra(self, request, obj=None, **kwargs):
if self.has_add_permission(request, obj=None):
return super().get_extra(request, obj=None, **kwargs)
else:
return 0
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30334>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.9f98b0fce517ca01475bc3b28a6fa7c2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.