Skip to content

Commit

Permalink
fix: allow force root while fetch dirs (close #1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 14, 2022
1 parent b197322 commit 66b2562
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions server/handles/fsread.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type ListReq struct {
}

type DirReq struct {
Path string `json:"path" form:"path"`
Password string `json:"password" form:"password"`
Path string `json:"path" form:"path"`
Password string `json:"password" form:"password"`
ForceRoot bool `json:"force_root" form:"force_root"`
}

type ObjResp struct {
Expand Down Expand Up @@ -93,7 +94,14 @@ func FsDirs(c *gin.Context) {
return
}
user := c.MustGet("user").(*model.User)
req.Path = stdpath.Join(user.BasePath, req.Path)
if req.ForceRoot {
if !user.IsAdmin() {
common.ErrorStrResp(c, "Permission denied", 403)
return
}
} else {
req.Path = stdpath.Join(user.BasePath, req.Path)
}
meta, err := db.GetNearestMeta(req.Path)
if err != nil {
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
Expand Down

0 comments on commit 66b2562

Please sign in to comment.