aboutsummaryrefslogtreecommitdiff
path: root/cmd/monfront/authorizer.go
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2021-12-02 17:54:14 +0100
committerGibheer <gibheer+git@zero-knowledge.org>2021-12-02 17:54:14 +0100
commitfa05045d31c05c8928020f05f1d281901d983b2b (patch)
tree2ed3bac60302bfb14535a169f4b3e10d18fc6120 /cmd/monfront/authorizer.go
parent41d4805d584161ca16b8187194385e47c36422a6 (diff)
cmd/monfront - import monfront from separate repository
This is the import from the separate monfront repository. The history could not be imported, but this should suffice.
Diffstat (limited to 'cmd/monfront/authorizer.go')
-rw-r--r--cmd/monfront/authorizer.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/cmd/monfront/authorizer.go b/cmd/monfront/authorizer.go
new file mode 100644
index 0000000..7880cd0
--- /dev/null
+++ b/cmd/monfront/authorizer.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "database/sql"
+ "fmt"
+)
+
+type (
+ Authorizer struct {
+ db *sql.DB
+ Mode string
+ List []string
+ }
+)
+
+func (a *Authorizer) Handler() (func(c *Context) error, error) {
+ switch a.Mode {
+ case "none":
+ return func(_ *Context) error { return nil }, nil
+ case "list":
+ return func(c *Context) error {
+ for _, user := range a.List {
+ if user == c.User {
+ c.CanEdit = true
+ return nil
+ }
+ }
+ return nil
+ }, nil
+ case "all":
+ return func(c *Context) error { c.CanEdit = true; return nil }, nil
+ default:
+ return func(_ *Context) error { return nil }, fmt.Errorf("authorization mode '%s' is unsupported", a.Mode)
+ }
+}