zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

commit 27863bb40541969b5b430f3f7f290ed2de84c756
parent e320dd018e9c9221607821b30fb747d1af91019c
Author: srfsh <dev@srf.sh>
Date:   Thu, 21 Jul 2022 20:08:05 +0300

gql/schema: simplify admin/sign logic

Diffstat:
Msrc/zenflows/gql/schema.ex | 20+++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/zenflows/gql/schema.ex b/src/zenflows/gql/schema.ex @@ -160,15 +160,21 @@ mutation do #import_fields :mutation_proposed_to end -@impl true -def middleware(mw, %{identifier: ident}, _) - when ident in ~w[create_person delete_person import_repos]a do - mw ++ [MW.Errors, MW.Admin] -end +require Logger + +# List of mutations/queries that require admin key. +#@admin_calls ~w[create_person delete_person import_repos]a -def middleware(mw, _, _) do - mw ++ [MW.Errors, MW.Sign] +@impl true +def middleware(mw, field, %{identifier: id}) + when id in ~w[query mutation subscription]a do + if Absinthe.Type.meta(field, :auth_admin?) do + [MW.Admin | mw] ++ [MW.Errors] + else + [MW.Sign | mw] ++ [MW.Errors] + end end +def middleware(mw, _, _), do: mw @impl true #def hydrate(%Absinthe.Blueprint.Schema.ScalarTypeDefinition{identifier: :id}, %{identifier: :action}) do