From a31ad44bb81a782757a35d7432255939afe5eb09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 12 May 2022 00:12:15 +0200 Subject: [PATCH] plugins generic only. --- pkg/auth/auth.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 98620387..43126ae5 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -2,6 +2,7 @@ package auth import ( "context" + "fmt" "net/http" "gitlab.com/demodesk/neko/server/pkg/types" @@ -69,3 +70,19 @@ func CanAccessClipboardOnly(w http.ResponseWriter, r *http.Request) (context.Con return nil, nil } + +func PluginsGenericOnly[V comparable](key string, value V) func(w http.ResponseWriter, r *http.Request) (context.Context, error) { + return func(w http.ResponseWriter, r *http.Request) (context.Context, error) { + session, ok := GetSession(r) + if !ok { + return nil, utils.HttpForbidden("session not found") + } + + plugins := session.Profile().Plugins + if val, ok := plugins[key].(V); !ok || val != value { + return nil, utils.HttpForbidden(fmt.Sprintf("%s is set to %v; expected %v", key, value, val)) + } + + return nil, nil + } +}