0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Make UserPagesInWorkflowModerationPanel generic

This commit is contained in:
Sage Abdullah 2022-12-22 12:04:42 +00:00
parent e4dbd88810
commit 6e7394c90f
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217
2 changed files with 13 additions and 10 deletions

View File

@ -110,9 +110,9 @@ class PagesForModerationPanel(Component):
return context
class UserPagesInWorkflowModerationPanel(Component):
name = "user_pages_in_workflow_moderation"
template_name = "wagtailadmin/home/user_pages_in_workflow_moderation.html"
class UserObjectsInWorkflowModerationPanel(Component):
name = "user_objects_in_workflow_moderation"
template_name = "wagtailadmin/home/user_objects_in_workflow_moderation.html"
order = 210
def get_context_data(self, parent_context):
@ -126,16 +126,19 @@ class UserPagesInWorkflowModerationPanel(Component):
# Once the issue is resolved, the subquery can be removed and the
# filter can be changed to:
# Q(page__owner=request.user) | Q(requested_by=request.user)
owned_by_user = Subquery(
Page.objects.filter(
owner=request.user,
id=Cast(OuterRef("object_id"), output_field=IntegerField()),
).values_list(Cast("id", output_field=CharField()), flat=True)
pages_owned_by_user = Q(
base_content_type_id=get_default_page_content_type().id,
object_id__in=Subquery(
Page.objects.filter(
owner=request.user,
id=Cast(OuterRef("object_id"), output_field=IntegerField()),
).values_list(Cast("id", output_field=CharField()), flat=True)
),
)
# Find in progress workflow states which are either requested by the user or on pages owned by the user
context["workflow_states"] = (
WorkflowState.objects.active()
.filter(Q(object_id__in=owned_by_user) | Q(requested_by=request.user))
.filter(pages_owned_by_user | Q(requested_by=request.user))
.prefetch_related("content_object")
.select_related(
"current_task_state",
@ -294,7 +297,7 @@ class HomeView(WagtailAdminTemplateMixin, TemplateView):
UpgradeNotificationPanel(),
WorkflowPagesToModeratePanel(),
PagesForModerationPanel(),
UserPagesInWorkflowModerationPanel(),
UserObjectsInWorkflowModerationPanel(),
RecentEditsPanel(),
LockedPagesPanel(),
]