mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-10-31 18:16:00 +08:00 
			
		
		
		
	fix (access): UI should show/hide according to plugin meta
This commit is contained in:
		| @ -285,16 +285,34 @@ 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) { | ||||
| 		if perms.CanSee == nil || *perms.CanSee == true { | ||||
| 			allowed = append(allowed, "GET") | ||||
| 		} | ||||
| 	} | ||||
| 	if model.CanEdit(&ctx) { | ||||
| 		if (perms.CanCreateFile == nil || *perms.CanCreateFile == true) && | ||||
| 			(perms.CanCreateDirectory == nil || *perms.CanCreateDirectory == true) { | ||||
| 			allowed = append(allowed, "PUT") | ||||
| 		} | ||||
| 	} | ||||
| 	if model.CanUpload(&ctx) { | ||||
| 		if perms.CanUpload == nil || *perms.CanUpload == true { | ||||
| 			allowed = append(allowed, "POST") | ||||
| 		} | ||||
| 	} | ||||
| 	header := res.Header() | ||||
| 	header.Set("Allow", strings.Join(allowed, ", ")) | ||||
| 	SendSuccessResult(res, nil) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Mickael Kerjean
					Mickael Kerjean