fix (access): UI should show/hide according to plugin meta

This commit is contained in:
Mickael Kerjean
2021-09-16 23:21:36 +10:00
parent b154c559ff
commit be09a0f60f

View File

@ -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, ", "))