Skip to content
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

Enable 2FA for Django Admin #166

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

jesusalderetein
Copy link
Contributor

Closes #165

@leocarreras
Copy link
Collaborator

Que tal Jesus, me esta dando este error al agregar un usuario, con este PR

Environment:


Request Method: POST
Request URL: http://localhost:8000/admin/auth/user/add/

Django Version: 2.2.12
Python Version: 3.7.5
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.humanize',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'leaflet',
 'django.contrib.gis',
 'core',
 'org',
 'widget_tweaks',
 'rest_framework',
 'rest_framework_gis',
 'django_filters']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/admin/options.py" in wrapper
  606.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/auth/admin.py" in add_view
  99.             return self._add_view(request, form_url, extra_context)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/auth/admin.py" in _add_view
  126.         return super().add_view(request, form_url, extra_context)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/admin/options.py" in add_view
  1645.         return self.changeform_view(request, None, form_url, extra_context)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/admin/options.py" in changeform_view
  1529.             return self._changeform_view(request, object_id, form_url, extra_context)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/admin/options.py" in _changeform_view
  1572.                 self.save_model(request, new_object, form, not add)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/admin/options.py" in save_model
  1088.         obj.save()

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/contrib/auth/base_user.py" in save
  66.         super().save(*args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/db/models/base.py" in save
  741.                        force_update=force_update, update_fields=update_fields)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/db/models/base.py" in save_base
  790.                 update_fields=update_fields, raw=raw, using=using,

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/dispatch/dispatcher.py" in send
  175.             for receiver in self._live_receivers(sender)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/dispatch/dispatcher.py" in <listcomp>
  175.             for receiver in self._live_receivers(sender)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/org/models.py" in create_user_profile
  142.         Profile.objects.create(user=instance)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/home/lcarreras/Documents/repos/ayudapy/ayudapy/env/lib/python3.7/site-packages/django/db/models/query.py" in create
  422.         obj.save(force_insert=True, using=self.db)

Exception Type: TypeError at /admin/auth/user/add/
Exception Value: save() got an unexpected keyword argument 'force_insert'

@jesusalderetein
Copy link
Contributor Author

jesusalderetein commented Apr 13, 2020

@leocarreras gracias por el feedback, ese error se encuentra presente sin los cambios incluidos en esta PR, ahora pude comprobar desde la rama dev y con una base de datos limpia.

image

Veo para corregir esto en esta misma PR. Gracias.

@leocarreras
Copy link
Collaborator

Te queda una tarea extra, gracias por eso también!

@jesusalderetein
Copy link
Contributor Author

@leocarreras, @pablo, @melizeche este cambio no afecta a la creación de usuarios, sí al acceso a la administración. Así pues, recomiendo tratar con sumo cuidado el fix para la creación de usuarios mencionado en el issue #184, ya que tanto usuarios administradores como usuarios finales están en una misma tabla.

Posibles soluciones:

  1. Crear un nuevo ticket para separar usuarios en diferentes tablas users y admin_users
  2. Asignar valores por default de location para usuarios administradores y mantener la estructura de base de datos actual. Adicionalmente corregir el método overwritten save pasando los parámetros requeridos según el mensaje de error unexpected keyword...force_insert...
  3. Hacer merge de estos cambios para habilitar 2FA para el acceso a /admin y tratar los bugs por separado.

Atento a tus comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable 2FA for Django Admin
2 participants