mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-31 19:36:44 +01:00
add role map to users
This commit is contained in:
parent
8a4b6d3b0a
commit
c8e63adc22
2 changed files with 11 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue