From 031582f865d62e44cb435f2d284513679febfd24 Mon Sep 17 00:00:00 2001 From: Craig Davies <30801483+cwdavies@users.noreply.github.com> Date: Fri, 21 Aug 2020 12:49:04 -0400 Subject: [PATCH 1/9] Support LTS + Current versions of Wagtail and Django (#39) * Add support for Django 3.1 * Add coveralls badge to the README * Remove dependency on external mock package and use unittest.mock --- .github/workflows/test.yml | 74 ++++++++++++++++++++++ .travis.yml | 28 -------- README.rst | 24 +++---- setup.py | 17 ++--- tox.ini | 17 +++-- wagtailsharing/tests/test_urls.py | 9 +-- wagtailsharing/tests/test_views.py | 3 +- wagtailsharing/tests/test_wagtail_hooks.py | 3 +- 8 files changed, 105 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4293605 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,74 @@ +name: test + +on: [pull_request, push] + +jobs: + + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + + - name: Run tox -e lint + run: tox + env: + TOXENV: lint + + test: + name: unittests + runs-on: ubuntu-latest + + strategy: + matrix: + toxenv: + - py36-dj22-wag27 + - py36-dj22-wag210 + - py36-dj31-wag210 + - py38-dj22-wag27 + - py38-dj22-wag210 + - py38-dj31-wag210 + include: + - toxenv: py36-dj22-wag27 + python-version: 3.6 + - toxenv: py36-dj22-wag210 + python-version: 3.6 + - toxenv: py36-dj31-wag210 + python-version: 3.6 + - toxenv: py38-dj22-wag27 + python-version: 3.8 + - toxenv: py38-dj22-wag210 + python-version: 3.8 + - toxenv: py38-dj31-wag210 + python-version: 3.8 + + steps: + - uses: actions/checkout@v1 + + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox coveralls + + - name: Run tox + run: | + tox + coveralls + env: + TOXENV: ${{ matrix.toxenv }} + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9698f07..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: python -cache: pip - -matrix: - include: - - env: TOXENV=lint - python: 3.6 - - env: TOXENV=py36-dj111-wag23 - python: 3.6 - - env: TOXENV=py36-dj22-wag23 - python: 3.6 - - env: TOXENV=py36-dj22-wag29 - python: 3.6 - - env: TOXENV=py38-dj22-wag29 - python: 3.8 - - env: TOXENV=py36-dj22-wag210 - python: 3.6 - - env: TOXENV=py38-dj22-wag210 - python: 3.8 - -install: - pip install tox coveralls - -script: - tox - -after_success: - coveralls diff --git a/README.rst b/README.rst index a82f5d3..8d2b444 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,9 @@ -.. image:: https://travis-ci.org/cfpb/wagtail-sharing.svg?branch=master +.. image:: https://travis-ci.org/cfpb/wagtail-sharing.svg?branch=main :alt: Build Status :target: https://travis-ci.org/cfpb/wagtail-sharing -.. image:: https://coveralls.io/repos/github/cfpb/wagtail-sharing/badge.svg?branch=master +.. image:: https://coveralls.io/repos/github/cfpb/wagtail-sharing/badge.svg?branch=main :alt: Coverage Status - :target: https://coveralls.io/github/cfpb/wagtail-sharing?branch=master + :target: https://coveralls.io/github/cfpb/wagtail-sharing?branch=main wagtail-sharing =============== @@ -68,7 +68,7 @@ Sharing sites The Wagtail admin now contains a new section under Settings called Sharing Sites that allows users to define how they would like to expose latest page revisions. -.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/master/docs/images/sharing-sites.png +.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/main/docs/images/sharing-sites.png :width: 200px :height: 100px :alt: Sharing sites @@ -90,7 +90,7 @@ Verify that you can access your local server at http://sharing.localhost:8000. Y To do so, in the Wagtail admin, under Settings, Sharing Sites, create a new sharing site for the default site, with hostname ``sharing.localhost`` and port ``8000``. -.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/master/docs/images/new-sharing-site.png +.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/main/docs/images/new-sharing-site.png :width: 200px :height: 100px :alt: New sharing site with site: "localhost [default]", hostname: "sharing.localhost", port: "8000" @@ -102,7 +102,7 @@ Banners Pages viewed on a wagtail-sharing shared site have a simple banner added to them to remind reviewers that the current published content may differ from the content they are viewing. -.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/master/docs/images/banner.png +.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/main/docs/images/banner.png :alt: Banner This behavior can be disabled by setting ``settings.WAGTAILSHARING_BANNER = False``. The banner template can be overridden by providing an alternate template file at ``wagtailsharing/banner.html`` similar to how `wagtailadmin template overrides `_ are supported. @@ -114,7 +114,7 @@ A page's sharing URL can be retrieved by passing its ``Page`` instance to ``wagt Shared pages will also have a new dropdown menu option that links to this sharing URL from the Wagtail page explorer. -.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/master/docs/images/dropdown.png +.. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/main/docs/images/dropdown.png :alt: Dropdown with sharing link Hooks @@ -162,9 +162,9 @@ Compatibility This project has been tested for compatibility with: -* Python 3.6, 3.8 -* Django 1.11, 2.2 -* Wagtail 2.3, 2.9, 2.10 +* Python 3.6+ +* Django 2.2 (LTS), 3.1 (current) +* Wagtail 2.7 (LTS), 2.10 (current) It should be compatible with all intermediate versions, as well. If you find that it is not, please `file an issue `_. @@ -172,6 +172,6 @@ If you find that it is not, please `file an issue `_ -#. `LICENSE `_ +#. `TERMS `_ +#. `LICENSE `_ #. `CFPB Source Code Policy `_ diff --git a/setup.py b/setup.py index f8846d8..f4c7b10 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,10 @@ from setuptools import find_packages, setup - install_requires = [ - "wagtail>=2.3,<2.11", -] - - -testing_extras = [ - "coverage>=3.7.0", - "flake8>=2.2.0", - "mock>=1.0.0", + "wagtail>=2.7,<2.11", ] +testing_extras = ["coverage>=3.7.0"] setup( name="wagtail-sharing", @@ -19,18 +12,18 @@ author="CFPB", author_email="tech@cfpb.gov", license="CCO", - version="2.2.1", + version="2.3.0", include_package_data=True, packages=find_packages(), python_requires=">=3.6", install_requires=install_requires, extras_require={"testing": testing_extras}, description="Easier sharing of Wagtail drafts", - long_description=open("README.rst").read(), + long_description=open("README.rst", "r", encoding="utf-8").read(), classifiers=[ "Framework :: Django", - "Framework :: Django :: 1.11", "Framework :: Django :: 2.2", + "Framework :: Django :: 3.1", "Framework :: Wagtail", "Framework :: Wagtail :: 2", "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", diff --git a/tox.ini b/tox.ini index cf65862..6b093ce 100644 --- a/tox.ini +++ b/tox.ini @@ -2,13 +2,14 @@ skipsdist=True envlist= lint, - py{36}-dj{111,22}-wag{23}, - py{36,38}-dj{22}-wag{29,210} + py{36,38}-dj{22,31}-wag{27,210} [testenv] install_command=pip install -e ".[testing]" -U {opts} {packages} commands= + coverage erase coverage run {envbindir}/django-admin.py test {posargs} + coverage report -m setenv= DJANGO_SETTINGS_MODULE=wagtailsharing.tests.settings @@ -18,14 +19,12 @@ basepython= deps= mock>=1.0.0 - dj111: Django>=1.11,<1.12 dj22: Django>=2.2,<2.3 - wag23: wagtail>=2.3,<2.4 - wag29: wagtail>=2.9,<2.10 + dj31: Django>=3.1,<3.2 + wag27: wagtail>=2.7,<2.8 wag210: wagtail>=2.10,<2.11 [testenv:lint] -recreate=False basepython=python3.6 deps= black @@ -33,7 +32,7 @@ deps= isort commands= black --check wagtailsharing setup.py - flake8 wagtailsharing + flake8 wagtailsharing setup.py isort --check-only --diff wagtailsharing [flake8] @@ -53,6 +52,6 @@ multi_line_output=3 skip=.tox,migrations use_parentheses=1 known_django=django -known_future_library=future +known_wagtail=wagtail default_section=THIRDPARTY -sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER +sections=FUTURE,STDLIB,DJANGO,WAGTAIL,THIRDPARTY,FIRSTPARTY,LOCALFOLDER diff --git a/wagtailsharing/tests/test_urls.py b/wagtailsharing/tests/test_urls.py index ca1a75c..ab94518 100644 --- a/wagtailsharing/tests/test_urls.py +++ b/wagtailsharing/tests/test_urls.py @@ -1,19 +1,14 @@ from importlib import reload +from unittest.mock import patch from django.test import TestCase +from django.urls import re_path -from mock import patch from wagtail.core import urls as wagtail_core_urls import wagtailsharing.urls -try: - from django.urls import re_path -except ImportError: - from django.conf.urls import url as re_path - - class TestUrlPatterns(TestCase): def setUp(self): def test_view(): diff --git a/wagtailsharing/tests/test_views.py b/wagtailsharing/tests/test_views.py index 58daba2..68a07bb 100644 --- a/wagtailsharing/tests/test_views.py +++ b/wagtailsharing/tests/test_views.py @@ -1,8 +1,9 @@ +from unittest.mock import patch + from django.http import Http404, HttpResponse from django.test import RequestFactory, TestCase import wagtail -from mock import patch from wagtail.core.models import Site from wagtail.tests.utils import WagtailTestUtils diff --git a/wagtailsharing/tests/test_wagtail_hooks.py b/wagtailsharing/tests/test_wagtail_hooks.py index 8531042..819d7b1 100644 --- a/wagtailsharing/tests/test_wagtail_hooks.py +++ b/wagtailsharing/tests/test_wagtail_hooks.py @@ -2,9 +2,10 @@ from django.http import HttpResponse from django.test import TestCase, override_settings -from mock import Mock, patch from wagtail.tests.testapp.models import SimplePage +from mock import Mock, patch + from wagtailsharing.wagtail_hooks import add_sharing_banner, add_sharing_link From e3421fcf9d9929080a0d73b26af3416f48471d1a Mon Sep 17 00:00:00 2001 From: Alex Martin Date: Mon, 24 Aug 2020 12:05:23 -0400 Subject: [PATCH 2/9] Swap Travis Badge for Github Action Badge (#40) --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 8d2b444..08dbe82 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,6 @@ -.. image:: https://travis-ci.org/cfpb/wagtail-sharing.svg?branch=main +.. image:: https://github.com/cfpb/wagtail-sharing/workflows/test/badge.svg?branch=main :alt: Build Status - :target: https://travis-ci.org/cfpb/wagtail-sharing + :target: https://github.com/cfpb/wagtail-sharing/actions?query=branch%3Amain+workflow%3Atest+ .. image:: https://coveralls.io/repos/github/cfpb/wagtail-sharing/badge.svg?branch=main :alt: Coverage Status :target: https://coveralls.io/github/cfpb/wagtail-sharing?branch=main From 792cb77b11661ab3faff70d31804fb81c144c9cf Mon Sep 17 00:00:00 2001 From: Craig Davies <30801483+cwdavies@users.noreply.github.com> Date: Thu, 3 Dec 2020 11:39:27 -0500 Subject: [PATCH 3/9] Change maximum wagtail compatible version to 3 (#41) * Use waglatest in GitHub action and in tox --- .github/workflows/test.yml | 16 ++++++++-------- setup.py | 2 +- tox.ini | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4293605..02ea720 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,23 +33,23 @@ jobs: matrix: toxenv: - py36-dj22-wag27 - - py36-dj22-wag210 - - py36-dj31-wag210 + - py36-dj22-waglatest + - py36-dj31-waglatest - py38-dj22-wag27 - - py38-dj22-wag210 - - py38-dj31-wag210 + - py38-dj22-waglatest + - py38-dj31-waglatest include: - toxenv: py36-dj22-wag27 python-version: 3.6 - - toxenv: py36-dj22-wag210 + - toxenv: py36-dj22-waglatest python-version: 3.6 - - toxenv: py36-dj31-wag210 + - toxenv: py36-dj31-waglatest python-version: 3.6 - toxenv: py38-dj22-wag27 python-version: 3.8 - - toxenv: py38-dj22-wag210 + - toxenv: py38-dj22-waglatest python-version: 3.8 - - toxenv: py38-dj31-wag210 + - toxenv: py38-dj31-waglatest python-version: 3.8 steps: diff --git a/setup.py b/setup.py index f4c7b10..9537962 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import find_packages, setup install_requires = [ - "wagtail>=2.7,<2.11", + "wagtail>=2.7,<3", ] testing_extras = ["coverage>=3.7.0"] diff --git a/tox.ini b/tox.ini index 6b093ce..dcef9ff 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ skipsdist=True envlist= lint, - py{36,38}-dj{22,31}-wag{27,210} + py{36,38}-dj{22,31}-wag{27,latest} [testenv] install_command=pip install -e ".[testing]" -U {opts} {packages} @@ -22,7 +22,7 @@ deps= dj22: Django>=2.2,<2.3 dj31: Django>=3.1,<3.2 wag27: wagtail>=2.7,<2.8 - wag210: wagtail>=2.10,<2.11 + waglatest: wagtail<3 [testenv:lint] basepython=python3.6 From d62809054666e4f1216ff5b19a18361bf991e85e Mon Sep 17 00:00:00 2001 From: Tom Readings Date: Thu, 30 Jul 2020 15:10:17 +0100 Subject: [PATCH 4/9] Add token based URL to share site --- setup.py | 2 ++ wagtailsharing/urls.py | 27 +++++++++++++++++++-------- wagtailsharing/views.py | 10 +++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 9537962..6cd4141 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,9 @@ from setuptools import find_packages, setup + install_requires = [ "wagtail>=2.7,<3", + "pyjwt>1.7,<2.0", ] testing_extras = ["coverage>=3.7.0"] diff --git a/wagtailsharing/urls.py b/wagtailsharing/urls.py index 07bddf6..be64e64 100644 --- a/wagtailsharing/urls.py +++ b/wagtailsharing/urls.py @@ -1,9 +1,11 @@ +from django.conf import settings +from django.conf.urls import url + from wagtail.core.urls import ( serve_pattern, urlpatterns as wagtailcore_urlpatterns, ) - -from wagtailsharing.views import ServeView +from wagtailsharing.views import ServeView, TokenServeView try: @@ -12,9 +14,18 @@ from django.conf.urls import url as re_path -urlpatterns = [ - re_path(serve_pattern, ServeView.as_view(), name="wagtail_serve") - if urlpattern.name == "wagtail_serve" - else urlpattern - for urlpattern in wagtailcore_urlpatterns -] +if getattr(settings, "WAGTAILSHARING_TOKENIZE_URL", True): + urlpatterns = [ + url( + r"^share/([\w\.\-\_]+)/$", + TokenServeView.as_view(), + name="wagtail_serve", + ), + ] +else: + urlpatterns = [ + re_path(serve_pattern, ServeView.as_view(), name="wagtail_serve") + if urlpattern.name == "wagtail_serve" + else urlpattern + for urlpattern in wagtailcore_urlpatterns + ] diff --git a/wagtailsharing/views.py b/wagtailsharing/views.py index 1d5a4be..bd90e8e 100644 --- a/wagtailsharing/views.py +++ b/wagtailsharing/views.py @@ -1,13 +1,14 @@ import inspect +from django.conf import settings from django.http import Http404, HttpResponse from django.views.generic import View +import jwt from wagtail.contrib.routable_page.models import RoutablePageMixin from wagtail.core import hooks from wagtail.core.url_routing import RouteResult from wagtail.core.views import serve as wagtail_serve - from wagtailsharing.models import SharingSite @@ -99,3 +100,10 @@ def serve(page, request, args, kwargs): return result return response + + +class TokenServeView(ServeView): + def dispatch(self, request, path): + from pudb import set_trace + + set_trace() From 69b99be91f00f79de03487c593094c0d01fd57ec Mon Sep 17 00:00:00 2001 From: Tom Readings Date: Thu, 30 Jul 2020 16:36:02 +0100 Subject: [PATCH 5/9] Generate token based sharing link in wagtail admin --- wagtailsharing/helpers.py | 21 +++++++++++++++++++- wagtailsharing/urls.py | 7 ++++--- wagtailsharing/views.py | 35 +++++++++++++++++++++++++++------ wagtailsharing/wagtail_hooks.py | 1 - 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/wagtailsharing/helpers.py b/wagtailsharing/helpers.py index 582db55..9a8af81 100644 --- a/wagtailsharing/helpers.py +++ b/wagtailsharing/helpers.py @@ -1,8 +1,24 @@ -from wagtail.core.models import Site +from django.conf import settings +import jwt +from wagtail.core.models import Site from wagtailsharing.models import SharingSite +def get_tokenized_sharing_url(sharing_site, page_path): + share_path = getattr(settings, "WAGTAILSHARING_TOKEN_SHARE_PATH", "share") + payload = {"path": page_path} + return "/".join( + [ + sharing_site.root_url, + share_path, + jwt.encode(payload, settings.SECRET_KEY, algorithm="HS256").decode( + "utf-8" + ), + ] + ) + + def get_sharing_url(page): """Get a sharing URL for the latest revision of a page, if available.""" url_parts = page.get_url_parts() @@ -21,4 +37,7 @@ def get_sharing_url(page): # Site is not shared. return None + if getattr(settings, "WAGTAILSHARING_TOKENIZE_URL", False): + return get_tokenized_sharing_url(sharing_site, page_path) + return sharing_site.root_url + page_path diff --git a/wagtailsharing/urls.py b/wagtailsharing/urls.py index be64e64..51f9f78 100644 --- a/wagtailsharing/urls.py +++ b/wagtailsharing/urls.py @@ -14,10 +14,11 @@ from django.conf.urls import url as re_path -if getattr(settings, "WAGTAILSHARING_TOKENIZE_URL", True): - urlpatterns = [ +if getattr(settings, "WAGTAILSHARING_TOKENIZE_URL", False): + share_path = getattr(settings, "WAGTAILSHARING_TOKEN_SHARE_PATH", "share") + urlpatterns = wagtailcore_urlpatterns + [ url( - r"^share/([\w\.\-\_]+)/$", + rf"^{share_path}/([\w\.\-\_]+)/$", TokenServeView.as_view(), name="wagtail_serve", ), diff --git a/wagtailsharing/views.py b/wagtailsharing/views.py index bd90e8e..11c34c6 100644 --- a/wagtailsharing/views.py +++ b/wagtailsharing/views.py @@ -1,4 +1,5 @@ import inspect +import logging from django.conf import settings from django.http import Http404, HttpResponse @@ -13,15 +14,20 @@ class ServeView(View): - def dispatch(self, request, path): - if request.method.upper() != "GET": - return wagtail_serve(request, path) - + def get_sharing_site(self, request, path): try: sharing_site = SharingSite.find_for_request(request) except SharingSite.DoesNotExist: sharing_site = None + return sharing_site + + def dispatch(self, request, path): + if request.method.upper() != "GET": + return wagtail_serve(request, path) + + sharing_site = self.get_sharing_site(request, path) + if not sharing_site: return wagtail_serve(request, path) @@ -104,6 +110,23 @@ def serve(page, request, args, kwargs): class TokenServeView(ServeView): def dispatch(self, request, path): - from pudb import set_trace + sharing_site = self.get_sharing_site(request, path) - set_trace() + if not sharing_site: + return wagtail_serve(request, path) + + try: + # Get the wagtail path from the JWT token + data = jwt.decode(path, settings.SECRET_KEY, algorithms=["HS256"]) + decoded_path = data["path"] + except Exception as e: + logging.warn( + f"Could not decode wagtail path from sharing link: {e}" + ) + return wagtail_serve(request, path) + + page, args, kwargs = self.route( + sharing_site.site, request, decoded_path + ) + + return self.serve(page, request, args, kwargs) diff --git a/wagtailsharing/wagtail_hooks.py b/wagtailsharing/wagtail_hooks.py index bd439fd..72cc138 100644 --- a/wagtailsharing/wagtail_hooks.py +++ b/wagtailsharing/wagtail_hooks.py @@ -8,7 +8,6 @@ from wagtail.admin import widgets as wagtailadmin_widgets from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register from wagtail.core import hooks - from wagtailsharing.helpers import get_sharing_url from wagtailsharing.models import SharingSite From 397cb226bee51a237d7e10132f854779d7b19ed3 Mon Sep 17 00:00:00 2001 From: Tom Readings Date: Thu, 30 Jul 2020 17:07:20 +0100 Subject: [PATCH 6/9] Add token option to readme --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index 08dbe82..ca4dba1 100644 --- a/README.rst +++ b/README.rst @@ -117,6 +117,12 @@ Shared pages will also have a new dropdown menu option that links to this sharin .. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/main/docs/images/dropdown.png :alt: Dropdown with sharing link +To use tokens in place of the page path on the sharing site, add the following setting: + +.. code-block:: python + + WAGTAILSHARING_TOKENIZE_URL = True + Hooks ----- From 133c201047e2b5c8805c10a643ea283a61bbccb5 Mon Sep 17 00:00:00 2001 From: Tom Readings Date: Fri, 31 Jul 2020 10:28:22 +0100 Subject: [PATCH 7/9] Linting - sort imports --- CONTRIBUTING.md | 9 +++------ README.rst | 6 +++--- wagtailsharing/helpers.py | 1 + wagtailsharing/urls.py | 1 + wagtailsharing/views.py | 1 + wagtailsharing/wagtail_hooks.py | 1 + 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 590afb1..d6bd468 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,11 +5,10 @@ > feature request, you are agreeing to comply with this waiver of copyright interest. > Details can be found in our [TERMS](TERMS.md) and [LICENCE](LICENSE). - There are two primary ways to help: - - Using the issue tracker, and - - Changing the code-base. +- Using the issue tracker, and +- Changing the code-base. ## Using the issue tracker @@ -21,7 +20,6 @@ Use the issue tracker to find ways to contribute. Find a bug or a feature, menti the issue that you will take on that effort, then follow the _Changing the code-base_ guidance below. - ## Changing the code-base Generally speaking, you should fork this repository, make changes in your @@ -31,7 +29,6 @@ Additionally, the code should follow any stylistic and architectural guidelines prescribed by the project. In the absence of such guidelines, mimic the styles and patterns in the existing code-base. - ## Style This project uses [`black`](https://github.com/psf/black) to format code, @@ -42,7 +39,7 @@ You can format code and imports by calling: ``` black wagtailsharing -isort --recursive wagtailsharing +isort wagtailsharing ``` And you can check for style, import order, and other linting by using: diff --git a/README.rst b/README.rst index ca4dba1..cfe0028 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ Install the package using pip: .. code-block:: bash $ pip install wagtail-sharing - + Add ``wagtailsharing`` as an installed app in your Django settings: .. code-block:: python @@ -49,7 +49,7 @@ Run migrations to create required database tables: .. code-block:: bash $ manage.py migrate wagtailsharing - + Replace use of Wagtail's catch-all URL pattern: .. code-block:: diff @@ -66,7 +66,7 @@ Replace use of Wagtail's catch-all URL pattern: Sharing sites ------------- -The Wagtail admin now contains a new section under Settings called Sharing Sites that allows users to define how they would like to expose latest page revisions. +The Wagtail admin now contains a new section under Settings called Sharing Sites that allows users to define how they would like to expose latest page revisions. .. image:: https://raw.githubusercontent.com/cfpb/wagtail-sharing/main/docs/images/sharing-sites.png :width: 200px diff --git a/wagtailsharing/helpers.py b/wagtailsharing/helpers.py index 9a8af81..9aa4448 100644 --- a/wagtailsharing/helpers.py +++ b/wagtailsharing/helpers.py @@ -2,6 +2,7 @@ import jwt from wagtail.core.models import Site + from wagtailsharing.models import SharingSite diff --git a/wagtailsharing/urls.py b/wagtailsharing/urls.py index 51f9f78..833f47f 100644 --- a/wagtailsharing/urls.py +++ b/wagtailsharing/urls.py @@ -5,6 +5,7 @@ serve_pattern, urlpatterns as wagtailcore_urlpatterns, ) + from wagtailsharing.views import ServeView, TokenServeView diff --git a/wagtailsharing/views.py b/wagtailsharing/views.py index 11c34c6..0bd386c 100644 --- a/wagtailsharing/views.py +++ b/wagtailsharing/views.py @@ -10,6 +10,7 @@ from wagtail.core import hooks from wagtail.core.url_routing import RouteResult from wagtail.core.views import serve as wagtail_serve + from wagtailsharing.models import SharingSite diff --git a/wagtailsharing/wagtail_hooks.py b/wagtailsharing/wagtail_hooks.py index 72cc138..bd439fd 100644 --- a/wagtailsharing/wagtail_hooks.py +++ b/wagtailsharing/wagtail_hooks.py @@ -8,6 +8,7 @@ from wagtail.admin import widgets as wagtailadmin_widgets from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register from wagtail.core import hooks + from wagtailsharing.helpers import get_sharing_url from wagtailsharing.models import SharingSite From abdc53ddd26e12ff86b5bb18ed9c88d71f9cf6a6 Mon Sep 17 00:00:00 2001 From: Tom Readings Date: Thu, 6 Aug 2020 17:59:11 +0100 Subject: [PATCH 8/9] Add note re heroku and ports --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index cfe0028..b5f031f 100644 --- a/README.rst +++ b/README.rst @@ -123,6 +123,12 @@ To use tokens in place of the page path on the sharing site, add the following s WAGTAILSHARING_TOKENIZE_URL = True +In some environments such as Heroku, SERVER_PORT set at release time and the real port is fowarded, so the following is needed in settings: + +.. code-block:: python + + USE_X_FORWARDED_PORT = True + Hooks ----- From e5a1bacbb632c35d07e538a33710ef0599942df4 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 7 Aug 2020 10:18:46 +0100 Subject: [PATCH 9/9] Only react to GET requests --- wagtailsharing/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wagtailsharing/views.py b/wagtailsharing/views.py index 0bd386c..cda6ab4 100644 --- a/wagtailsharing/views.py +++ b/wagtailsharing/views.py @@ -111,6 +111,9 @@ def serve(page, request, args, kwargs): class TokenServeView(ServeView): def dispatch(self, request, path): + if request.method.upper() != "GET": + return wagtail_serve(request, path) + sharing_site = self.get_sharing_site(request, path) if not sharing_site: @@ -122,7 +125,7 @@ def dispatch(self, request, path): decoded_path = data["path"] except Exception as e: logging.warn( - f"Could not decode wagtail path from sharing link: {e}" + f"Could not decode Wagtail path from sharing link: {e}" ) return wagtail_serve(request, path)