diff --git a/core/systems/assignment/_public.ex b/core/systems/assignment/_public.ex index eb04d2750..35520a12e 100644 --- a/core/systems/assignment/_public.ex +++ b/core/systems/assignment/_public.ex @@ -37,6 +37,12 @@ defmodule Systems.Assignment.Public do |> Repo.get(id) end + def get_by_content_page(%Content.PageModel{} = page, preload \\ []) do + assignment_query(page) + |> Repo.one() + |> Repo.preload(preload) + end + def get_workflow!(id, preload \\ []) do from(a in Workflow.Model, preload: ^preload) |> Repo.get!(id) diff --git a/core/systems/assignment/_queries.ex b/core/systems/assignment/_queries.ex index afb4c8513..a103bab00 100644 --- a/core/systems/assignment/_queries.ex +++ b/core/systems/assignment/_queries.ex @@ -7,6 +7,7 @@ defmodule Systems.Assignment.Queries do alias Systems.Assignment alias Systems.Account + alias Systems.Content alias Systems.Project def assignment_query() do @@ -19,6 +20,16 @@ defmodule Systems.Assignment.Queries do ]) end + def assignment_query(%Content.PageModel{id: page_id}) do + build(assignment_query(), :assignment, + page_refs: [ + page: [ + id == ^page_id + ] + ] + ) + end + def assignment_query(%Account.User{id: user_id}, :participant) do build(assignment_query(), :assignment, crew: [ diff --git a/core/systems/assignment/_switch.ex b/core/systems/assignment/_switch.ex index 1a8662980..14f1caecc 100644 --- a/core/systems/assignment/_switch.ex +++ b/core/systems/assignment/_switch.ex @@ -12,6 +12,25 @@ defmodule Systems.Assignment.Switch do alias Systems.Crew alias Systems.NextAction + @impl true + def intercept( + {:content_page, _} = signal, + %{content_page: content_page} = message + ) do + if assignment = + Assignment.Public.get_by_content_page( + content_page, + Assignment.Model.preload_graph(:down) + ) do + dispatch!( + {:assignment, signal}, + Map.merge(message, %{assignment: assignment}) + ) + end + + :ok + end + @impl true def intercept( {:project_item, :inserted} = signal,