mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-24 04:01:54 +08:00
feat: per path modify permissions (#57)
This commit is contained in:
+11
-3
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user