django_mail_admin icon indicating copy to clipboard operation
django_mail_admin copied to clipboard

Support for read-only admin access

Open frnhr opened this issue 5 years ago • 0 comments

  • django mail admin version: 0.2.0
  • Django version: 3.0.4
  • Python version: 3.8.2
  • Operating System: McLinux Vista :p

Description

Users with only "view" permissions for "django_mail_admin" app trigger an error when accessing changeview for OutgoingEmail:

KeyError: 'from_email'

What I Did

  • Crated a staff user (non-superuser) and gave it all of the "view" permissions for "django_mail_admin" app, but no "change", "add" or "delete" permissions: Change_group___STEMI

  • Log in as this user and open http://localhost:8000/admin/django_mail_admin/outgoingemail/

  • Click on any object in the list.

  • 💥

Traceback:

Internal Server Error: /admin/django_mail_admin/outgoingemail/4/change/
Traceback (most recent call last):
  File ".../django/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File ".../django/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File ".../django/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File ".../django/django/contrib/admin/options.py", line 607, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File ".../django/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File ".../django/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File ".../django/django/contrib/admin/sites.py", line 231, in inner
    return view(request, *args, **kwargs)
  File ".../django/django/contrib/admin/options.py", line 1641, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File ".../django/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File ".../django/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File ".../django/django/contrib/admin/options.py", line 1522, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File ".../django/django/contrib/admin/options.py", line 1555, in _changeform_view
    ModelForm = self.get_form(request, obj, change=not add)
  File ".../django_mail_admin/admin.py", line 314, in get_form
    form.base_fields['from_email'].initial = configurations.first().email_host_user
KeyError: 'from_email'

frnhr avatar May 11 '20 19:05 frnhr