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

Add SSO with Google within the Admin and bump dependencies #49

Merged
merged 13 commits into from
Sep 10, 2024
15 changes: 9 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/megalus/django-google-sso>`_).
* Module `django-adminfilters <https://github.com/mrsarm/django-adminfilters>`_
that allows multiselection searches.
* Send emails when a task is created.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -124,8 +125,9 @@ in `Docker Hub <https://hub.docker.com/r/mrsarm/django-coleman>`_.

Also ``compose.yaml`` and ``.env.example`` files are provided in the
`dcoleman-e2e <https://github.com/mrsarm/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 <https://github.com/mrsarm/tornado-dcoleman-mtasks-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::
Expand Down Expand Up @@ -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 <https://github.com/mrsarm/dcoleman-e2e/blob/main/.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:
Expand Down
15 changes: 15 additions & 0 deletions coleman/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions coleman/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mtasks/migrations/0003_auth_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Migration(migrations.Migration):
"""

dependencies = [
('contenttypes', '__latest__'),
('auth', '__latest__'),
('mtasks', '0002_alter_task_options'),
]

Expand Down
11 changes: 6 additions & 5 deletions requirements/requirements-dev.in
Original file line number Diff line number Diff line change
@@ -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
56 changes: 50 additions & 6 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions requirements/requirements-prod.in
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions requirements/requirements-prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions requirements/requirements-test.in
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions requirements/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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