Skip to content

Commit

Permalink
fix: hide apply to sub path without enable (close #3661)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Feb 28, 2023
1 parent 53a1c42 commit ca9e739
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/common/check.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"path"
"regexp"
"strings"

Expand All @@ -15,9 +16,17 @@ func CanWrite(meta *model.Meta, path string) bool {
return meta.WSub || meta.Path == path
}

func IsApply(metaPath, reqPath string, applySub bool) bool {
if utils.PathEqual(metaPath, reqPath) {
return true
}
return utils.IsSubPath(reqPath, metaPath) && applySub
}

func CanAccess(user *model.User, meta *model.Meta, reqPath string, password string) bool {
// if the reqPath is in hide (only can check the nearest meta) and user can't see hides, can't access
if meta != nil && !user.CanSeeHides() && meta.Hide != "" && !utils.PathEqual(meta.Path, reqPath) {
if meta != nil && !user.CanSeeHides() && meta.Hide != "" &&
IsApply(meta.Path, path.Dir(reqPath), meta.HSub) { // the meta should apply to the parent of current path
for _, hide := range strings.Split(meta.Hide, "\n") {
re := regexp.MustCompile(hide)
if re.MatchString(reqPath[len(meta.Path)+1:]) {
Expand Down

0 comments on commit ca9e739

Please sign in to comment.