plugins generic only.

This commit is contained in:
Miroslav Šedivý 2022-05-12 00:12:15 +02:00
parent 91c8f0886b
commit a31ad44bb8

View File

@ -2,6 +2,7 @@ package auth
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"gitlab.com/demodesk/neko/server/pkg/types" "gitlab.com/demodesk/neko/server/pkg/types"
@ -69,3 +70,19 @@ func CanAccessClipboardOnly(w http.ResponseWriter, r *http.Request) (context.Con
return nil, nil 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
}
}