Created
April 14, 2023 00:47
-
-
Save rayrayzayzay/6605843390a3b4b775542eb6ecfc2a55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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