Skip to content

Commit

Permalink
#855 Participant who does not give consent causes runaway memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Sep 11, 2024
1 parent 144260e commit 0b0e959
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
7 changes: 7 additions & 0 deletions core/systems/assignment/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ defmodule Systems.Assignment.Public do
end
end

def participant_id(%Assignment.Model{crew: crew}, user) do
case Crew.Public.get_member_unsafe(crew, user) do
%{public_id: public_id} -> {:ok, public_id}
_ -> :error
end
end

def owner!(%Assignment.Model{} = assignment), do: parent_owner!(assignment)
def owner!(%Workflow.Model{} = workflow), do: parent_owner!(workflow)
def owner!(%Workflow.ItemModel{} = item), do: parent_owner!(item)
Expand Down
14 changes: 14 additions & 0 deletions core/systems/assignment/controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,23 @@ defmodule Systems.Assignment.Controller do
defp start_participant(conn, %{id: id} = assignment) do
conn
|> authorize_user(assignment)
|> add_panel_info(assignment)
|> redirect(to: ~p"/assignment/#{id}")
end

defp add_panel_info(%{assigns: %{current_user: user}} = conn, assignment) do
{:ok, participant} = Assignment.Public.participant_id(assignment, user)

panel_info = %{
panel: :next,
embedded?: false,
participant: participant,
query_string: []
}

conn |> put_session(:panel_info, panel_info)
end

defp authorize_user(%{assigns: %{current_user: user}} = conn, %Assignment.Model{} = assignment) do
Assignment.Public.add_participant!(assignment, user)
conn
Expand Down
17 changes: 13 additions & 4 deletions core/systems/assignment/crew_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ defmodule Systems.Assignment.CrewPage do
}
end

@impl true
def compose(:declined_view, _) do
%{
module: Assignment.DeclinedView,
params: %{}
}
end

@impl true
def handle_view_model_updated(socket) do
socket
Expand Down Expand Up @@ -132,10 +140,9 @@ defmodule Systems.Assignment.CrewPage do
if embedded? do
socket
else
title = dgettext("eyra-assignment", "declined_view.title")
child = prepare_child(socket, :declined_view, Assignment.DeclinedView, %{title: title})
modal = %{live_component: child, style: :notification}
assign(socket, modal: modal)
socket
|> compose_child(:declined_view)
|> show_modal(:declined_view, :notification)
end

{:noreply, socket}
Expand All @@ -158,6 +165,8 @@ defmodule Systems.Assignment.CrewPage do

@impl true
def handle_event(name, event, socket) do
Logger.warn("forwarding to flow: name=#{name}, event=#{inspect(event)}")

{
:noreply,
socket |> send_event(:flow, name, event)
Expand Down
4 changes: 3 additions & 1 deletion core/systems/assignment/declined_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ defmodule Systems.Assignment.DeclinedView do
@impl true
def update(_, socket) do
body = dgettext("eyra-assignment", "declined_view.body")
title = dgettext("eyra-assignment", "declined_view.title")

{
:ok,
socket |> assign(body: body)
socket |> assign(body: body, title: title)
}
end

@impl true
def render(assigns) do
~H"""
<div>
<Text.title2><%= @title %></Text.title2>
<div class="flex flex-col gap-2 items-center w-full h-full">
<div class="wysiwyg">
<%= raw @body %>
Expand Down
4 changes: 2 additions & 2 deletions core/systems/assignment/onboarding_consent_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ defmodule Systems.Assignment.OnboardingConsentView do
end

@impl true
def handle_event("accept", _payload, socket) do
def handle_event("accept", %{source: %{name: :clickwrap_view}}, socket) do
{:noreply, socket |> send_event(:parent, "accept")}
end

@impl true
def handle_event("decline", _payload, socket) do
def handle_event("decline", %{source: %{name: :clickwrap_view}}, socket) do
{:noreply, socket |> send_event(:parent, "decline")}
end

Expand Down
4 changes: 3 additions & 1 deletion core/systems/storage/delivery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ defmodule Systems.Storage.Delivery do
end

def deliver(backend, endpoint, data, meta_data) do
Logger.notice("[Storage.Delivery] deliver", ansi_color: :light_magenta)
Logger.notice("[Storage.Delivery] deliver #{byte_size(data)} bytes",
ansi_color: :light_magenta
)

try do
backend.store(endpoint, data, meta_data)
Expand Down

0 comments on commit 0b0e959

Please sign in to comment.