MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / CanAccess

Function CanAccess

server/common/check.go:50–78  ·  view source on GitHub ↗
(user *model.User, meta *model.Meta, reqPath string, password string)

Source from the content-addressed store, hash-verified

48}
49
50func CanAccess(user *model.User, meta *model.Meta, reqPath string, password string) bool {
51 // if the reqPath is in hide (only can check the nearest meta) and user can't see hides, can't access
52 if meta != nil && !user.CanSeeHides() && meta.Hide != "" &&
53 MetaCoversPath(meta.Path, path.Dir(reqPath), meta.HSub) { // the meta should apply to the parent of current path
54 for hide := range strings.SplitSeq(meta.Hide, "\n") {
55 re := regexp2.MustCompile(hide, regexp2.None)
56 if isMatch, _ := re.MatchString(path.Base(reqPath)); isMatch {
57 return false
58 }
59 }
60 }
61 if !CanRead(user, meta, reqPath) {
62 return false
63 }
64 // if is not guest and can access without password
65 if user.CanAccessWithoutPassword() {
66 return true
67 }
68 // if meta is nil or password is empty, can access
69 if meta == nil || meta.Password == "" {
70 return true
71 }
72 // if meta doesn't apply to sub_folder, can access
73 if !MetaCoversPath(meta.Path, reqPath, meta.PSub) {
74 return true
75 }
76 // validate password
77 return meta.Password == password
78}
79
80func MetaCoversPath(metaPath, reqPath string, applyToSubFolder bool) bool {
81 if utils.PathEqual(metaPath, reqPath) {

Callers 15

handleGetHeadPostMethod · 0.92
handlePropfindMethod · 0.92
callFSLinkMethod · 0.92
callFSGetMethod · 0.92
callFSListMethod · 0.92
FsArchiveMetaFunction · 0.92
FsArchiveListFunction · 0.92
SearchFunction · 0.92
FsListFunction · 0.92
FsDirsFunction · 0.92
FsGetFunction · 0.92
FsOtherFunction · 0.92

Calls 4

MetaCoversPathFunction · 0.85
CanReadFunction · 0.85
CanSeeHidesMethod · 0.80

Tested by 1