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

Support Wagtail 6 + add sharing link to Action Menu + more #3

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 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
6349819
Merge pull request #1 from mozmeao/add-wagtail-6-support
stevejalim Oct 9, 2024
a53fc23
Fix blow-up when adding a new page to the CMS
stevejalim Oct 14, 2024
ad1be8f
Update pyproject.toml with new (mozmeao) version number and add self …
stevejalim Oct 14, 2024
ae9034c
Merge pull request #2 from mozmeao/15291--hotfix--page-creation-blocked
stevejalim Oct 14, 2024
8e7a3bb
Standardise settings prefix to be WAGTAILDRAFTSHARING_* and update RE…
stevejalim Nov 2, 2024
f4659c8
Bump mozmeao version
stevejalim Nov 2, 2024
2a4b004
Merge pull request #3 from mozmeao/amend-settings-naming
stevejalim Nov 2, 2024
10c52fe
Small refactor to move the link generation out of the view, to make i…
stevejalim Nov 13, 2024
d234ec9
Bump mozmeao version to 0.1.3
stevejalim Nov 13, 2024
d829af8
Merge pull request #4 from mozmeao/refactor-link-generation-to-be-a-p…
stevejalim Nov 13, 2024
488291d
Refactor settings to be a dict
stevejalim Nov 29, 2024
3698592
Allow the max age of a sharing link to be set via method arguments, n…
stevejalim Dec 3, 2024
75ea3ca
Rename max_age to max_ttl, ahead of adding min_ttl
stevejalim Dec 4, 2024
13e1b2c
Also rename MAX_AGE setting to MAX_TTL to match max_tt method argument
stevejalim Dec 4, 2024
cfc9160
Fix erroneous test names
stevejalim Dec 4, 2024
b828cbb
Support making a new sharing link each time, not reusing an existing one
stevejalim Dec 4, 2024
4c60d70
Increase default link TTL to 28 days
stevejalim Dec 4, 2024
33ba471
Add extra audit logging to show when we're reusing an existing link v…
stevejalim Dec 4, 2024
c17d3cd
Prep 0.2.0 release
stevejalim Dec 4, 2024
ae030bf
Update documentation
stevejalim Dec 4, 2024
768b989
Merge pull request #7 from mozmeao/5-customisable-max-age
stevejalim Dec 4, 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"]
52 changes: 46 additions & 6 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,54 @@ 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.
The following settings can be added to your Django settings file as keys in a `WAGTAILDRAFTSHARING` dictionary

```
WAGTAILDRAFTSHARING = {
...
"MAX_TTL": 123456,
...
}
```

### ``MAX_TTL``

The default expiry time for generated links, in seconds. Defaults to 28 days. Set it to a negative value to disable expiry.

### ```ADMIN_MENU_POSITION```

Set the integer priority to control where in the admin menu
the link to the list of generated links sits. Defaults to 200.

### ```VERBOSE_NAME```

Provide a different singular label for a link. Defaults to "Draftsharing Link"

### ```VERBOSE_NAME_PLURAL```

Provide a different plural label for a link. Defaults to "Draftsharing Links"

### ```MENU_ITEM_LABEL```

Customise the label used in the page-level Action Menu for creating a link. Defaults to "Create draft sharing link",

## Testing

To install testing dependencies locally run `pip install -e ".[testing]"`
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.
59 changes: 21 additions & 38 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
[project]
name = "wagtaildraftsharing"
version = "0.0.4"
version = "0.2.0"
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]" }
]
maintainers = [
{name = "Steve Jalim", email = "[email protected]" }
]
dependencies = [
"wagtail>=5.1",
]
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 +31,9 @@ classifiers = [
[project.optional-dependencies]
testing = [
"coverage[toml]",
"tox",
"wagtail-factories",
"freezegun==1.5.1",
]

[project.urls]
Expand All @@ -44,42 +51,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 +61,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
Loading