Skip to content

Commit

Permalink
feat!: Remove support for Django 4.1 and add support to 5.1
Browse files Browse the repository at this point in the history
This is a BREAKING CHANGE commit.
  • Loading branch information
chrismaille committed Aug 29, 2024
1 parent 5219a90 commit 6e7573a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12"]
django-version: ["4.1", "4.2", "5.0"]
django-version: ["4.2", "5.0", "5.1"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
59 changes: 48 additions & 11 deletions django_google_sso/checks/warnings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.core.checks import Tags, register
from django.core.checks.messages import Warning
from django.core.checks.templates import check_for_template_tags_with_the_same_name

TEMPLATE_TAG_NAMES = ["show_form", "sso_tags"]

Expand All @@ -16,20 +15,58 @@ def register_sso_check(app_configs, **kwargs):
like django_microsoft_sso and django_google_sso.
To silence any E003/W003 warning, you can add the following to your settings.py:
SILENCED_SYSTEM_CHECKS = ["templates.E003"]
SILENCED_SYSTEM_CHECKS = ["templates.W003"] # or templates.E003 for Django<=5.1
And to run an alternate version of this check,
you can add the following to your settings.py:
SSO_USE_ALTERNATE_W003 = True
You need to silence the original templates.E003 check for this to work.
New warnings will use the id `sso.E003`
You need to silence the original templates.W003 check for this to work.
New warnings will use the id `sso.W003`
"""
errors = check_for_template_tags_with_the_same_name(app_configs, **kwargs)
errors = [
Warning(msg=error.msg, hint=error.hint, obj=error.obj, id="sso.E003")
for error in errors
if not any(name in error.msg for name in TEMPLATE_TAG_NAMES)
]
return errors
try: # Django <=5.0 error was templates.E003
from django.core.checks.templates import (
check_for_template_tags_with_the_same_name,
)

errors = check_for_template_tags_with_the_same_name(app_configs, **kwargs)
errors = [
Warning(msg=error.msg, hint=error.hint, obj=error.obj, id="sso.E003")
for error in errors
if not any(name in error.msg for name in TEMPLATE_TAG_NAMES)
]
return errors
except ImportError: # Django >=5.1 error is now templates.W003
from django.apps import apps
from django.conf import settings
from django.template.backends.django import DjangoTemplates

errors = []
if app_configs is None:
app_configs = apps.get_app_configs()

errors = []
for config in app_configs:
for engine in settings.TEMPLATES:
if (
engine["BACKEND"]
== "django.template.backends.django.DjangoTemplates"
):
engine_params = engine.copy()
engine_params.pop("BACKEND")
django_engine = DjangoTemplates(engine_params)
template_tag_errors = (
django_engine._check_for_template_tags_with_the_same_name()
)
for error in template_tag_errors:
if not any(name in error.msg for name in TEMPLATE_TAG_NAMES):
errors.append(
Warning(
msg=error.msg,
hint=error.hint,
obj=error.obj,
id="sso.W003",
)
)
return errors
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pip install django-google-sso

!!! info "Currently this project supports:"
* Python 3.10, 3.11 and 3.12
* Django 4.2 and 5.0
* Django 4.2, 5.0 and 5.1

For python 3.8 please use version 2.x
For python 3.9 please use version 3.x
4 changes: 2 additions & 2 deletions docs/multiple.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ This is because both packages use the same template tags. To silence this warnin

```python
# settings.py
SILENCED_SYSTEM_CHECKS = ["templates.E003"]
SILENCED_SYSTEM_CHECKS = ["templates.W003"] # Or "templates.E003" for Django <=5.0
```

But if you need to check the templates, you can use the `SSO_USE_ALTERNATE_W003` setting to use an alternate template tag. This alternate check will
Expand All @@ -143,6 +143,6 @@ run the original check, but will not raise the warning for the Django SSO packag
```python
# settings.py

SILENCED_SYSTEM_CHECKS = ["templates.E003"] # Will silence the original check
SILENCED_SYSTEM_CHECKS = ["templates.W003"] # Will silence the original check
SSO_USE_ALTERNATE_W003 = True # Will run alternate check
```
3 changes: 2 additions & 1 deletion docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| `GOOGLE_SSO_NEXT_URL` | The named url path that the user will be redirected if there is no next url after successful authentication. Default: `admin:index` |
| `GOOGLE_SSO_PRE_CREATE_CALLBACK` | Callable for processing pre-create logic. Default: `django_google_sso.hooks.pre_create_user` |
| `GOOGLE_SSO_PRE_LOGIN_CALLBACK` | Callable for processing pre-login logic. Default: `django_google_sso.hooks.pre_login_user` |
| `GOOGLE_SSO_PRE_VALIDATE_CALLBACK` | Callable for processing pre-validate logic. Default: `django_google_sso.hooks.pre_validate_user` |
| `GOOGLE_SSO_PROJECT_ID` | The Google OAuth 2.0 Project ID. Default: `None` |
| `GOOGLE_SSO_SAVE_ACCESS_TOKEN` | Save the access token in the session. Default: `False` |
| `GOOGLE_SSO_SAVE_BASIC_GOOGLE_INFO` | Save basic Google info in the database. Default: `True` |
Expand All @@ -29,4 +30,4 @@
| `GOOGLE_SSO_TEXT` | The text to be used on the login button. Default: `Sign in with Google` |
| `GOOGLE_SSO_TIMEOUT` | The timeout in seconds for the Google SSO authentication returns info, in minutes. Default: `10` |
| `SSO_SHOW_FORM_ON_ADMIN_PAGE` | Show the form on the admin page. Default: `True` |
| `SSO_USE_ALTERNATE_W003` | Use alternate W003 warning. You need to silence original templates.E003 warning. Default: `False` |
| `SSO_USE_ALTERNATE_W003` | Use alternate W003 warning. You need to silence original templates.W003 warning. Default: `False` | |
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ keywords = ["google", "django", "sso"]
license = "MIT"
classifiers = [
"Framework :: Django",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Intended Audience :: Developers",
"Development Status :: 5 - Production/Stable",
"Environment :: Plugins"
]

[tool.poetry.dependencies]
python = ">=3.10, <4.0"
django = ">=4.1"
django = ">=4.2"
loguru = "*"
google-auth = "*"
google-auth-httplib2 = "*"
Expand Down

0 comments on commit 6e7573a

Please sign in to comment.