From 30fb311b2ead289fb27f7880c9d228bfa400c7b4 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 8 Mar 2020 23:03:35 +0100 Subject: [PATCH 1/2] modular settings start --- note_kfet/settings/__init__.py | 34 +++++++++++++++++++++--- note_kfet/settings/base.py | 28 -------------------- note_kfet/settings/secrets_example.py | 9 +++++++ note_kfet/urls.py | 38 ++++++++++++++++++--------- 4 files changed, 66 insertions(+), 43 deletions(-) create mode 100644 note_kfet/settings/secrets_example.py diff --git a/note_kfet/settings/__init__.py b/note_kfet/settings/__init__.py index a2e28372..6d871599 100644 --- a/note_kfet/settings/__init__.py +++ b/note_kfet/settings/__init__.py @@ -33,14 +33,42 @@ if app_stage == 'prod': DATABASES["default"]["PASSWORD"] = os.environ.get('DJANGO_DB_PASSWORD', 'CHANGE_ME_IN_ENV_SETTINGS') SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'CHANGE_ME_IN_ENV_SETTINGS') - ALLOWED_HOSTS.append(os.environ.get('ALLOWED_HOSTS', 'localhost')) + ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOSTS', 'localhost')] else: from .development import * try: + #in secrets.py defines everything you want from .secrets import * except ImportError: pass -# env variables set at the of in /env/bin/activate -# don't forget to unset in deactivate ! +if "cas" in INSTALLED_APPS: + MIDDLEWARE += ['cas.middleware.CASMiddleware'] + # CAS Settings + CAS_AUTO_CREATE_USER = False + CAS_LOGO_URL = "/static/img/Saperlistpopette.png" + CAS_FAVICON_URL = "/static/favicon/favicon-32x32.png" + CAS_SHOW_SERVICE_MESSAGES = True + CAS_SHOW_POWERED = False + CAS_REDIRECT_TO_LOGIN_AFTER_LOGOUT = False + CAS_INFO_MESSAGES = { + "cas_explained": { + "message": _( + u"The Central Authentication Service grants you access to most of our websites by " + u"authenticating only once, so you don't need to type your credentials again unless " + u"your session expires or you logout." + ), + "discardable": True, + "type": "info", # one of info, success, info, warning, danger + }, + } + + CAS_INFO_MESSAGES_ORDER = [ + 'cas_explained', + ] + AUTHENTICATION_BACKENDS += ('cas.backends.CASBackend',) + +if "debug_toolbar" in INSTALLED_APPS: + MIDDLEWARE.insert(1,"debug_toolbar.middleware.DebugToolbarMiddleware") + INTERNAL_IPS = [ '127.0.0.1'] diff --git a/note_kfet/settings/base.py b/note_kfet/settings/base.py index 103e368d..f339699c 100644 --- a/note_kfet/settings/base.py +++ b/note_kfet/settings/base.py @@ -55,9 +55,6 @@ INSTALLED_APPS = [ # Autocomplete 'dal', 'dal_select2', - # CAS - 'cas_server', - 'cas', # Note apps 'activity', @@ -80,7 +77,6 @@ MIDDLEWARE = [ 'django.middleware.locale.LocaleMiddleware', 'django.contrib.sites.middleware.CurrentSiteMiddleware', 'note_kfet.middlewares.TurbolinksMiddleware', - 'cas.middleware.CASMiddleware', ] ROOT_URLCONF = 'note_kfet.urls' @@ -134,7 +130,6 @@ PASSWORD_HASHERS = [ AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', # this is default 'guardian.backends.ObjectPermissionBackend', - 'cas.backends.CASBackend', ) REST_FRAMEWORK = { @@ -201,26 +196,3 @@ MEDIA_URL = '/media/' # Profile Picture Settings PIC_WIDTH = 200 PIC_RATIO = 1 - -# CAS Settings -CAS_AUTO_CREATE_USER = False -CAS_LOGO_URL = "/static/img/Saperlistpopette.png" -CAS_FAVICON_URL = "/static/favicon/favicon-32x32.png" -CAS_SHOW_SERVICE_MESSAGES = True -CAS_SHOW_POWERED = False -CAS_REDIRECT_TO_LOGIN_AFTER_LOGOUT = False -CAS_INFO_MESSAGES = { - "cas_explained": { - "message": _( - u"The Central Authentication Service grants you access to most of our websites by " - u"authenticating only once, so you don't need to type your credentials again unless " - u"your session expires or you logout." - ), - "discardable": True, - "type": "info", # one of info, success, info, warning, danger - }, -} - -CAS_INFO_MESSAGES_ORDER = [ - 'cas_explained', -] diff --git a/note_kfet/settings/secrets_example.py b/note_kfet/settings/secrets_example.py new file mode 100644 index 00000000..70d17ad4 --- /dev/null +++ b/note_kfet/settings/secrets_example.py @@ -0,0 +1,9 @@ +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +# CAS +OPTIONAL_APPS = [ +# 'cas_server', +# 'cas', +# 'debug_toolbar' +] diff --git a/note_kfet/urls.py b/note_kfet/urls.py index 56251955..b4f4ed5c 100644 --- a/note_kfet/urls.py +++ b/note_kfet/urls.py @@ -1,7 +1,6 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from cas import views as cas_views from django.conf import settings from django.conf.urls.static import static from django.contrib import admin @@ -15,25 +14,40 @@ urlpatterns = [ # Include project routers path('note/', include('note.urls')), - # Include CAS Client routers - path('accounts/login/', cas_views.login, name='login'), - path('accounts/logout/', cas_views.logout, name='logout'), - # Include Django Contrib and Core routers path('i18n/', include('django.conf.urls.i18n')), path('accounts/', include('member.urls')), path('accounts/', include('django.contrib.auth.urls')), path('admin/doc/', include('django.contrib.admindocs.urls')), path('admin/', admin.site.urls), - - # Include CAS Server routers - path('cas/', include('cas_server.urls', namespace="cas_server")), - - # Include Django REST API - path('api/', include('api.urls')), - path('logs/', include('logs.urls')), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + + +if "cas_server" in settings.INSTALLED_APPS: + urlpatterns += [ + # Include CAS Server routers + path('cas/', include('cas_server.urls', namespace="cas_server")), + ] +if "cas" in settings.INSTALLED_APPS: + from cas import views as cas_views + urlpatterns += [ + # Include CAS Client routers + path('accounts/login/', cas_views.login, name='login'), + path('accounts/logout/', cas_views.logout, name='logout'), + + ] +if "debug_toolbar" in settings.INSTALLED_APPS: + import debug_toolbar + urlpatterns = [ + path('__debug__/', include(debug_toolbar.urls)), + ] + urlpatterns + +if "api" in settings.INSTALLED_APPS: + # Include Django REST API + urlpatterns += [ + path('api/', include('api.urls')), + ] From 7d616eb1c93146c04966e382623f3cb3a810004e Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Mon, 9 Mar 2020 11:48:39 +0100 Subject: [PATCH 2/2] api should stay mandatory --- note_kfet/urls.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/note_kfet/urls.py b/note_kfet/urls.py index b4f4ed5c..896c0655 100644 --- a/note_kfet/urls.py +++ b/note_kfet/urls.py @@ -21,6 +21,7 @@ urlpatterns = [ path('admin/doc/', include('django.contrib.admindocs.urls')), path('admin/', admin.site.urls), path('logs/', include('logs.urls')), + path('api/', include('api.urls')), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) @@ -45,9 +46,3 @@ if "debug_toolbar" in settings.INSTALLED_APPS: urlpatterns = [ path('__debug__/', include(debug_toolbar.urls)), ] + urlpatterns - -if "api" in settings.INSTALLED_APPS: - # Include Django REST API - urlpatterns += [ - path('api/', include('api.urls')), - ]