diff --git a/.github/workflows/python-release.yml b/.github/workflows/python-release.yml index d9c2320..40ade5e 100644 --- a/.github/workflows/python-release.yml +++ b/.github/workflows/python-release.yml @@ -8,9 +8,9 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python 3.7 - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: 3.7 - name: Install build requirements diff --git a/.github/workflows/python-tox.yml b/.github/workflows/python-tox.yml index 2f0507b..18460df 100644 --- a/.github/workflows/python-tox.yml +++ b/.github/workflows/python-tox.yml @@ -9,48 +9,42 @@ jobs: strategy: max-parallel: 4 matrix: - tox_env: - - py37-django32-wagtail215 - - py38-django32-wagtail215 - - py38-django32-wagtail216 - - py38-django40-wagtail216 - - py39-django32-wagtail215 - - py39-django32-wagtail216 - - py39-django40-wagtail216 - - py310-django32-wagtail215 - - py310-django32-wagtail216 - - py310-django40-wagtail216 + python: ['3.8', '3.9', '3.10'] + django: ['3.2', '4.0'] + wagtail: ['2.16', '3.0', '4.0'] include: - - python-version: "3.7" - tox_env: py37-django32-wagtail215 - - python-version: "3.8" - tox_env: py38-django32-wagtail215 - - python-version: "3.8" - tox_env: py38-django32-wagtail216 - - python-version: "3.8" - tox_env: py38-django40-wagtail216 - - python-version: "3.9" - tox_env: py39-django32-wagtail215 - - python-version: "3.9" - tox_env: py39-django32-wagtail216 - - python-version: "3.9" - tox_env: py39-django40-wagtail216 - - python-version: "3.10" - tox_env: py310-django32-wagtail215 - - python-version: "3.10" - tox_env: py310-django32-wagtail216 - - python-version: "3.10" - tox_env: py310-django40-wagtail216 - + - wagtail: '2.15' + django: '3.2' + python: '3.7' + - wagtail: '2.15' + django: '3.2' + python: '3.8' + - wagtail: '2.15' + django: '3.2' + python: '3.9' + - wagtail: '2.15' + django: '3.2' + python: '3.10' + - wagtail: '4.0' + django: '4.1' + python: '3.8' + - wagtail: '4.0' + django: '4.1' + python: '3.9' + - wagtail: '4.0' + django: '4.1' + python: '3.10' steps: - - uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.python }} - name: Install dependencies run: | python -m pip install --upgrade pip tox - name: Test with tox run: | - tox -e ${{ matrix.tox_env }} + tox + env: + TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }} \ No newline at end of file diff --git a/sandbox/sandbox/apps/__init__.py b/sandbox/sandbox/apps/__init__.py index 8b13789..e69de29 100644 --- a/sandbox/sandbox/apps/__init__.py +++ b/sandbox/sandbox/apps/__init__.py @@ -1 +0,0 @@ - diff --git a/sandbox/sandbox/apps/home/models.py b/sandbox/sandbox/apps/home/models.py index c739141..db1d3f2 100644 --- a/sandbox/sandbox/apps/home/models.py +++ b/sandbox/sandbox/apps/home/models.py @@ -1,4 +1,3 @@ -from django.db import models from wagtail.core.models import Page diff --git a/sandbox/sandbox/settings.py b/sandbox/sandbox/settings.py index ff821d3..ac4d74d 100644 --- a/sandbox/sandbox/settings.py +++ b/sandbox/sandbox/settings.py @@ -15,6 +15,8 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +from wagtail import VERSION as WAGTAIL_VERSION + PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(PROJECT_DIR) @@ -44,7 +46,7 @@ 'wagtail.images', 'wagtail.search', 'wagtail.admin', - 'wagtail.core', + 'wagtail' if WAGTAIL_VERSION >= (3, 0) else 'wagtail.core', 'wagtail.contrib.modeladmin', 'wagtail.contrib.styleguide', @@ -159,7 +161,10 @@ # Base URL to use when referring to full URLs within the Wagtail admin backend - # e.g. in notification emails. Don't include '/admin' or a trailing slash -BASE_URL = 'http://example.com' +if WAGTAIL_VERSION >= (3, 0): + WAGTAILADMIN_BASE_URL = 'http://example.com' +else: + BASE_URL = 'http://example.com' INTERNAL_IPS = ['127.0.0.1'] diff --git a/sandbox/sandbox/urls.py b/sandbox/sandbox/urls.py index 509b5a1..4604c80 100644 --- a/sandbox/sandbox/urls.py +++ b/sandbox/sandbox/urls.py @@ -1,17 +1,22 @@ +import debug_toolbar from django.conf import settings -from django.conf.urls import include, url from django.contrib import admin +from django.urls import include, re_path +from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin import urls as wagtailadmin_urls -from wagtail.core import urls as wagtail_urls -from wagtail.documents import urls as wagtaildocs_urls -import debug_toolbar +if WAGTAIL_VERSION >= (3, 0): + from wagtail import urls as wagtail_urls +else: + from wagtail.core import urls as wagtail_urls + +from wagtail.documents import urls as wagtaildocs_urls urlpatterns = [ - url(r'^admin/', admin.site.urls), - url(r'^cms/', include(wagtailadmin_urls)), - url(r'^documents/', include(wagtaildocs_urls)), - url(r'', include(wagtail_urls)), + re_path(r'^admin/', admin.site.urls), + re_path(r'^cms/', include(wagtailadmin_urls)), + re_path(r'^documents/', include(wagtaildocs_urls)), + re_path(r'', include(wagtail_urls)), ] @@ -24,5 +29,5 @@ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns = [ - url(r'^__debug__/', include(debug_toolbar.urls)), + re_path(r'^__debug__/', include(debug_toolbar.urls)), ] + urlpatterns diff --git a/src/wagtail_2fa/views.py b/src/wagtail_2fa/views.py index 232fffe..67ddc58 100644 --- a/src/wagtail_2fa/views.py +++ b/src/wagtail_2fa/views.py @@ -1,8 +1,14 @@ import qrcode import qrcode.image.svg +from django import VERSION as DJANGO_VERSION from django.conf import settings from django.contrib.auth import REDIRECT_FIELD_NAME -from django.contrib.auth.views import SuccessURLAllowedHostsMixin + +if DJANGO_VERSION >= (4, 1): + from django.contrib.auth.views import RedirectURLMixin +else: + from django.contrib.auth.views import SuccessURLAllowedHostsMixin as RedirectURLMixin + from django.core.exceptions import PermissionDenied from django.http import HttpResponse from django.shortcuts import resolve_url @@ -12,7 +18,8 @@ from django.utils.http import url_has_allowed_host_and_scheme from django.views.decorators.cache import never_cache from django.views.decorators.debug import sensitive_post_parameters -from django.views.generic import DeleteView, FormView, ListView, UpdateView, View +from django.views.generic import ( + DeleteView, FormView, ListView, UpdateView, View) from django_otp import login as otp_login from django_otp.plugins.otp_totp.models import TOTPDevice @@ -20,7 +27,7 @@ from wagtail_2fa.mixins import OtpRequiredMixin -class LoginView(SuccessURLAllowedHostsMixin, FormView): +class LoginView(RedirectURLMixin, FormView): template_name = "wagtail_2fa/otp_form.html" form_class = forms.TokenForm redirect_field_name = REDIRECT_FIELD_NAME diff --git a/src/wagtail_2fa/wagtail_hooks.py b/src/wagtail_2fa/wagtail_hooks.py index c7ec351..1652224 100644 --- a/src/wagtail_2fa/wagtail_hooks.py +++ b/src/wagtail_2fa/wagtail_hooks.py @@ -2,8 +2,14 @@ from django.contrib.auth.models import Permission from django.urls import path, re_path, reverse from django.utils.translation import gettext_lazy as _ +from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin.menu import MenuItem -from wagtail.core import hooks + +if WAGTAIL_VERSION >= (3, 0): + from wagtail import hooks +else: + from wagtail.core import hooks + from wagtail.users.widgets import UserListingButton from wagtail_2fa import views diff --git a/tests/conftest.py b/tests/conftest.py index 1fd170d..53acfc3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ import pytest from django.conf import settings +from wagtail import VERSION as WAGTAIL_VERSION def pytest_configure(): @@ -28,7 +29,7 @@ def pytest_configure(): "wagtail.images", "wagtail.search", "wagtail.admin", - "wagtail.core", + "wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail.core", "wagtail.contrib.modeladmin", "modelcluster", "taggit", diff --git a/tests/test_middleware.py b/tests/test_middleware.py index fdc337e..2d1faf5 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -5,7 +5,8 @@ from django_otp import login as otp_login from django_otp.plugins.otp_totp.models import TOTPDevice -from wagtail_2fa.middleware import VerifyUserMiddleware, VerifyUserPermissionsMiddleware +from wagtail_2fa.middleware import ( + VerifyUserMiddleware, VerifyUserPermissionsMiddleware) def test_verified_request(rf, superuser): diff --git a/tests/test_views.py b/tests/test_views.py index 6023bba..64f26f1 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -9,7 +9,8 @@ from django_otp import DEVICE_ID_SESSION_KEY from django_otp.plugins.otp_totp.models import TOTPDevice -from wagtail_2fa.views import DeviceDeleteView, DeviceListView, DeviceUpdateView +from wagtail_2fa.views import ( + DeviceDeleteView, DeviceListView, DeviceUpdateView) def test_device_list_view(admin_client, admin_user, django_assert_max_num_queries): diff --git a/tests/urls.py b/tests/urls.py index 90709ee..083c82b 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,7 +1,13 @@ from django.contrib import admin from django.urls import include, path +from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin import urls as wagtailadmin_urls -from wagtail.core import urls as wagtail_urls + +if WAGTAIL_VERSION >= (3, 0): + from wagtail import urls as wagtail_urls +else: + from wagtail.core import urls as wagtail_urls + from wagtail.documents import urls as wagtaildocs_urls urlpatterns = [ diff --git a/tox.ini b/tox.ini index aba7639..e10b49c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,27 @@ [tox] envlist = - py{37,38,39,310}-django32-wagtail215 - py{38,39,310}-django{32,40}-wagtail216 + python{3.7,3.8,3.9,3.10}-django{3.2}-wagtail{2.15,2.16,3.0,4.0} + python{3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0} + python{3.8,3.9,3.10}-django{4.1}-wagtail{4.0} [testenv] commands = coverage run --parallel -m pytest {posargs} -vvv + +basepython = + python3.7: python3.7 + python3.8: python3.8 + python3.9: python3.9 + python3.10: python3.10 + deps = - django32: Django>=3.2,<4.0 - django40: Django>=4.0,<4.1 - wagtail215: wagtail>=2.15,<2.16 # LTS - wagtail216: wagtail>=2.16,<2.17 + django3.2: Django>=3.2,<4.0 + django4.0: Django>=4.0,<4.1 + django4.1: Django>=4.1,<4.2 + wagtail2.15: wagtail>=2.15,<2.16 # LTS + wagtail2.16: wagtail>=2.16,<2.17 + wagtail3.0: wagtail>=3.0,<3.1 + wagtail4.0: wagtail>=4.0,<4.1 + extras = test [testenv:coverage-report]