diff --git a/models/cloudbrain.go b/models/cloudbrain.go index dacb1b03a..f536895a2 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -291,6 +291,13 @@ func (task *Cloudbrain) IsRunning() bool { status == string(JobRunning) || status == GrampusStatusRunning } +func (task *Cloudbrain) IsUserHasRight(user *User) bool { + if user == nil { + return false + } + return user.IsAdmin || user.ID == task.UserID +} + func ConvertDurationToStr(duration int64) string { if duration <= 0 { return DURATION_STR_ZERO diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 68d2923a4..7022dc011 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -653,8 +653,7 @@ func CloudbrainGetLog(ctx *context.APIContext) { //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 != "" && - (ctx.IsSigned && (ctx.IsUserSiteAdmin() || ctx.User.ID == job.UserID)) + 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 9f9e67ccc..16e4997a3 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -296,10 +296,7 @@ func TrainJobGetLog(ctx *context.APIContext) { } func canLogDownload(user *models.User, task *models.Cloudbrain) bool { - if user == nil { - return false - } - if !user.IsAdmin && user.ID != task.UserID { + if task == nil || !task.IsUserHasRight(user) { return false } prefix := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, modelarts.LogPath, task.VersionName), "/") + "/job" diff --git a/routers/repo/grampus.go b/routers/repo/grampus.go index 0620350f6..e16d39a00 100755 --- a/routers/repo/grampus.go +++ b/routers/repo/grampus.go @@ -941,12 +941,7 @@ func GrampusGetLog(ctx *context.Context) { ctx.ServerError(err.Error(), err) return } - var canLogDownload bool - if err != nil { - canLogDownload = false - } else { - canLogDownload = true - } + canLogDownload := err == nil && job.IsUserHasRight(ctx.User) ctx.JSON(http.StatusOK, map[string]interface{}{ "JobName": job.JobName, "Content": content,