Skip to content

Commit

Permalink
Merge pull request labd#227 from torchbox-forks/support/wagtail-51
Browse files Browse the repository at this point in the history
Wagtail 4.0 - 5.1
  • Loading branch information
davisnando authored Oct 30, 2023
2 parents a065cf0 + ef46a17 commit 1f0f8f0
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 128 deletions.
32 changes: 3 additions & 29 deletions .github/workflows/python-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,8 @@ jobs:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python: ['3.8', '3.9', '3.10']
django: ['3.2', '4.0']
wagtail: ['2.16', '3.0', '4.0']
include:
- 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'
python: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
Expand All @@ -42,9 +17,8 @@ jobs:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip tox
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: |
tox
env:
TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@

# Editors
.idea/
/venv/
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.0.0 (2023-07-24)
=================

- Includes [217](https://github.com/labd/wagtail-2fa/pull/217)
- Includes [220](https://github.com/labd/wagtail-2fa/pull/220)
- Adds support for Wagtail v4.1+ upto v5.0

1.5.0 (2021-8-23)
=================
- Add support for Wagtail 2.13
Expand Down
2 changes: 1 addition & 1 deletion sandbox/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django>=3.2
wagtail>=2.15
wagtail>=4.1
django-debug-toolbar==3.2.2
-e .[docs,test]
2 changes: 1 addition & 1 deletion sandbox/sandbox/apps/home/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from wagtail.core.models import Page
from wagtail.models import Page


class HomePage(Page):
Expand Down
14 changes: 6 additions & 8 deletions sandbox/sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# 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)

Expand Down Expand Up @@ -46,8 +44,9 @@
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail' if WAGTAIL_VERSION >= (3, 0) else 'wagtail.core',
'wagtail.contrib.modeladmin',
'wagtail',
# 'wagtail_modeladmin', # if Wagtail >=5.1; Don't repeat if it's there already
'wagtail.contrib.modeladmin', # if Wagtail <5.1; Don't repeat if it's there already
'wagtail.contrib.styleguide',

'modelcluster',
Expand Down Expand Up @@ -161,13 +160,12 @@

# 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
if WAGTAIL_VERSION >= (3, 0):
WAGTAILADMIN_BASE_URL = 'http://example.com'
else:
BASE_URL = 'http://example.com'

WAGTAILADMIN_BASE_URL = 'http://example.com'

INTERNAL_IPS = ['127.0.0.1']


WAGTAIL_2FA_REQUIRED = True

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
9 changes: 2 additions & 7 deletions sandbox/sandbox/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
from django.conf import settings
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

if WAGTAIL_VERSION >= (3, 0):
from wagtail import urls as wagtail_urls
else:
from wagtail.core import urls as wagtail_urls

from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls

urlpatterns = [
Expand Down
13 changes: 9 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

install_requires = [
"Django>=3.2",
"Wagtail>=2.15",
"Wagtail>=4.1",
"django-otp>=0.8.1",
"six>=1.14.0",
"qrcode>=6.1",
Expand Down Expand Up @@ -46,7 +46,7 @@
"docs": docs_require,
"test": tests_require,
},
python_requires=">=3.7",
python_requires=">=3.8",
use_scm_version=True,
entry_points={},
package_dir={"": "src"},
Expand All @@ -58,13 +58,18 @@
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Wagtail",
"Framework :: Wagtail :: 2",
"Framework :: Wagtail :: 3",
"Framework :: Wagtail :: 4",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
zip_safe=False,
)
2 changes: 0 additions & 2 deletions src/wagtail_2fa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
default_app_config = "wagtail_2fa.apps.Wagtail2faConfig"

__version__ = "1.6.5"
4 changes: 3 additions & 1 deletion src/wagtail_2fa/templates/wagtail_2fa/device_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ <h2>URL:</h2>
</li>
{% endif %}
{% for field in form %}
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
<li>
{% include "wagtailadmin/shared/field.html" with field=field %}
</li>
{% endfor %}
<li class="submit">
<a href="{% url 'wagtail_2fa_device_list' user.id %}" class="button button-secondary">{% trans "Cancel" %}</a>
Expand Down
78 changes: 33 additions & 45 deletions src/wagtail_2fa/templates/wagtail_2fa/legacy/otp_form.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{% extends "wagtailadmin/admin_base.html" %}
{% load static i18n %}
{% load i18n wagtailadmin_tags %}
{% block titletag %}{% trans "Sign in" %}{% endblock %}
{% block bodyclass %}login{% endblock %}

{% block extra_css %}
{{ block.super }}

<link rel="stylesheet" href="{% static 'wagtailadmin/css/layouts/login.css' %}" type="text/css" />
{% endblock %}

{% block furniture %}
<div class="content-wrapper">
{% if messages or form.errors %}
<div class="messages">
<main class="content-wrapper" id="main">
<h1>{% block branding_login %}{% trans "Enter your two-factor authentication code" %}{% endblock %}</h1>

<div class="messages" role="status">
{# Always show messages div so it can be appended to by JS #}
{% if messages or form.errors %}
<ul>
{% if form.errors %}
<li class="error">{% blocktrans %}Invalid code{% endblocktrans %}</li>
Expand All @@ -21,54 +18,45 @@
<li class="{{ message.tags }}">{{ message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endif %}
</div>

{% block above_login %}{% endblock %}

<form action="{% url 'wagtail_2fa_auth' %}" method="post" autocomplete="off" novalidate>
{% block login_form %}
{% csrf_token %}
{% csrf_token %}

{% url 'wagtailadmin_home' as home_url %}
<input type="hidden" name="next" value="{{ next|default:home_url }}" />
{% url 'wagtailadmin_home' as home_url %}
<input type="hidden" name="next" value="{{ next|default:home_url }}" />

<h1>{% block branding_login %}{% trans "Enter your two-factor authentication code" %}{% endblock %}</h1>

<ul class="fields">
{% block fields %}
<li class="full">
<div class="field iconfield">
{{ form.otp_token.label_tag }}
<div class="input icon-locked">
{{ form.otp_token }}
</div>
</div>
</li>
{% field field=form.otp_token %}{% endfield %}

{% block extra_fields %}
{% for field_name, field in form.extra_fields %}gs
<li class="full">
{{ field.label_tag }}
<div class="field iconfield">
{{ field }}
</div>
</li>
{% endfor %}
{% endblock extra_fields %}
{% block extra_fields %}
{% for field_name, field in form.extra_fields %}
{% field field=field %}{% endfield %}
{% endfor %}
{% endblock extra_fields %}

{% endblock %}
<li class="submit">
{% block submit_buttons %}
<button type="submit" class="button button-longrunning" tabindex="3" data-clicked-text="{% trans 'Signing in…' %}"><span class="icon icon-spinner"></span><em>{% trans 'Sign in' %}</em></button>
<a href="{% url "wagtailadmin_logout" %}" class="button button-secondary" tabindex="4">{% trans 'Sign out' %}</a>
{% endblock %}
</li>
</ul>
{% endblock %}
{% endblock %}
<footer class="form-actions">
{% block submit_buttons %}
<button type="submit" class="button button-longrunning" tabindex="3" data-clicked-text="{% trans 'Signing in…' %}">{% icon name="spinner" %}<em>{% trans 'Sign in' %}</em></button>
<span style="margin-top:1rem;display:block;">
<a href="{% url 'wagtailadmin_logout' %}" class="button button-secondary" tabindex="4">{% trans 'Sign out' %}</a>
</span>
{% endblock %}
</footer>
</form>

{% block below_login %}{% endblock %}

</div>
{% block branding_logo %}
<div class="login-logo">
<img class="login-logo-img" alt="" src="{% versioned_static 'wagtailadmin/images/wagtail-logo.svg' %}" />
</div>
{% endblock %}
</main>
{% endblock %}
6 changes: 4 additions & 2 deletions src/wagtail_2fa/templates/wagtail_2fa/otp_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ <h1>{% block branding_login %}{% trans "Enter your two-factor authentication cod
{% endblock %}
<footer class="form-actions">
{% block submit_buttons %}
<button type="submit" class="button button-longrunning" tabindex="3" data-clicked-text="{% trans 'Signing in…' %}">{% icon name="spinner" %}<em>{% trans 'Sign in' %}</em></button>
<a href="{% url "wagtailadmin_logout" %}" class="button button-secondary" tabindex="4">{% trans 'Sign out' %}</a>
<button type="submit" class="button button-longrunning" tabindex="3" data-controller="w-progress" data-action="w-progress#activate" data-w-progress-active-value="{% trans 'Signing in…' %}">{% icon name="spinner" %}<em>{% trans 'Sign in' %}</em></button>
<span style="margin-top:1rem;display:block;">
<a href="{% url 'wagtailadmin_logout' %}" class="button button-secondary" tabindex="4">{% trans 'Sign out' %}</a>
</span>
{% endblock %}
</footer>
</form>
Expand Down
7 changes: 5 additions & 2 deletions src/wagtail_2fa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
else:
from django.contrib.auth.views import SuccessURLAllowedHostsMixin as RedirectURLMixin

from wagtail import VERSION as WAGTAIL_VERSION

from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.shortcuts import resolve_url
Expand All @@ -23,16 +25,17 @@
from django_otp import login as otp_login
from django_otp.plugins.otp_totp.models import TOTPDevice

from wagtail import VERSION as WAGTAIL_VERSION
from wagtail_2fa import forms, utils
from wagtail_2fa.mixins import OtpRequiredMixin


class LoginView(RedirectURLMixin, FormView):
if WAGTAIL_VERSION >= (4, 0, 0):

if WAGTAIL_VERSION >= (5, 0):
template_name = "wagtail_2fa/otp_form.html"
else:
template_name = "wagtail_2fa/legacy/otp_form.html"

form_class = forms.TokenForm
redirect_field_name = REDIRECT_FIELD_NAME

Expand Down
9 changes: 2 additions & 7 deletions src/wagtail_2fa/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
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

if WAGTAIL_VERSION >= (3, 0):
from wagtail import hooks
else:
from wagtail.core import hooks

from wagtail import hooks
from wagtail.admin.menu import MenuItem
from wagtail.users.widgets import UserListingButton

from wagtail_2fa import views
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from django.conf import settings
from wagtail import VERSION as WAGTAIL_VERSION


def pytest_configure():
Expand Down Expand Up @@ -29,8 +28,9 @@ def pytest_configure():
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail.core",
"wagtail.contrib.modeladmin",
"wagtail",
# "wagtail_modeladmin", # if Wagtail >=5.1; Don't repeat if it's there already
"wagtail.contrib.modeladmin", # if Wagtail <5.1; Don't repeat if it's there already
"modelcluster",
"taggit",
"django.contrib.admin",
Expand Down
3 changes: 2 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DeviceDeleteView, DeviceListView, DeviceUpdateView)



def test_device_list_view(admin_client, admin_user, django_assert_max_num_queries):
with override_settings(WAGTAIL_2FA_REQUIRED=True):
admin_device = TOTPDevice.objects.create(
Expand All @@ -32,7 +33,7 @@ def test_device_list_view(admin_client, admin_user, django_assert_max_num_querie

def test_device_list_create(admin_client, django_assert_max_num_queries):
with override_settings(WAGTAIL_2FA_REQUIRED=True):
with django_assert_max_num_queries(10):
with django_assert_max_num_queries(14):
response = admin_client.get(reverse("wagtail_2fa_device_new"))
assert response.status_code == 200

Expand Down
Loading

0 comments on commit 1f0f8f0

Please sign in to comment.