| @@ -607,24 +607,6 @@ func CloudbrainGetLog(ctx *context.APIContext) { | |||||
| lines := ctx.QueryInt("lines") | lines := ctx.QueryInt("lines") | ||||
| baseLine := ctx.Query("base_line") | baseLine := ctx.Query("base_line") | ||||
| order := ctx.Query("order") | 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{} | var result map[string]interface{} | ||||
| resultPath := "/model" | resultPath := "/model" | ||||
| if job.JobType == string(models.JobTypeInference) || job.JobType == string(models.JobTypeModelSafety) { | 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) | content = content + ctx.Data["existStr"].(string) | ||||
| } | } | ||||
| logFileName := result["FileName"] | 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{}{ | re := map[string]interface{}{ | ||||
| "JobID": ID, | "JobID": ID, | ||||
| @@ -274,21 +274,6 @@ func TrainJobGetLog(ctx *context.APIContext) { | |||||
| log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error()) | log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error()) | ||||
| return | 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) | resultLogFile, result, err := trainJobGetLogContent(jobID, task.VersionID, baseLine, order, lines_int) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error()) | log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error()) | ||||
| @@ -305,12 +290,15 @@ func TrainJobGetLog(ctx *context.APIContext) { | |||||
| "EndLine": result.EndLine, | "EndLine": result.EndLine, | ||||
| "Content": result.Content, | "Content": result.Content, | ||||
| "Lines": result.Lines, | "Lines": result.Lines, | ||||
| "CanLogDownload": canLogDownload(task), | |||||
| "CanLogDownload": canLogDownload(ctx.User, task), | |||||
| "StartTime": task.StartTime, | "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" | prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, modelarts.LogPath, task.VersionName), "/") + "/job" | ||||
| _, err := storage.GetObsLogFileName(prefix) | _, err := storage.GetObsLogFileName(prefix) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -935,25 +935,17 @@ func GrampusGetLog(ctx *context.Context) { | |||||
| return | 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) | content, err := grampus.GetTrainJobLog(job.JobID) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("GetTrainJobLog failed: %v", err, ctx.Data["MsgID"]) | log.Error("GetTrainJobLog failed: %v", err, ctx.Data["MsgID"]) | ||||
| ctx.ServerError(err.Error(), err) | ctx.ServerError(err.Error(), err) | ||||
| return | return | ||||
| } | } | ||||
| canLogDownload := err == nil && job.IsUserHasRight(ctx.User) | |||||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | ctx.JSON(http.StatusOK, map[string]interface{}{ | ||||
| "JobName": job.JobName, | "JobName": job.JobName, | ||||
| "Content": content, | "Content": content, | ||||
| "CanLogDownload": true, | |||||
| "CanLogDownload": canLogDownload, | |||||
| }) | }) | ||||
| return | return | ||||