From 3b003b0661359c43bc51d47bc9b8fda33a84e5e6 Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Sat, 13 Apr 2019 00:39:33 +0200 Subject: [PATCH] feat(EditSpeaker): Register the video_id where the speaker was changed --- apps/cf/lib/actions/action_creator.ex | 4 ++++ apps/cf_rest_api/lib/channels/video_debate_channel.ex | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/cf/lib/actions/action_creator.ex b/apps/cf/lib/actions/action_creator.ex index 73772d46..a44bafe4 100644 --- a/apps/cf/lib/actions/action_creator.ex +++ b/apps/cf/lib/actions/action_creator.ex @@ -105,6 +105,10 @@ defmodule CF.Actions.ActionCreator do ) end + def action_update(user_id, %{data: %Speaker{id: id}, changes: changes}, video_id) do + action(user_id, :speaker, :update, speaker_id: id, video_id: video_id, changes: changes) + end + def action_update(user_id, %{data: %Speaker{id: id}, changes: changes}) do action(user_id, :speaker, :update, speaker_id: id, changes: changes) end diff --git a/apps/cf_rest_api/lib/channels/video_debate_channel.ex b/apps/cf_rest_api/lib/channels/video_debate_channel.ex index 15958e65..54decc99 100644 --- a/apps/cf_rest_api/lib/channels/video_debate_channel.ex +++ b/apps/cf_rest_api/lib/channels/video_debate_channel.ex @@ -6,7 +6,7 @@ defmodule CF.RestApi.VideoDebateChannel do only: [ action_add: 3, action_create: 2, - action_update: 2, + action_update: 3, action_remove: 3 ] @@ -156,6 +156,7 @@ defmodule CF.RestApi.VideoDebateChannel do def handle_in_authenticated!("update_speaker", params, socket) do user_id = socket.assigns.user_id + video_id = socket.assigns.video_id UserPermissions.check!(user_id, :update, :speaker) speaker = Repo.get!(Speaker, params["id"]) changeset = Speaker.changeset(speaker, params) @@ -167,7 +168,7 @@ defmodule CF.RestApi.VideoDebateChannel do _ -> Multi.new() |> Multi.update(:speaker, changeset) - |> Multi.insert(:action_update, action_update(user_id, changeset)) + |> Multi.insert(:action_update, action_update(user_id, changeset, video_id)) |> Repo.transaction() |> case do {:ok, %{speaker: speaker}} ->