mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-29 17:18:43 +08:00
fix (access): UI should show/hide according to plugin meta
This commit is contained in:
@ -285,15 +285,33 @@ func FileCat(ctx App, res http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FileAccess(ctx App, res http.ResponseWriter, req *http.Request) {
|
func FileAccess(ctx App, res http.ResponseWriter, req *http.Request) {
|
||||||
|
path, err := PathBuilder(ctx, req.URL.Query().Get("path"))
|
||||||
|
if err != nil {
|
||||||
|
Log.Debug("access::path '%s'", err.Error())
|
||||||
|
SendErrorResult(res, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var perms Metadata = Metadata{}
|
||||||
|
if obj, ok := ctx.Backend.(interface{ Meta(path string) Metadata }); ok {
|
||||||
|
perms = obj.Meta(path)
|
||||||
|
}
|
||||||
|
|
||||||
allowed := []string{}
|
allowed := []string{}
|
||||||
if model.CanRead(&ctx) {
|
if model.CanRead(&ctx) {
|
||||||
allowed = append(allowed, "GET")
|
if perms.CanSee == nil || *perms.CanSee == true {
|
||||||
|
allowed = append(allowed, "GET")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if model.CanEdit(&ctx) {
|
if model.CanEdit(&ctx) {
|
||||||
allowed = append(allowed, "PUT")
|
if (perms.CanCreateFile == nil || *perms.CanCreateFile == true) &&
|
||||||
|
(perms.CanCreateDirectory == nil || *perms.CanCreateDirectory == true) {
|
||||||
|
allowed = append(allowed, "PUT")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if model.CanUpload(&ctx) {
|
if model.CanUpload(&ctx) {
|
||||||
allowed = append(allowed, "POST")
|
if perms.CanUpload == nil || *perms.CanUpload == true {
|
||||||
|
allowed = append(allowed, "POST")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
header := res.Header()
|
header := res.Header()
|
||||||
header.Set("Allow", strings.Join(allowed, ", "))
|
header.Set("Allow", strings.Join(allowed, ", "))
|
||||||
|
|||||||
Reference in New Issue
Block a user