Skip to content

Instantly share code, notes, and snippets.

@josevalim
Forked from jeremytregunna/authorize.ex
Last active April 29, 2018 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josevalim/89aab76890f1840153026180d2a764cb to your computer and use it in GitHub Desktop.
Save josevalim/89aab76890f1840153026180d2a764cb to your computer and use it in GitHub Desktop.
This looks horrible (formatter)
defmodule Api.Authorize do
alias Account.Models.User
def board?(board_id, %User{} = user, available_permissions, required_permissions) do
with(
{:ok, board} <- Tracker.Board.find(board_id),
true <- Tracker.OrganizationMembers.user_in_organization?(user.id, board.organization_id),
^required_permissions <-
Enum.to_list(
MapSet.intersection(
MapSet.new(required_permissions),
MapSet.new(available_permissions)
)
) do
true
else
_ -> false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment