diff --git a/README.rst b/README.rst index 3ce946f..6a0ae01 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,8 @@ Features partner (customer, provider...), description, responsible of the task, priority... * Each task may have items: sub-tasks to be done. * The built-in Django *Authentication and Authorization* system - to manage users and groups, login, etc. + to manage users and groups, login, etc, and optionally SSO with Google + within the Admin (`django-google-sso `_). * Module `django-adminfilters `_ that allows multiselection searches. * Send emails when a task is created. @@ -44,7 +45,7 @@ Requirements Docker, or: -* Python 3.8+ (tested with Python 3.8 and 3.11). +* Python 3.10+ (tested with 3.11). * Django 4.2 LTS and other dependencies declared in the ``requirements.txt`` file (use virtual environments or containers!). * A Django compatible database like PostgreSQL (by default uses @@ -124,8 +125,9 @@ in `Docker Hub `_. Also ``compose.yaml`` and ``.env.example`` files are provided in the `dcoleman-e2e `_ project, you -can run all from there, Django Coleman, the viewer app and Postgres, -and the E2E tests. +can run all from there, Django Coleman, the +`viewer `_ app +and Postgres, and the E2E tests. First, copy the ``.env.example`` file as ``.env`` files from the E2E repo, and edit whatever value you want to:: @@ -199,10 +201,11 @@ set *debug* options to false:: $ DEBUG=False LANGUAGE_CODE=es-ar python3 manage.py runserver Also in development environments an ``.env`` file can be used to setup -the environment variables easily, checkout the `<.env.example>`_ as example. +the environment variables easily, checkout the +`.env.example `_ as example. You can copy the example file and edit the variables you want to change:: - $ cp .env.example .env + $ cp ../dcoleman-e2e/.env.example .env $ vi .env Some available settings: diff --git a/coleman/settings.py b/coleman/settings.py index 0debcbf..ff4d2f9 100644 --- a/coleman/settings.py +++ b/coleman/settings.py @@ -176,6 +176,21 @@ ] } +SESSION_COOKIE_AGE = 8 * 60 * 60 + + +# Google SSO (django-google-sso) +GOOGLE_SSO_ENABLED = env.bool('GOOGLE_SSO_ENABLED', False) +if GOOGLE_SSO_ENABLED: + SSO_SHOW_FORM_ON_ADMIN_PAGE = env.bool('SSO_SHOW_FORM_ON_ADMIN_PAGE', True) + GOOGLE_SSO_CLIENT_ID = env.str("GOOGLE_SSO_CLIENT_ID", None) + GOOGLE_SSO_CLIENT_SECRET = env.str('GOOGLE_SSO_CLIENT_SECRET', None) + GOOGLE_SSO_PROJECT_ID = env.str('GOOGLE_SSO_PROJECT_ID', "django-coleman") + GOOGLE_SSO_AUTO_CREATE_USERS = True + GOOGLE_SSO_STAFF_LIST = ["*"] + GOOGLE_SSO_ALLOWABLE_DOMAINS = env.str('GOOGLE_SSO_ALLOWABLE_DOMAINS', "gmail.com").split(',') + INSTALLED_APPS += ['django_google_sso'] + # # Custom configurations diff --git a/coleman/urls.py b/coleman/urls.py index 85ba623..0ead31a 100644 --- a/coleman/urls.py +++ b/coleman/urls.py @@ -13,9 +13,8 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ -from django.urls import re_path, include +from django.urls import path, re_path, include from django.contrib import admin -from django.urls import path from django.conf import settings from django.http import HttpResponseRedirect @@ -29,13 +28,23 @@ urlpatterns = [ re_path('^api/v1/', include(router.urls)), + re_path(r'^health/', include('health_check.urls')), ] if settings.ADMIN: urlpatterns = [ re_path(r'^$', lambda r: HttpResponseRedirect('admin/')), # Remove this redirect if you add custom views path('admin/', admin.site.urls), - re_path(r'^health/', include('health_check.urls')), + ] + urlpatterns + +if settings.GOOGLE_SSO_ENABLED: + urlpatterns = [ + path( + "google_sso/", include( + "django_google_sso.urls", + namespace="django_google_sso" + ) + ), ] + urlpatterns admin.site.site_title = admin.site.site_header = settings.SITE_HEADER diff --git a/mtasks/migrations/0003_auth_groups.py b/mtasks/migrations/0003_auth_groups.py index 3a50644..6f2a323 100644 --- a/mtasks/migrations/0003_auth_groups.py +++ b/mtasks/migrations/0003_auth_groups.py @@ -64,6 +64,8 @@ class Migration(migrations.Migration): """ dependencies = [ + ('contenttypes', '__latest__'), + ('auth', '__latest__'), ('mtasks', '0002_alter_task_options'), ] diff --git a/requirements/requirements-dev.in b/requirements/requirements-dev.in index 206d5cc..1519c2a 100644 --- a/requirements/requirements-dev.in +++ b/requirements/requirements-dev.in @@ -1,8 +1,9 @@ Django~=4.2 -environs~=9.5.0 -dj-database-url~=1.3.0 +environs~=11.0.0 +dj-database-url~=2.2.0 django-admin-list-filter-dropdown~=1.0.3 -django-adminfilters~=2.1.0 +django-adminfilters~=2.4.3 djangorestframework~=3.15.2 -django-extensions~=3.2.1 -django-health-check~=3.17.0 +django-extensions~=3.2.3 +django-google-sso~=6.5.0 +django-health-check~=3.18.3 diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index a18fef6..7e750fb 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -6,32 +6,76 @@ # asgiref==3.6.0 # via django -dj-database-url==1.3.0 +cachetools==5.5.0 + # via google-auth +certifi==2024.7.4 + # via requests +charset-normalizer==3.3.2 + # via requests +dj-database-url==2.2.0 # via -r requirements-dev.in django==4.2.15 # via # -r requirements-dev.in # dj-database-url # django-extensions + # django-google-sso # django-health-check # djangorestframework django-admin-list-filter-dropdown==1.0.3 # via -r requirements-dev.in -django-adminfilters==2.1.0 +django-adminfilters==2.4.3 # via -r requirements-dev.in -django-extensions==3.2.1 +django-extensions==3.2.3 # via -r requirements-dev.in -django-health-check==3.17.0 +django-google-sso==6.5.0 + # via -r requirements-dev.in +django-health-check==3.18.3 # via -r requirements-dev.in djangorestframework==3.15.2 # via -r requirements-dev.in -environs==9.5.0 +environs==11.0.0 # via -r requirements-dev.in -marshmallow==3.14.1 +google-auth==2.34.0 + # via + # django-google-sso + # google-auth-httplib2 + # google-auth-oauthlib +google-auth-httplib2==0.2.0 + # via django-google-sso +google-auth-oauthlib==1.2.1 + # via django-google-sso +httplib2==0.22.0 + # via google-auth-httplib2 +idna==3.8 + # via requests +loguru==0.7.2 + # via django-google-sso +marshmallow==3.22.0 # via environs +oauthlib==3.2.2 + # via requests-oauthlib +packaging==24.1 + # via marshmallow +pyasn1==0.6.0 + # via + # pyasn1-modules + # rsa +pyasn1-modules==0.4.0 + # via google-auth +pyparsing==3.1.4 + # via httplib2 python-dotenv==0.19.2 # via environs +requests==2.32.3 + # via requests-oauthlib +requests-oauthlib==2.0.0 + # via google-auth-oauthlib +rsa==4.9 + # via google-auth sqlparse==0.5.0 # via django typing-extensions==4.5.0 # via dj-database-url +urllib3==2.2.2 + # via requests diff --git a/requirements/requirements-prod.in b/requirements/requirements-prod.in index d1bf821..1e311fc 100644 --- a/requirements/requirements-prod.in +++ b/requirements/requirements-prod.in @@ -1,4 +1,4 @@ # Web server -uWSGI~=2.0.22 +uWSGI~=2.0.26 # PosgreSQL driver -psycopg[binary]~=3.1.8 +psycopg[binary]~=3.2.1 diff --git a/requirements/requirements-prod.txt b/requirements/requirements-prod.txt index 0174f24..504b2f8 100644 --- a/requirements/requirements-prod.txt +++ b/requirements/requirements-prod.txt @@ -4,11 +4,11 @@ # # pip-compile --no-emit-index-url --output-file=requirements-prod.txt requirements-prod.in # -psycopg[binary]==3.1.8 +psycopg[binary]==3.2.1 # via -r requirements-prod.in -psycopg-binary==3.1.8 +psycopg-binary==3.2.1 # via psycopg typing-extensions==4.5.0 # via psycopg -uwsgi==2.0.22 +uwsgi==2.0.26 # via -r requirements-prod.in diff --git a/requirements/requirements-test.in b/requirements/requirements-test.in index efbbea5..159a1a4 100644 --- a/requirements/requirements-test.in +++ b/requirements/requirements-test.in @@ -1,3 +1,3 @@ -pytest~=7.3.0 +pytest~=7.4.4 pytest-cov~=4.0.0 -pytest-django==4.5.2 +pytest-django==4.8.0 diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index c6e3f97..dcd57d5 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -8,20 +8,20 @@ coverage[toml]==6.3.1 # via pytest-cov iniconfig==1.1.1 # via pytest -packaging==21.3 +packaging==24.1 # via pytest pluggy==1.0.0 # via pytest -pyparsing==3.0.7 +pyparsing==3.1.4 # via packaging -pytest==7.3.0 +pytest==7.4.4 # via # -r requirements-test.in # pytest-cov # pytest-django pytest-cov==4.0.0 # via -r requirements-test.in -pytest-django==4.5.2 +pytest-django==4.8.0 # via -r requirements-test.in tomli==2.0.1 # via coverage