diff --git a/data_management/models.py b/data_management/models.py index 3b9b5205..d3dfcbec 100644 --- a/data_management/models.py +++ b/data_management/models.py @@ -4,7 +4,6 @@ from django.core.exceptions import ValidationError from django.db import models from django.urls import reverse -from dynamic_validator import ModelFieldRequiredMixin from django.contrib.auth import get_user_model from . import validators @@ -15,7 +14,7 @@ TEXT_FIELD_LENGTH = 1024**2 -class BaseModel(ModelFieldRequiredMixin, models.Model): +class BaseModel(models.Model): """ Base model for all objects in the database. Used to defined common fields and functionality. """ diff --git a/data_management/templatetags/auth_tags.py b/data_management/templatetags/auth_tags.py new file mode 100644 index 00000000..7d4d27e9 --- /dev/null +++ b/data_management/templatetags/auth_tags.py @@ -0,0 +1,12 @@ +from django import template +from django.conf import settings + +register = template.Library() + +@register.simple_tag +def is_auth_method(method): + _auth_method = settings.AUTH_METHOD + if _auth_method: + if _auth_method == method: + return True + return False \ No newline at end of file diff --git a/drams/base_settings.py b/drams/base_settings.py index db8ac2f2..c931035d 100644 --- a/drams/base_settings.py +++ b/drams/base_settings.py @@ -1,5 +1,12 @@ import os +# Bootstrap Breadcrumbs fix +import django +from django.utils.encoding import smart_str +django.utils.encoding.smart_text = smart_str + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -32,11 +39,8 @@ 'django.contrib.sites', 'django_extensions', 'crispy_forms', - 'dynamic_validator', - 'allauth', - 'allauth.account', - 'allauth.socialaccount', - 'allauth.socialaccount.providers.github', + 'crispy_bootstrap3', + 'social_django', 'custom_user.apps.CustomUserConfig', 'data_management.apps.DataManagementConfig', ] @@ -64,6 +68,8 @@ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'social_django.context_processors.backends', + 'social_django.context_processors.login_redirect', ], }, }, @@ -141,9 +147,12 @@ AUTHENTICATION_BACKENDS = ( "django.contrib.auth.backends.ModelBackend", - "allauth.account.auth_backends.AuthenticationBackend", + 'social_core.backends.github.GithubOAuth2', + 'social_core.backends.gitlab.GitLabOAuth2' ) +SOCIAL_AUTH_URL_NAMESPACE = 'social' + SITE_ID = 1 # We don't need email verification upon signup as we're using GitHub @@ -152,17 +161,10 @@ # Redirect authenticated users to this URL LOGIN_REDIRECT_URL = 'index' -# Specify required scopes -SOCIALACCOUNT_PROVIDERS = { - 'github': { - 'SCOPE': [ - 'read:user', - 'user:email', - ], - } -} +CRISPY_TEMPLATE_PACK = 'bootstrap3' CONFIG_LOCATION = "" CACHE_DURATION = 0 -AUTHORISED_USER_FILE = "" \ No newline at end of file +AUTHORISED_USER_FILE = "" +AUTH_METHOD = "" \ No newline at end of file diff --git a/drams/urls.py b/drams/urls.py index 2c55c7d4..b2efa1f8 100644 --- a/drams/urls.py +++ b/drams/urls.py @@ -14,21 +14,22 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path, include +from django.urls import include, path -from allauth.account.views import login, logout +#from allauth.account.views import login, logout urlpatterns = [ path('', include('data_management.urls')), - path('accounts/email/', login, name='disable_email'), - path('accounts/password/', login, name='disable_password'), - path('accounts/inactive/', login, name='disable_inactive'), - path('accounts/confirm-email/', login, name='disable_confirm_email'), - path('login/', login, name='account_login'), - path('logout/', logout, name='account_logout'), - path('signup/', login, name='account_signup'), - path('accounts/', include('allauth.urls')), + #path('accounts/email/', login, name='disable_email'), + #path('accounts/password/', login, name='disable_password'), + #path('accounts/inactive/', login, name='disable_inactive'), + #path('accounts/confirm-email/', login, name='disable_confirm_email'), + #path('login/', login, name='account_login'), + #path('logout/', logout, name='account_logout'), + #path('signup/', login, name='account_signup'), + #path('accounts/', include('allauth.urls')), path('grappelli', include('grappelli.urls')), path('admin/', admin.site.urls), path('', include('data_management.urls')), + path('', include('social_django.urls', namespace='social')) ] diff --git a/local-requirements.txt b/local-requirements.txt index e37253bb..a2b5436d 100644 --- a/local-requirements.txt +++ b/local-requirements.txt @@ -2,14 +2,14 @@ certifi==2020.4.5.1 chardet==3.0.4 decorator==4.4.2 defusedxml==0.6.0 -Django==3.1.13 -django-allauth==0.42.0 +Django==4.2.6 +social-auth-app-django==5.4.0 django-bootstrap-breadcrumbs==0.9.2 django-dynamic-model-validation==0.1.13 -django-extensions==2.2.9 +django-extensions==3.2.3 django-filter==2.3.0 -django-grappelli==2.14.2 -djangorestframework==3.11.2 +django-grappelli==3.0.8 +djangorestframework==3.14.0 future==0.17.1 gunicorn==20.0.4 idna==2.9 @@ -26,14 +26,15 @@ python-dateutil==2.8.1 python3-openid==3.1.0 pytz==2020.1 rdflib==6.0.1 -requests==2.25.0 +requests>=2.25.0 requests-oauthlib==1.3.0 six==1.14.0 sqlparse==0.3.1 -urllib3==1.26.5 -semver==2.10.2 +urllib3>=1.26.5 +semver>=2.10.2 django-crispy-forms==1.9.2 -Markdown==3.2.2 +crispy-bootstrap3==2022.1 +Markdown>=3.2.2 setuptools>54.2 whitenoise==5.2.0 coverage diff --git a/pyproject.toml b/pyproject.toml index ad365248..4d39ed9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,20 +15,21 @@ authors = [ ] description = "Codebase for the FAIR data-registry" name = "data-registry" -version = "v1.0.10" +version = "v1.0.11" [tool.poetry.dependencies] -Django = "3.1.13" +Django = "4.2.6" Markdown = "3.2.2" coverage = "7.2.*" -django-allauth = "0.42.0" +social-auth-app-django = "5.4.0" django-bootstrap-breadcrumbs = "0.9.2" django-crispy-forms = "1.9.2" django-dynamic-model-validation = "0.1.13" -django-extensions = "2.2.9" +django-extensions = "3.2.3" django-filter = "2.3.0" -django-grappelli = "2.14.2" -djangorestframework = "3.11.2" +django-grappelli = "3.0.8" +djangorestframework = "3.14.0" +oauthlib = "3.1.0" future = "0.17.1" gunicorn = "20.0.4" mysql-connector-python = "8.0.20" diff --git a/requirements.txt b/requirements.txt index 3777899d..a2b5436d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,20 +1,41 @@ -coverage==5.5 -Django==3.1.13 -django-allauth==0.42.0 +certifi==2020.4.5.1 +chardet==3.0.4 +decorator==4.4.2 +defusedxml==0.6.0 +Django==4.2.6 +social-auth-app-django==5.4.0 django-bootstrap-breadcrumbs==0.9.2 -django-crispy-forms==1.9.2 django-dynamic-model-validation==0.1.13 -django-extensions==2.2.9 +django-extensions==3.2.3 django-filter==2.3.0 -django-grappelli==2.14.2 -djangorestframework==3.11.2 +django-grappelli==3.0.8 +djangorestframework==3.14.0 +future==0.17.1 gunicorn==20.0.4 -Markdown==3.2.2 +idna==2.9 +isodate==0.6.0 +lxml>=4.9 mysql-connector-python==8.0.20 +networkx==3.0 +oauthlib==3.1.0 +protobuf==3.12.2 prov==2.0 pydot==1.4.2 -semver==2.10.2 +pyparsing==2.4.7 +python-dateutil==2.8.1 +python3-openid==3.1.0 +pytz==2020.1 +rdflib==6.0.1 +requests>=2.25.0 +requests-oauthlib==1.3.0 +six==1.14.0 +sqlparse==0.3.1 +urllib3>=1.26.5 +semver>=2.10.2 +django-crispy-forms==1.9.2 +crispy-bootstrap3==2022.1 +Markdown>=3.2.2 +setuptools>54.2 whitenoise==5.2.0 -future==0.17.1 -networkx==3.0 +coverage rocrate==0.7.0 diff --git a/templates/base.html b/templates/base.html index 3313af89..11bcebb4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,5 +1,5 @@ -{% load socialaccount %} {% load django_bootstrap_breadcrumbs %} +{% load auth_tags %} {% block breadcrumbs %} {% clear_breadcrumbs %} @@ -50,7 +50,14 @@ Logged in as: {{ user.username }} logout {% else %} - Log in or sign up using GitHub + {% is_auth_method "GitHub" as is_github %} + {% if is_github %} + Login / Signup with GitHub + {% endif %} + {% is_auth_method "GitLub" as is_gitlab %} + {% if is_gitlab %} + Login / Signup with GitLab + {% endif %} {% endif %} {% endif %} diff --git a/templates/rest_framework/api.html b/templates/rest_framework/api.html index 1a4dcc3f..cc761967 100644 --- a/templates/rest_framework/api.html +++ b/templates/rest_framework/api.html @@ -1,6 +1,5 @@ {% extends "rest_framework/base.html" %} -{% load socialaccount %} {% load static %} {% block style %} @@ -25,7 +24,8 @@ Logged in as: {{ user.username }} logout {% else %} - Log in or sign up using GitHub + Login / Signup with GitHub + Login / Signup with GitLab {% endif %} {% endif %}