Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanJField committed Nov 24, 2023
1 parent fcba13a commit de1f64e
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 58 deletions.
3 changes: 1 addition & 2 deletions data_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
"""
Expand Down
12 changes: 12 additions & 0 deletions data_management/templatetags/auth_tags.py
Original file line number Diff line number Diff line change
@@ -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
34 changes: 18 additions & 16 deletions drams/base_settings.py
Original file line number Diff line number Diff line change
@@ -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__)))

Expand Down Expand Up @@ -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',
]
Expand Down Expand Up @@ -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',
],
},
},
Expand Down Expand Up @@ -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
Expand All @@ -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 = ""
AUTHORISED_USER_FILE = ""
AUTH_METHOD = ""
21 changes: 11 additions & 10 deletions drams/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
]
19 changes: 10 additions & 9 deletions local-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 32 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
11 changes: 9 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load socialaccount %}
{% load django_bootstrap_breadcrumbs %}
{% load auth_tags %}

{% block breadcrumbs %}
{% clear_breadcrumbs %}
Expand Down Expand Up @@ -50,7 +50,14 @@
Logged in as: {{ user.username }}
<a href="logout">logout</a>
{% else %}
<a href="{% provider_login_url 'github' %}">Log in or sign up using GitHub</a>
{% is_auth_method "GitHub" as is_github %}
{% if is_github %}
<a href="{% url 'social:begin' 'github' %}">Login / Signup with GitHub </a>
{% endif %}
{% is_auth_method "GitLub" as is_gitlab %}
{% if is_gitlab %}
<a href="{% url 'social:begin' 'gitlab' %}">Login / Signup with GitLab </a>
{% endif %}
{% endif %}
</span>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/rest_framework/api.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "rest_framework/base.html" %}

{% load socialaccount %}
{% load static %}

{% block style %}
Expand All @@ -25,7 +24,8 @@
Logged in as: {{ user.username }}
<a href="/logout">logout</a>
{% else %}
<a href="{% provider_login_url 'github' %}">Log in or sign up using GitHub</a>
<a href="{% url 'social:begin' 'github' %}">Login / Signup with GitHub </a>
<a href="{% url 'social:begin' 'gitlab' %}">Login / Signup with GitLab </a>
{% endif %}
</span>
{% endif %}
Expand Down

0 comments on commit de1f64e

Please sign in to comment.