From a53fc23c782ad255b1a65f43771484834c092d72 Mon Sep 17 00:00:00 2001 From: Steve Jalim Date: Mon, 14 Oct 2024 11:02:06 +0100 Subject: [PATCH 1/2] Fix blow-up when adding a new page to the CMS --- wagtaildraftsharing/tests/test_wagtail_hooks.py | 5 +++++ wagtaildraftsharing/wagtail_hooks.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/wagtaildraftsharing/tests/test_wagtail_hooks.py b/wagtaildraftsharing/tests/test_wagtail_hooks.py index 55cd82a..3dbf0e0 100644 --- a/wagtaildraftsharing/tests/test_wagtail_hooks.py +++ b/wagtaildraftsharing/tests/test_wagtail_hooks.py @@ -76,3 +76,8 @@ def test_action_menu_hook__is_shown(self): mock_page.has_unpublished_changes = True self.assertTrue(menu_item.is_shown({"page": mock_page})) + + def test_action_menu_hook__is_shown__no_page_in_context(self): + menu_item = wagtail_hooks.DraftsharingPageActionMenuItem() + self.assertFalse(menu_item.is_shown({})) + self.assertFalse(menu_item.is_shown({"something_that_is_not_a_page": "here"})) diff --git a/wagtaildraftsharing/wagtail_hooks.py b/wagtaildraftsharing/wagtail_hooks.py index 4edebe0..e3c95ef 100644 --- a/wagtaildraftsharing/wagtail_hooks.py +++ b/wagtaildraftsharing/wagtail_hooks.py @@ -59,11 +59,12 @@ class DraftsharingPageActionMenuItem(ActionMenuItem): def get_context_data(self, parent_context): context_data = super().get_context_data(parent_context) + context_data["revision"] = context_data["page"].latest_revision return context_data def is_shown(self, context): - return context["page"].has_unpublished_changes + return "page" in context and context["page"].has_unpublished_changes @hooks.register("register_page_action_menu_item") From ad1be8fefe336064189d9753f2335d7795838eca Mon Sep 17 00:00:00 2001 From: Steve Jalim Date: Mon, 14 Oct 2024 11:02:37 +0100 Subject: [PATCH 2/2] Update pyproject.toml with new (mozmeao) version number and add self as a maintainer contact --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ba68459..da94b7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "wagtaildraftsharing" -version = "0.0.4" +version = "0.1.1" description = "Share wagtail drafts with private URLs." readme = "README.md" requires-python = ">=3.9" @@ -8,6 +8,9 @@ license = {text = "CC0"} authors = [ {name = "Shohan Dutta Roy", email = "shohanduttaroy99@gmail.com" } ] +maintainers = [ + {name = "Steve Jalim", email = "stevejalim@mozilla.com" } +] dependencies = [ "wagtail>=5.1", ]