Skip to content

Commit

Permalink
fix(permissions): masking of permissions left permissions nested, unn…
Browse files Browse the repository at this point in the history
…ested permissions to match what frontend expects
  • Loading branch information
akinsey committed Oct 25, 2022
1 parent 84d8a75 commit a8f5733
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/epochtalk_server/models/role.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ defmodule EpochtalkServer.Models.Role do
Takes in list of user's roles, and returns an xored map of all `Role` permissions
"""
@spec get_masked_permissions(roles :: [t()]) :: map()
def get_masked_permissions(roles) when is_list(roles), do: Enum.reduce(roles, %{}, &mask_permissions(&2, &1))

def get_masked_permissions(roles) when is_list(roles) do
masked_role = Enum.reduce(roles, %{}, &mask_permissions(&2, &1))
masked_role.permissions
|> Map.put(:highlight_color, masked_role.highlight_color)
|> Map.put(:priority_restrictions, masked_role.priority_restrictions)
|> Map.put(:priority, masked_role.priority)
end
## === Private Helper Functions ===

defp mask_permissions(target, source) do
Expand Down

0 comments on commit a8f5733

Please sign in to comment.