Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wagtail 6 support + extra way to create a sharing link #1

Merged
merged 29 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f933896
Add missing migration for change to 'editable' attr of created_by field
stevejalim Oct 1, 2024
4b1af63
Make draftsharing menu position customisable
stevejalim Sep 23, 2024
819fffa
Change menu icon
stevejalim Sep 23, 2024
f075a9d
Make draftsharing verbose names customisable
stevejalim Sep 23, 2024
c22b58b
Support current draftsharing behaviour in Wagtail 6
stevejalim Oct 1, 2024
49af612
Add an option in the main Page menu to create a draftsharing link
stevejalim Oct 1, 2024
5619783
Update README with new screenshot + make links relative
stevejalim Oct 1, 2024
7b1a34a
Expand test coverage for SharingLinkView
stevejalim Oct 1, 2024
003f678
Expand test coverage around expiry of links and setting expiry time d…
stevejalim Oct 2, 2024
c133b19
Move link expiry setting into app-level settings
stevejalim Oct 2, 2024
6c8bf77
Expand test coverage: access to view to create a sharing link
stevejalim Oct 2, 2024
6d395e8
Expand view test to 100% coverage
stevejalim Oct 2, 2024
ff0b469
Refactor view tests to split into focused TestCases now that we have …
stevejalim Oct 2, 2024
127802d
Rename snippet class to improve code comprehension a tiny bit
stevejalim Oct 2, 2024
d4381d8
Add tests for model methods
stevejalim Oct 2, 2024
9f1ffa6
Naming and formatting tweaks
stevejalim Oct 7, 2024
9e9e444
Add comments to help understanding
stevejalim Oct 7, 2024
cf7dfa3
Expand model test coverage to 100%; fixup test regression due to code…
stevejalim Oct 7, 2024
3172d68
Add tests for wagtail_hooks
stevejalim Oct 7, 2024
828b0f1
Update gitignore to skip build artifacts and coverage reports
stevejalim Oct 7, 2024
897adee
Address outlier case where, with Wagtail 5.1, the active_until field …
stevejalim Oct 7, 2024
b677cb9
Update tox to cover more versions of Python, Wagtail and Django
stevejalim Oct 7, 2024
33035b9
Fix unused import
stevejalim Oct 7, 2024
8cbe7bc
Switch to only using ruff, not black + isort + ruff
stevejalim Oct 7, 2024
56f5db0
Formatting fixups with ruff (only)
stevejalim Oct 7, 2024
d61c5bb
Remove redundant isort config
stevejalim Oct 7, 2024
bf09190
Add GHA for CI; drop 3.8 support
stevejalim Oct 7, 2024
91f78be
Stabilise tests across Python 3.9 and/or Wagtail 5.1 by enforcing UTC…
stevejalim Oct 8, 2024
99a2e7a
Update ruff config with known sort order
stevejalim Oct 8, 2024
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
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"]
15 changes: 12 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,6 +24,7 @@ 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.
Expand All @@ -46,18 +48,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.
44 changes: 7 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"
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you get rid of this you'll want to make sure ruff has the appropriate config for sorting imports, e.g. lint.isort.known-first-party, lint.isort.section-order, and/or lint.isort.sections.django.


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

[lint]
ignore = []
select = [
"E",
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
Loading