fix: include user role in moderator role

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Hugo Renard
2023-05-22 19:11:30 +02:00
committed by Thomas Citharel
parent 3309850d72
commit c4d60194a6
2 changed files with 30 additions and 1 deletions

View File

@@ -31,13 +31,14 @@ defmodule Mobilizon.GraphQL.Authorization do
@impl true
def role_authorized?(_user_role, :all), do: true
def role_authorized?(role, _allowed_role) when is_super_role(role), do: true
def role_authorized?(:moderator, :user), do: true
def role_authorized?(user_role, allowed_role) when is_atom(user_role) and is_atom(allowed_role),
do: user_role === allowed_role
def role_authorized?(user_role, allowed_roles)
when is_atom(user_role) and is_list(allowed_roles),
do: user_role in allowed_roles
do: user_role in allowed_roles or (user_role === :moderator and :user in allowed_roles)
@impl true
def get_user_role(%ApplicationToken{user: %{role: role}}), do: role