Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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-waglatest
- py36-dj31-waglatest
- py38-dj22-wag27
- py38-dj22-waglatest
- py38-dj31-waglatest
include:
- toxenv: py36-dj22-wag27
python-version: 3.6
- toxenv: py36-dj22-waglatest
python-version: 3.6
- toxenv: py36-dj31-waglatest
python-version: 3.6
- toxenv: py38-dj22-wag27
python-version: 3.8
- toxenv: py38-dj22-waglatest
python-version: 3.8
- toxenv: py38-dj31-waglatest
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 }}
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

9 changes: 3 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -42,7 +39,7 @@ You can format code and imports by calling:

```
black wagtailsharing
isort --recursive wagtailsharing
isort wagtailsharing
Comment thread
tombola marked this conversation as resolved.
```

And you can check for style, import order, and other linting by using:
Expand Down
44 changes: 28 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.. image:: https://travis-ci.org/cfpb/wagtail-sharing.svg?branch=master
.. image:: https://github.com/cfpb/wagtail-sharing/workflows/test/badge.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
: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=master
:target: https://coveralls.io/github/cfpb/wagtail-sharing?branch=main

wagtail-sharing
===============
Expand All @@ -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
Expand All @@ -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
Expand All @@ -66,9 +66,9 @@ 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/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
Expand All @@ -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"
Expand All @@ -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 <http://docs.wagtail.io/en/latest/advanced_topics/customisation/admin_templates.html#customising-admin-templates>`_ are supported.
Expand All @@ -114,9 +114,21 @@ 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

To use tokens in place of the page path on the sharing site, add the following setting:

.. code-block:: python

WAGTAILSHARING_TOKENIZE_URL = True

Comment thread
tombola marked this conversation as resolved.
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
-----

Expand Down Expand Up @@ -162,16 +174,16 @@ 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 <https://github.com/cfpb/wagtail-sharing/issues/new>`_.

Open source licensing info
--------------------------

#. `TERMS <https://github.com/cfpb/cfgov-refresh/blob/master/TERMS.md>`_
#. `LICENSE <https://github.com/cfpb/cfgov-refresh/blob/master/LICENSE>`_
#. `TERMS <https://github.com/cfpb/cfgov-refresh/blob/main/TERMS.md>`_
#. `LICENSE <https://github.com/cfpb/cfgov-refresh/blob/main/LICENSE>`_
#. `CFPB Source Code Policy <https://github.com/cfpb/source-code-policy>`_
17 changes: 6 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@


install_requires = [
"wagtail>=2.3,<2.11",
]


testing_extras = [
"coverage>=3.7.0",
"flake8>=2.2.0",
"mock>=1.0.0",
"wagtail>=2.7,<3",
"pyjwt>1.7,<2.0",
]

testing_extras = ["coverage>=3.7.0"]

setup(
name="wagtail-sharing",
url="https://github.com/cfpb/wagtail-sharing",
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",
Expand Down
19 changes: 9 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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,latest}

[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

Expand All @@ -18,22 +19,20 @@ 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
wag210: wagtail>=2.10,<2.11
dj31: Django>=3.1,<3.2
wag27: wagtail>=2.7,<2.8
waglatest: wagtail<3

[testenv:lint]
recreate=False
basepython=python3.6
deps=
black
flake8
isort
commands=
black --check wagtailsharing setup.py
flake8 wagtailsharing
flake8 wagtailsharing setup.py
isort --check-only --diff wagtailsharing

[flake8]
Expand All @@ -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
20 changes: 20 additions & 0 deletions wagtailsharing/helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
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()
Expand All @@ -21,4 +38,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
Loading