mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-30 01:26: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) {
|
||||
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{}
|
||||
if model.CanRead(&ctx) {
|
||||
allowed = append(allowed, "GET")
|
||||
if perms.CanSee == nil || *perms.CanSee == true {
|
||||
allowed = append(allowed, "GET")
|
||||
}
|
||||
}
|
||||
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) {
|
||||
allowed = append(allowed, "POST")
|
||||
if perms.CanUpload == nil || *perms.CanUpload == true {
|
||||
allowed = append(allowed, "POST")
|
||||
}
|
||||
}
|
||||
header := res.Header()
|
||||
header.Set("Allow", strings.Join(allowed, ", "))
|
||||
|
||||
Reference in New Issue
Block a user