add role map to users

This commit is contained in:
byte[] 2019-12-07 19:57:37 -05:00
parent 8a4b6d3b0a
commit c8e63adc22
2 changed files with 11 additions and 0 deletions

View file

@ -172,5 +172,13 @@ defmodule Philomena.Users do
|> join(:left, [u, _], _ in assoc(u, :current_filter))
|> preload([_, r, cf], [current_filter: cf, roles: r])
|> Repo.get_by(clauses)
|> setup_roles()
end
defp setup_roles(nil), do: nil
defp setup_roles(user) do
role_map = Map.new(user.roles, &{&1.name, &1.resource_type || true})
%{user | role_map: role_map}
end
end

View file

@ -130,6 +130,9 @@ defmodule Philomena.Users.User do
field :uploaded_avatar, :string, virtual: true
field :removed_avatar, :string, virtual: true
# For mod stuff
field :role_map, :any, virtual: true
timestamps(inserted_at: :created_at)
end