diff --git a/lib/mindwendel/accounts.ex b/lib/mindwendel/accounts.ex index 009783bc..76d4f877 100644 --- a/lib/mindwendel/accounts.ex +++ b/lib/mindwendel/accounts.ex @@ -92,13 +92,13 @@ defmodule Mindwendel.Accounts do def add_moderating_user(%Brainstorming{} = brainstorming, user_id) when is_binary(user_id) do case Ecto.UUID.dump(user_id) do - :error -> brainstorming + :error -> {:error} {:ok, _} -> add_moderating_user(brainstorming, get_or_create_user(user_id)) end end - def add_moderating_user(%Brainstorming{} = brainstorming, user_id) when is_nil(user_id) do - brainstorming + def add_moderating_user(%Brainstorming{} = _brainstorming, user_id) when is_nil(user_id) do + {:error} end @doc """ diff --git a/lib/mindwendel/brainstormings.ex b/lib/mindwendel/brainstormings.ex index db840431..542939ca 100644 --- a/lib/mindwendel/brainstormings.ex +++ b/lib/mindwendel/brainstormings.ex @@ -230,6 +230,15 @@ defmodule Mindwendel.Brainstormings do brainstorming end + @doc """ + Validates the given secret against the brainstorming. Returns true/false. + + ## Examples + + iex> validate_admin_secret(brainstorming, abc) + false + + """ def validate_admin_secret(brainstorming, admin_secret_id) do brainstorming.admin_url_id == admin_secret_id end diff --git a/lib/mindwendel_web/live/brainstorming_live/show.ex b/lib/mindwendel_web/live/brainstorming_live/show.ex index 6d32e8ee..5a95d326 100644 --- a/lib/mindwendel_web/live/brainstorming_live/show.ex +++ b/lib/mindwendel_web/live/brainstorming_live/show.ex @@ -18,11 +18,12 @@ defmodule MindwendelWeb.BrainstormingLive.Show do brainstorming = Brainstormings.get_brainstorming!(id) admin_secret = get_connect_params(socket)["adminSecret"] - case Brainstormings.validate_admin_secret(brainstorming, admin_secret) do - true -> Accounts.add_moderating_user(brainstorming, current_user_id) - _ -> Accounts.merge_brainstorming_user(brainstorming, current_user_id) + if Brainstormings.validate_admin_secret(brainstorming, admin_secret) do + Accounts.add_moderating_user(brainstorming, current_user_id) end + Accounts.merge_brainstorming_user(brainstorming, current_user_id) + lanes = Lanes.get_lanes_for_brainstorming_with_labels_filtered(id) # load the user, also for permissions of brainstormings current_user = Mindwendel.Accounts.get_user(current_user_id)