diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 7022dc011..9da1251e4 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -607,6 +607,24 @@ 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) { @@ -650,10 +668,7 @@ func CloudbrainGetLog(ctx *context.APIContext) { content = content + ctx.Data["existStr"].(string) } logFileName := result["FileName"] - - //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) + canLogDownload := logFileName != nil && logFileName != "" re := map[string]interface{}{ "JobID": ID, diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index 16e4997a3..00cdea0ef 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -274,6 +274,21 @@ 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()) @@ -290,15 +305,12 @@ func TrainJobGetLog(ctx *context.APIContext) { "EndLine": result.EndLine, "Content": result.Content, "Lines": result.Lines, - "CanLogDownload": canLogDownload(ctx.User, task), + "CanLogDownload": canLogDownload(task), "StartTime": task.StartTime, }) } -func canLogDownload(user *models.User, task *models.Cloudbrain) bool { - if task == nil || !task.IsUserHasRight(user) { - return false - } +func canLogDownload(task *models.Cloudbrain) bool { 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 e16d39a00..a2a021a43 100755 --- a/routers/repo/grampus.go +++ b/routers/repo/grampus.go @@ -935,17 +935,25 @@ 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": canLogDownload, + "CanLogDownload": true, }) return