Skip to content

Instantly share code, notes, and snippets.

@rayrayzayzay
Created April 14, 2023 00:47
Show Gist options
  • Save rayrayzayzay/6605843390a3b4b775542eb6ecfc2a55 to your computer and use it in GitHub Desktop.
Save rayrayzayzay/6605843390a3b4b775542eb6ecfc2a55 to your computer and use it in GitHub Desktop.
defmodule Felt.Channel.ElementHandler do
def handle_event("create", payload, socket) do
with :ok <- ensure_map_editable(socket) do
# Create the element
end
end
def handle_event("update", payload, socket) do
with :ok <- ensure_map_editable(socket) do
# Update the element
end
end
def handle_event("delete", payload, socket) do
with :ok <- ensure_map_editable(socket) do
# Delete the element
end
end
defp ensure_map_editable(socket) do
case Felt.Maps.check_map_editable(socket.assigns.map_id, socket.assigns.current_user) do
:ok -> :ok
{:error, :unauthorized} -> {:error, "Not enough permissions"}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment