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

Django upgade #216

Merged
merged 12 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ session_port.log
session_address.log
coverage.xml
.coverage
.DS_Store
16 changes: 16 additions & 0 deletions custom_user/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ def create_superuser(self, username, password=None, **extra_fields):
raise ValueError('Superuser must have is_superuser=True.')

return self._create_user(username, password, **extra_fields)

def create_user(self, password=None, **kwargs):
"""Create and return a `User` with an username"""

username = kwargs.get('username')

if username is None:
raise TypeError("Users must have a username.")

user = self.model(
username = self.model.normalize_username(username)
)
user.set_password(password)
user.save()

return user
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
9 changes: 8 additions & 1 deletion data_management/rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
from django_filters import constants, filters
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from django.http import Http404
from django.http import Http404, JsonResponse
from django.shortcuts import get_object_or_404
from django.db.models import Q
from django.conf import settings as conf_settings

from data_management import models, object_storage, settings
from data_management import object_storage
Expand Down Expand Up @@ -563,3 +564,9 @@ class CodeRunViewSet(BaseViewSet, mixins.UpdateModelMixin, mixins.DestroyModelMi
data['renderer_classes'] = BaseViewSet.renderer_classes + [TextRenderer]
globals()[name + "ViewSet"] = type(name + "ViewSet", (BaseViewSet,), data)

def auth_provider(request):
"""Returns Auth Provider in Json Format"""
_data = {
"auth_provider":conf_settings.AUTH_METHOD
}
return JsonResponse(_data)
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
4 changes: 3 additions & 1 deletion data_management/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
path('external_object/<path:alternate_identifier>:<path:title>@<str:version>', views.external_object, name='get_external_object'),
path('data/<str:name>', views.get_data),
path('api/data/<str:checksum>', api_views.ObjectStorageView.as_view()),
path('api/data', api_views.ObjectStorageView.as_view())
path('api/data', api_views.ObjectStorageView.as_view()),
path('api/auth-provider', api_views.auth_provider),
path('logout', views.logout),
]


Expand Down
6 changes: 6 additions & 0 deletions data_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.views import generic
from django.utils.text import camel_case_to_spaces
from django.contrib.auth import get_user_model
from django.contrib.auth import logout as auth_logout
from django.db.models import Q
from django.contrib.sites.models import Site
from rest_framework import status
Expand Down Expand Up @@ -293,3 +294,8 @@ def external_object(request, alternate_identifier, title, version):

# External object exists but there is no StorageLocation or original_store
return HttpResponse(status=204)

def logout(request):
"""Logs out user"""
auth_logout(request)
return redirect("/")
35 changes: 19 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,28 +147,25 @@

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
ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_UNIQUE_EMAIL = False

# 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'))
]
24 changes: 12 additions & 12 deletions local-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ 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 +25,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
six==1.16.0
sqlparse==0.3.1
urllib3==1.26.5
semver==2.10.2
django-crispy-forms==1.9.2
Markdown==3.2.2
urllib3>=1.26.5
semver>=2.10.2
django-crispy-forms==1.14.0
crispy-bootstrap3==2022.1
Markdown==3.5.1
setuptools>54.2
whitenoise==5.2.0
coverage
Expand Down
Loading
Loading