Skip to content

Instantly share code, notes, and snippets.

@jeremytregunna
Created April 29, 2018 09:09
Show Gist options
  • Save jeremytregunna/b198c08abfa6b7c87e42c7f2bf67979d to your computer and use it in GitHub Desktop.
Save jeremytregunna/b198c08abfa6b7c87e42c7f2bf67979d 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
@jeremytregunna
Copy link
Author

As Jose Valim pointed out, usually a sign of needed refactoring...I did that, and this is what I ended up with: https://gist.github.com/jeremytregunna/95830562d9b3a70e0c898d9694445eb5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment