Skip to content

Commit

Permalink
Merge pull request #1 from mozmeao/add-wagtail-6-support
Browse files Browse the repository at this point in the history
Add Wagtail 6 support + extra way to create a sharing link
  • Loading branch information
stevejalim authored Oct 9, 2024
2 parents 4bd7a70 + 99a2e7a commit 6349819
Show file tree
Hide file tree
Showing 22 changed files with 796 additions and 144 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "CI" # Note that this name appears in the README's badge
on:
push:
branches:
- main
workflow_dispatch:
pull_request:
# Placeholder for the future if this work gets accepted into the upstream repo
# release:
# types: [published]

jobs:
run-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.9'
- '3.10'
- '3.11'
- '3.12'

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .'[testing]'
- name: Test with tox
run: tox

# Placeholder for the future if this work gets accepted into the upstream repo
# release:
# name: Release to PyPI
# if: github.event_name == 'release' && github.event.action == 'published'
# needs:
# - run-tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v5
# with:
# python-version: 3.11
# - name: Install dependencies for package building only
# run: pip install build
# - name: Build package for upload to PyPI
# run: python -m build .
# - name: Upload the distribution to PyPI
# uses: pypa/[email protected]
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Thumbs.db
__pycache__/
*.py[cod]
.env
build/

# Django #
#################
Expand All @@ -59,6 +60,7 @@ __pycache__/
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
Expand Down
14 changes: 1 addition & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args: ["wagtaildraftsharing", "setup.py", "testmanage.py", "--line-length=79"]
exclude: migrations
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
rev: v0.6.9
hooks:
- id: ruff
exclude: migrations
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["wagtaildraftsharing"]
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Share [Wagtail](https://wagtail.io) drafts with private URLs.
``wagtaildraftsharing`` makes it easier to share Wagtail draft content for review by users who don't have access to the Wagtail admin site. It allows you to generate random urls to expose the revisions of your Wagtail pages.

## Setup

Install the package using pip:

```bash
Expand All @@ -23,10 +24,13 @@ INSTALLED_APPS = (
...
)
```

Since ``wagtaildraftsharing`` overrides one of the ``wagtail.admin`` templates, it must be listed before ``wagtail.admin`` in the ``INSTALLED_APPS`` list.

This package also makes use of ``wagtail.snippets``, so it must be included in your list of installed apps.

You must also have ``USE_TZ=True`` in your project settings to ensure expiry datetimes are all referencing the expected timezone - from Django 5, this defaults to ``True``, whereas previously it was ``False``.

Run migrations to create the required database tables:

```bash
Expand All @@ -46,18 +50,25 @@ urlpatterns += [

Each draft in the history page for any page (/admin/pages/\<id\>/history/) will now have an additional action - ``Copy external sharing url``. Clicking this will generate a random url (and copy it to the clipboard) that can be shared with anyone. The url will display the draft version of the page.

![Screenshot](https://raw.githubusercontent.com/KIRA009/wagtaildraftsharing/main/docs/images/history.png)
![Screenshot](docs/images/history.png)

All generated links can be viewed at ``/admin/wagtaildraftsharing/``.

![Screenshot](https://raw.githubusercontent.com/KIRA009/wagtaildraftsharing/main/docs/images/sharinglinks.png)
![Screenshot](docs/images/sharinglinks.png)

Each link can be edited to expire at a certain date, or to be disabled immediately.

![Screenshot](https://raw.githubusercontent.com/KIRA009/wagtaildraftsharing/main/docs/images/sharinglink.png)
![Screenshot](docs/images/sharinglink.png)

In addition, it you can also make a sharing link directly from the Action Menu at the bottom of a page being edited, as long as there is a
draft version saved since the last time the page was published

![Screenshot](docs/images/action_menu.png)

## Settings

The following settings can be added to your Django settings file:

### ``WAGTAILDRAFTSHARING_MAX_AGE``

The default expiry time for generated links, in seconds. Defaults to 1 week. Set it to a negative value to disable expiry.
Binary file added docs/images/action_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 17 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "wagtaildraftsharing"
version = "0.0.4"
description = "Share wagtail drafts with private URLs."
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = {text = "CC0"}
authors = [
{name = "Shohan Dutta Roy", email = "[email protected]" }
Expand All @@ -15,8 +15,10 @@ classifiers = [
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.1",
"Framework :: Wagtail",
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6",
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"License :: Public Domain",
"Programming Language :: Python",
Expand All @@ -26,7 +28,9 @@ classifiers = [
[project.optional-dependencies]
testing = [
"coverage[toml]",
"tox",
"wagtail-factories",
"freezegun==1.5.1",
]

[project.urls]
Expand All @@ -44,42 +48,6 @@ inventory = [
"static/wagtaildraftsharing/*",
]

[tool.black]
line-length = 79
target-version = ["py38"]
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs
| \.git
| \.tox
| \*.egg-info
| _build
| build
| dist
| migrations
)/
)
'''

[tool.isort]
profile = "black"
line_length = 79
lines_after_imports = 2
skip = [".tox", "migrations", ".venv", "venv"]
known_django = ["django"]
known_wagtail = ["wagtail"]
default_section = "THIRDPARTY"
sections = [
"STDLIB",
"DJANGO",
"WAGTAIL",
"THIRDPARTY",
"FIRSTPARTY",
"LOCALFOLDER"
]

[tool.ruff]
exclude = [
".git",
Expand All @@ -90,13 +58,25 @@ exclude = [
".venv",
"venv",
]


[tool.ruff.lint]
ignore = []
select = [
"E",
"F",
"W",
]

[tool.ruff.lint.isort]
section-order = [
"future",
"standard-library",
"third-party",
"first-party",
"local-folder",
]

[tool.coverage.run]
omit = [
"wagtaildraftsharing/tests/*",
Expand Down
49 changes: 27 additions & 22 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,53 @@
skipsdist=True
envlist=
lint,
python{3.8,3.11}-django{3.2,4.2}-wagtail{5.1,5.2},
python{3.9,3.10,3.11,3.12}-django{3.2,4.2,5.1}-wagtail{5.1,5.2,6.1,6.2},
coverage

[testenv]
install_command=pip install -e ".[testing]" -U {opts} {packages}

commands=
python -b -m coverage run --parallel-mode --source='wagtaildraftsharing' {toxinidir}/testmanage.py test {posargs}

passenv = PYTHONBREAKPOINT

basepython=
python3.8: python3.8
python3.9: python3.9
python3.10: python3.10
python3.11: python3.11
python3.12: python3.12

deps=
wagtail5.1: wagtail>=5.1,<5.2
wagtail5.2: wagtail>=5.2,<5.3
wagtail6.1: wagtail>=6.1,<6.2
wagtail6.2: wagtail>=6.2,<6.3

[testenv:python3.12-django3.2-wagtail6.1]
# This permutation is not a valid install, but let's tolerate it
allowlist_externals=python # take the system python to just get tox running for this combo

[testenv:lint]
basepython=python3.8
basepython=python3.11
deps=
black
ruff
isort
commands=
black --check wagtaildraftsharing setup.py testmanage.py
ruff wagtaildraftsharing testmanage.py
isort --check-only --diff wagtaildraftsharing testmanage.py
ruff check wagtaildraftsharing testmanage.py

[testenv:coverage]
basepython=python3.8
basepython=python3.11
deps=
coverage[toml]
wagtail-factories
freezegun==1.5.1
commands=
coverage combine
coverage report -m
coverage xml

[isort]
combine_as_imports=1
lines_after_imports=2
include_trailing_comma=1
multi_line_output=3
skip=.tox,migrations
use_parentheses=1
known_django=django
known_wagtail=wagtail
default_section=THIRDPARTY
sections=FUTURE,STDLIB,DJANGO,WAGTAIL,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

[testenv:interactive]
basepython=python3.8
basepython=python3.11
deps=
wagtail>=5.2,<5.3

Expand All @@ -66,3 +62,12 @@ commands=

setenv=
INTERACTIVE=1

[gh-actions]
# Running tox in GHA without redefining it all in a GHA matrix:
# https://github.com/ymyzk/tox-gh-actions
python =
3.9: python3.9
3.10: python3.10
3.11: python3.11
3.12: python3.12
10 changes: 4 additions & 6 deletions wagtaildraftsharing/actions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from django.utils.translation import gettext_lazy as _

from wagtail.log_actions import LogFormatter


WAGTAILDRAFTSHARING_CREATE_SHARING_LINK = (
"wagtaildraftsharing.create_sharing_link"
)
WAGTAILDRAFTSHARING_CREATE_SHARING_LINK = "wagtaildraftsharing.create_sharing_link"


def register_wagtaildraftsharing_log_actions(actions):
Expand All @@ -14,7 +10,9 @@ class CreateSharingLink(LogFormatter):
label = _("Create sharing link")

def format_message(self, log_entry):
return _("Created sharing link for revision {revision_id}").format(
return _(
"{username} created sharing link for revision {revision_id}"
).format(
revision_id=log_entry.data["revision"],
username=log_entry.user,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.16 on 2024-10-01 14:32

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("wagtaildraftsharing", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="wagtaildraftsharinglink",
name="created_by",
field=models.ForeignKey(
blank=True,
editable=False,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
]
Loading

0 comments on commit 6349819

Please sign in to comment.