Skip to content

Commit

Permalink
Remove token promotion from entity state
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Oct 27, 2023
1 parent ef3fde0 commit 1796a8a
Showing 1 changed file with 5 additions and 35 deletions.
40 changes: 5 additions & 35 deletions lib/ret_web/channels/hub_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,8 @@ defmodule RetWeb.HubChannel do
def handle_in("save_entity_state", params, socket) do
params = parse(params)

with {:ok, hub, account} <- authorize(socket, :write_entity_state),
{:ok, %{entity: entity}} <- Ret.create_entity(hub, params),
:ok <- maybe_promote_file(params, account, socket) do
with {:ok, hub, _account} <- authorize(socket, :write_entity_state),
{:ok, %{entity: entity}} <- Ret.create_entity(hub, params) do
entity = Repo.preload(entity, [:sub_entities])

broadcast!(
Expand Down Expand Up @@ -498,10 +497,9 @@ defmodule RetWeb.HubChannel do
end
end

def handle_in("delete_entity_state", %{"nid" => nid} = payload, socket) do
with {:ok, hub, account} <- authorize(socket, :write_entity_state),
{:ok, _} <- Ret.delete_entity(hub.hub_id, nid),
{:ok, _} <- maybe_set_owned_file_inactive(payload, account) do
def handle_in("delete_entity_state", %{"nid" => nid} = _payload, socket) do
with {:ok, hub, _account} <- authorize(socket, :write_entity_state),
{:ok, _} <- Ret.delete_entity(hub.hub_id, nid) do
RoomObject.perform_unpin(hub, nid)

broadcast!(socket, "entity_state_deleted", %{
Expand Down Expand Up @@ -1472,34 +1470,6 @@ defmodule RetWeb.HubChannel do
}
end

defp maybe_set_owned_file_inactive(%{"file_id" => file_id}, %Account{account_id: account_id}) do
OwnedFile.set_inactive(file_id, account_id)
end

defp maybe_set_owned_file_inactive(_payload, _account) do
{:ok, :no_file}
end

defp maybe_promote_file(%{file_id: nil} = _params, _account, _socket) do
:ok
end

defp maybe_promote_file(params, account, _socket) do
with {:ok, _owned_file} <-
Storage.promote(
params.file_id,
params.file_access_token,
params.promotion_token,
account
) do
OwnedFile.set_active(params.file_id, account.account_id)
:ok
else
{:error, reason} ->
{:error, reason}
end
end

defp reply_error(socket, reason) do
{:reply, {:error, %{reason: reason}}, socket}
end
Expand Down

0 comments on commit 1796a8a

Please sign in to comment.