Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Nov 19, 2024
1 parent 772e48e commit d544171
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/mindwendel/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
9 changes: 9 additions & 0 deletions lib/mindwendel/brainstormings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/mindwendel_web/live/brainstorming_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d544171

Please sign in to comment.