From 208a99809fb830d1a29e0074bd713623f3c313c7 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Wed, 9 Nov 2022 15:36:01 +0800 Subject: [PATCH] Revert "#3157" This reverts commit 3aca1dc0749ccbe1af32063a2a621fe721f6bb01. --- routers/api/v1/repo/cloudbrain.go | 23 ++++------------------- routers/api/v1/repo/modelarts.go | 22 +++++----------------- routers/repo/grampus.go | 12 ++---------- 3 files changed, 11 insertions(+), 46 deletions(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 9da1251e4..7022dc011 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -607,24 +607,6 @@ func CloudbrainGetLog(ctx *context.APIContext) { lines := ctx.QueryInt("lines") baseLine := ctx.Query("base_line") order := ctx.Query("order") - - //Logs can only be downloaded if the file exists - //and the current user is an administrator or the creator of the task - if !job.IsUserHasRight(ctx.User) { - re := map[string]interface{}{ - "JobID": ID, - "LogFileName": "", - "StartLine": 0, - "EndLine": 0, - "Content": "", - "Lines": 0, - "CanLogDownload": false, - "StartTime": job.StartTime, - } - ctx.JSON(http.StatusOK, re) - return - } - var result map[string]interface{} resultPath := "/model" if job.JobType == string(models.JobTypeInference) || job.JobType == string(models.JobTypeModelSafety) { @@ -668,7 +650,10 @@ func CloudbrainGetLog(ctx *context.APIContext) { content = content + ctx.Data["existStr"].(string) } logFileName := result["FileName"] - canLogDownload := logFileName != nil && logFileName != "" + + //Logs can only be downloaded if the file exists + //and the current user is an administrator or the creator of the task + canLogDownload := logFileName != nil && logFileName != "" && job.IsUserHasRight(ctx.User) re := map[string]interface{}{ "JobID": ID, diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index 00cdea0ef..16e4997a3 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -274,21 +274,6 @@ func TrainJobGetLog(ctx *context.APIContext) { log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error()) return } - - if !task.IsUserHasRight(ctx.User) { - ctx.JSON(http.StatusOK, map[string]interface{}{ - "JobID": jobID, - "LogFileName": "", - "StartLine": 0, - "EndLine": 0, - "Content": "", - "Lines": 0, - "CanLogDownload": false, - "StartTime": task.StartTime, - }) - return - } - resultLogFile, result, err := trainJobGetLogContent(jobID, task.VersionID, baseLine, order, lines_int) if err != nil { log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error()) @@ -305,12 +290,15 @@ func TrainJobGetLog(ctx *context.APIContext) { "EndLine": result.EndLine, "Content": result.Content, "Lines": result.Lines, - "CanLogDownload": canLogDownload(task), + "CanLogDownload": canLogDownload(ctx.User, task), "StartTime": task.StartTime, }) } -func canLogDownload(task *models.Cloudbrain) bool { +func canLogDownload(user *models.User, task *models.Cloudbrain) bool { + if task == nil || !task.IsUserHasRight(user) { + return false + } prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, modelarts.LogPath, task.VersionName), "/") + "/job" _, err := storage.GetObsLogFileName(prefix) if err != nil { diff --git a/routers/repo/grampus.go b/routers/repo/grampus.go index a2a021a43..e16d39a00 100755 --- a/routers/repo/grampus.go +++ b/routers/repo/grampus.go @@ -935,25 +935,17 @@ func GrampusGetLog(ctx *context.Context) { return } - if !job.IsUserHasRight(ctx.User) { - ctx.JSON(http.StatusOK, map[string]interface{}{ - "JobName": job.JobName, - "Content": "", - "CanLogDownload": false, - }) - return - } - content, err := grampus.GetTrainJobLog(job.JobID) if err != nil { log.Error("GetTrainJobLog failed: %v", err, ctx.Data["MsgID"]) ctx.ServerError(err.Error(), err) return } + canLogDownload := err == nil && job.IsUserHasRight(ctx.User) ctx.JSON(http.StatusOK, map[string]interface{}{ "JobName": job.JobName, "Content": content, - "CanLogDownload": true, + "CanLogDownload": canLogDownload, }) return