From 659f56b9a2385bf47be7c044d13780d8903fe6f7 Mon Sep 17 00:00:00 2001 From: emli Date: Thu, 8 Feb 2018 20:00:06 +0600 Subject: [PATCH] Allow subutai user delete other's artifacts --- db/db.go | 4 +++- upload/upload.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/db/db.go b/db/db.go index 62368d0..27adc1e 100644 --- a/db/db.go +++ b/db/db.go @@ -232,7 +232,9 @@ func Info(id string) map[string]string { } return nil }) - list["id"] = id + if len(list) != 0 { + list["id"] = id + } return list } diff --git a/upload/upload.go b/upload/upload.go index 09f79a5..42b5ba0 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -147,13 +147,14 @@ func Delete(w http.ResponseWriter, r *http.Request) string { w.Write([]byte("Bad request")) return "" } - - if db.CheckRepo(user, repo[3], id) == 0 { + if db.CheckRepo(user, repo[3], id) == 0 && user != "subutai" { log.Warn("File " + info["name"] + "(" + id + ") in " + repo[3] + " repo is not owned by " + user + ", rejecting deletion request") w.WriteHeader(http.StatusNotFound) w.Write([]byte("File " + info["name"] + " not found or it has different owner")) return "" } + user = db.FileField(id, "owner")[0] + md5, _ := db.Hash(id) f, err := os.Stat(config.Storage.Path + md5) if !log.Check(log.WarnLevel, "Reading file stats", err) {