From 80d840dd43bab5f8089abb52420a68b5b6f4c971 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Fri, 12 Jun 2020 13:13:40 -0500 Subject: [PATCH 1/5] set up the wagtail hook for pages --- joplin/base/wagtail_hooks.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/joplin/base/wagtail_hooks.py b/joplin/base/wagtail_hooks.py index 14e19cfde..21921c2e7 100644 --- a/joplin/base/wagtail_hooks.py +++ b/joplin/base/wagtail_hooks.py @@ -280,6 +280,13 @@ def register_link_handler(features): features.register_link_type(InternalLinkHandler) +@hooks.register("construct_page_chooser_queryset") +def filter_department_pages(pages, request): + print(request.user) + pages = pages.filter + return pages + + # By default all menu items are shown all the time. # This checks for permission and returns True if the item should be shown class PermissionMenuItem(MenuItem): From b4918cbc14a4431926c6c2a68404d55501f8abf0 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Fri, 12 Jun 2020 16:59:55 -0500 Subject: [PATCH 2/5] use explorable pages fn in wagtail hook --- joplin/base/views/joplin_search_views.py | 2 +- joplin/base/wagtail_hooks.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/joplin/base/views/joplin_search_views.py b/joplin/base/views/joplin_search_views.py index 9c0ab9a54..dcb8e4287 100644 --- a/joplin/base/views/joplin_search_views.py +++ b/joplin/base/views/joplin_search_views.py @@ -38,7 +38,7 @@ def dept_explorable_pages(user): if not user.is_active: return Page.objects.none() if user.is_superuser: - return Page.objects.all() # todo: check this, we don't want the home page returned + return Page.objects.all() user_perms = UserPagePermissionsProxy(user) explorable_pages = Page.objects.none() diff --git a/joplin/base/wagtail_hooks.py b/joplin/base/wagtail_hooks.py index 21921c2e7..bd5b9070b 100644 --- a/joplin/base/wagtail_hooks.py +++ b/joplin/base/wagtail_hooks.py @@ -15,6 +15,7 @@ import wagtail.admin.rich_text.editors.draftail.features as draftail_features from wagtail.admin.rich_text.converters.html_to_contentstate import BlockElementHandler +from base.views.joplin_search_views import dept_explorable_pages # Following this: https://docs.python.org/3/library/html.parser.html#examples @@ -282,8 +283,10 @@ def register_link_handler(features): @hooks.register("construct_page_chooser_queryset") def filter_department_pages(pages, request): - print(request.user) - pages = pages.filter + if request.user.is_superuser: + return pages + + pages = (pages & dept_explorable_pages(request.user)) return pages From 73d446399ca1832d557fb6406489d1938b97f2eb Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Mon, 15 Jun 2020 15:55:37 -0500 Subject: [PATCH 3/5] include location pages in the page pickers --- joplin/base/wagtail_hooks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/joplin/base/wagtail_hooks.py b/joplin/base/wagtail_hooks.py index bd5b9070b..ecb708688 100644 --- a/joplin/base/wagtail_hooks.py +++ b/joplin/base/wagtail_hooks.py @@ -286,7 +286,12 @@ def filter_department_pages(pages, request): if request.user.is_superuser: return pages - pages = (pages & dept_explorable_pages(request.user)) + # include all location pages, since should be accessible regardless of user's department + location_pages = pages.filter(content_type_id=47) + # We need the home_page in the pages for the richtext link. + # It needs to be a queryset in order to include it with the other querysets (i.e. can't be just the page) + home_page = pages.filter(id=3) + pages = ((pages & dept_explorable_pages(request.user)) | location_pages | home_page) return pages From ae94b145eb8c8ca9c1f7d29452b44a9ce852540e Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Tue, 16 Jun 2020 12:35:52 -0500 Subject: [PATCH 4/5] users can pick topics from any department --- joplin/base/wagtail_hooks.py | 3 +++ joplin/pages/form_container/models.py | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/joplin/base/wagtail_hooks.py b/joplin/base/wagtail_hooks.py index ecb708688..ebc2f52ad 100644 --- a/joplin/base/wagtail_hooks.py +++ b/joplin/base/wagtail_hooks.py @@ -285,6 +285,9 @@ def register_link_handler(features): def filter_department_pages(pages, request): if request.user.is_superuser: return pages + # if a user is allowed to add topics, they can select from any topic regardless of department + if request.GET['page_type'] == 'topic_page.topicpage': + return pages # include all location pages, since should be accessible regardless of user's department location_pages = pages.filter(content_type_id=47) diff --git a/joplin/pages/form_container/models.py b/joplin/pages/form_container/models.py index 710c6570b..6f6672347 100644 --- a/joplin/pages/form_container/models.py +++ b/joplin/pages/form_container/models.py @@ -1,13 +1,9 @@ from django.db import models -from modelcluster.fields import ParentalKey -from modelcluster.models import ClusterableModel -from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, PageChooserPanel +from wagtail.admin.edit_handlers import FieldPanel, InlinePanel from base.forms import FormContainerForm -from pages.base_page.models import JanisBasePage - from base.models.widgets import countMe, countMeTextArea from publish_preflight.requirements import FieldPublishRequirement, RelationPublishRequirement, ConditionalPublishRequirement, DepartmentPublishRequirement From aa65cc78f8641b6c36f44a469dceaf9cc7104af7 Mon Sep 17 00:00:00 2001 From: Chia Berry Date: Tue, 16 Jun 2020 16:41:45 -0500 Subject: [PATCH 5/5] documentation and some cleanup --- joplin/base/wagtail_hooks.py | 6 ++++-- joplin/pages/guide_page/models.py | 4 ---- joplin/pages/location_page/models.py | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/joplin/base/wagtail_hooks.py b/joplin/base/wagtail_hooks.py index ebc2f52ad..1d5812676 100644 --- a/joplin/base/wagtail_hooks.py +++ b/joplin/base/wagtail_hooks.py @@ -283,15 +283,17 @@ def register_link_handler(features): @hooks.register("construct_page_chooser_queryset") def filter_department_pages(pages, request): + # superusers / admins are not restricted by department if request.user.is_superuser: return pages # if a user is allowed to add topics, they can select from any topic regardless of department if request.GET['page_type'] == 'topic_page.topicpage': return pages + print(request.GET) - # include all location pages, since should be accessible regardless of user's department + # include all location pages, since they should be accessible regardless of user's department location_pages = pages.filter(content_type_id=47) - # We need the home_page in the pages for the richtext link. + # We need the home_page in the pages for the richtext links # It needs to be a queryset in order to include it with the other querysets (i.e. can't be just the page) home_page = pages.filter(id=3) pages = ((pages & dept_explorable_pages(request.user)) | location_pages | home_page) diff --git a/joplin/pages/guide_page/models.py b/joplin/pages/guide_page/models.py index a691a566b..e4ca306ad 100644 --- a/joplin/pages/guide_page/models.py +++ b/joplin/pages/guide_page/models.py @@ -1,8 +1,5 @@ from django.db import models -from modelcluster.fields import ParentalKey -from modelcluster.models import ClusterableModel - from wagtail.core.fields import StreamField from wagtail.core.blocks import StructBlock, PageChooserBlock, TextBlock, ListBlock from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, PageChooserPanel, StreamFieldPanel @@ -11,7 +8,6 @@ from base.forms import GuidePageForm -from pages.base_page.models import JanisBasePage from pages.information_page.models import InformationPage from pages.service_page.models import ServicePage from snippets.contact.models import Contact diff --git a/joplin/pages/location_page/models.py b/joplin/pages/location_page/models.py index f3d219e28..15b9719eb 100644 --- a/joplin/pages/location_page/models.py +++ b/joplin/pages/location_page/models.py @@ -199,7 +199,6 @@ def clean(self): panels = [ PageChooserPanel("related_service"), FieldPanel("hours_same_as_location"), - ]