fix: align CHFS permission error responses
This commit is contained in:
@@ -226,7 +226,7 @@ func (s *Server) newdir(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
a := account(r, s)
|
||||
if !a.MaskFor(p).HasWrite() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
if e := s.Store.MkdirAll(p); e != nil {
|
||||
@@ -241,7 +241,7 @@ func (s *Server) rename(w http.ResponseWriter, r *http.Request) {
|
||||
old := strings.Trim(r.FormValue("old"), "/")
|
||||
neu := strings.Trim(r.FormValue("new"), "/")
|
||||
if old == "" || neu == "" || !a.MaskFor(old).HasWrite() || !a.MaskFor(path.Dir(neu)).HasWrite() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
if e := s.Store.Rename(old, neu); e != nil {
|
||||
@@ -262,7 +262,7 @@ func (s *Server) remove(w http.ResponseWriter, r *http.Request) {
|
||||
for _, raw := range items {
|
||||
p := strings.Trim(strings.ReplaceAll(raw, "\\", "/"), "/")
|
||||
if p == "" || !a.MaskFor(p).HasDelete() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
if e := s.removePath(p); e != nil {
|
||||
@@ -363,7 +363,7 @@ func (s *Server) newtext(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
p := path.Join(dir, filename)
|
||||
if !a.MaskFor(p).HasWrite() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
f, e := s.Store.Create(p)
|
||||
@@ -382,7 +382,7 @@ func (s *Server) updatetext(w http.ResponseWriter, r *http.Request) {
|
||||
name := strings.Trim(r.FormValue("filename"), "/")
|
||||
p := path.Join(dir, name)
|
||||
if name == "" || !a.MaskFor(p).HasWrite() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
f, e := s.Store.Create(p)
|
||||
@@ -406,7 +406,7 @@ func (s *Server) upload(w http.ResponseWriter, r *http.Request) {
|
||||
a := account(r, s)
|
||||
dir := strings.Trim(r.FormValue("folder"), "/")
|
||||
if !a.MaskFor(dir).HasWrite() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
var saved []string
|
||||
@@ -448,7 +448,7 @@ func (s *Server) upload2(w http.ResponseWriter, r *http.Request) {
|
||||
a := account(r, s)
|
||||
dir := strings.Trim(r.URL.Query().Get("folder"), "/")
|
||||
if !a.MaskFor(dir).HasWrite() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
if err := r.ParseMultipartForm(128 << 20); err != nil {
|
||||
@@ -490,7 +490,7 @@ func (s *Server) search(w http.ResponseWriter, r *http.Request) {
|
||||
a := account(r, s)
|
||||
rootMask := a.MaskFor("")
|
||||
if !rootMask.HasRead() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
needle := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("str")))
|
||||
@@ -581,7 +581,7 @@ func (s *Server) preview(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if !account(r, s).MaskFor(file).HasRead() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
if !s.ImagePreview {
|
||||
@@ -631,7 +631,7 @@ func (s *Server) serveFile(w http.ResponseWriter, r *http.Request, p string, att
|
||||
a := account(r, s)
|
||||
p = strings.Trim(strings.ReplaceAll(p, "\\", "/"), "/")
|
||||
if !a.MaskFor(p).HasRead() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
fi, err := s.Store.Stat(p)
|
||||
@@ -661,7 +661,7 @@ func (s *Server) downloadDir(w http.ResponseWriter, r *http.Request) {
|
||||
p := strings.TrimPrefix(r.URL.Path, "/chfs/downloaddir/")
|
||||
p = strings.Trim(p, "/")
|
||||
if !a.MaskFor(p).HasRead() {
|
||||
http.Error(w, "forbidden", 403)
|
||||
writeJSONError(w, http.StatusForbidden, "has no privilege")
|
||||
return
|
||||
}
|
||||
fi, err := s.Store.Stat(p)
|
||||
|
||||
Reference in New Issue
Block a user