Current section

Files

Jump to
step_flow lib step_flow controllers helpers.ex
Raw

lib/step_flow/controllers/helpers.ex

defmodule StepFlow.Controller.Helpers do
@moduledoc """
The Helper Controller context.
"""
@doc """
Check wether a user is allowed to use a rightable structure
"""
def has_right(rightable, user, action) do
rightable
|> Map.get(:rights)
|> Enum.find(%{}, fn r -> r.action == action end)
|> Map.get(:groups, [])
|> Enum.any?(fn g -> g in user.rights end)
end
end