feat: per path modify permissions (#57)

This commit is contained in:
mik2k2
2021-01-14 14:43:52 +00:00
committed by GitHub
parent fca4e54839
commit 8cd6d0a585
4 changed files with 22 additions and 17 deletions
+11 -3
View File
@@ -14,7 +14,7 @@ import (
"golang.org/x/net/webdav"
)
func parseRules(raw []interface{}) []*lib.Rule {
func parseRules(raw []interface{}, defaultModify bool) []*lib.Rule {
rules := []*lib.Rule{}
for _, v := range raw {
@@ -22,6 +22,7 @@ func parseRules(raw []interface{}) []*lib.Rule {
rule := &lib.Rule{
Regex: false,
Allow: false,
Modify: defaultModify,
Path: "",
}
@@ -33,6 +34,13 @@ func parseRules(raw []interface{}) []*lib.Rule {
rule.Allow = allow
}
if modify, ok := r["modify"].(bool); ok {
rule.Modify = modify
if modify {
rule.Allow = true
}
}
path, ok := r["path"].(string)
if !ok {
continue
@@ -110,7 +118,7 @@ func parseUsers(raw []interface{}, c *lib.Config) {
}
if rules, ok := u["rules"].([]interface{}); ok {
user.Rules = parseRules(rules)
user.Rules = append(c.User.Rules, parseRules(rules, user.Modify)...)
}
user.Handler = &webdav.Handler{
@@ -186,7 +194,7 @@ func readConfig(flags *pflag.FlagSet) *lib.Config {
rawRules := v.Get("rules")
if rules, ok := rawRules.([]interface{}); ok {
cfg.User.Rules = parseRules(rules)
cfg.User.Rules = parseRules(rules, cfg.User.Modify)
}
rawUsers := v.Get("users")