Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

4203 Limit page picker pages to authors department #747

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion joplin/base/views/joplin_search_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions joplin/base/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -280,6 +281,25 @@ def register_link_handler(features):
features.register_link_type(InternalLinkHandler)


@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 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 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)
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):
Expand Down
6 changes: 1 addition & 5 deletions joplin/pages/form_container/models.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 0 additions & 4 deletions joplin/pages/guide_page/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion joplin/pages/location_page/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def clean(self):
panels = [
PageChooserPanel("related_service"),
FieldPanel("hours_same_as_location"),

]


Expand Down