Browse Source

#3157

fix bug
tags/v1.22.11.2^2
chenyifan01 3 years ago
parent
commit
dc30a93f94
4 changed files with 10 additions and 12 deletions
  1. +7
    -0
      models/cloudbrain.go
  2. +1
    -2
      routers/api/v1/repo/cloudbrain.go
  3. +1
    -4
      routers/api/v1/repo/modelarts.go
  4. +1
    -6
      routers/repo/grampus.go

+ 7
- 0
models/cloudbrain.go View File

@@ -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


+ 1
- 2
routers/api/v1/repo/cloudbrain.go View File

@@ -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,


+ 1
- 4
routers/api/v1/repo/modelarts.go View File

@@ -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"


+ 1
- 6
routers/repo/grampus.go View File

@@ -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,


Loading…
Cancel
Save