Browse Source

Merge branch 'V20211213' into zouap

pull/1046/head
zhoupzh 3 years ago
parent
commit
68fac8a9f7
3 changed files with 18 additions and 17 deletions
  1. +15
    -14
      modules/cloudbrain/cloudbrain.go
  2. +1
    -1
      routers/repo/cloudbrain.go
  3. +2
    -2
      routers/repo/modelarts.go

+ 15
- 14
modules/cloudbrain/cloudbrain.go View File

@@ -2,6 +2,7 @@ package cloudbrain

import (
"errors"
"strconv"

"code.gitea.io/gitea/modules/setting"

@@ -30,24 +31,22 @@ var (
)

func isAdminOrOwnerOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool {

if !ctx.IsSigned {
return false
}
log.Info("is repo owner:" + strconv.FormatBool(ctx.IsUserRepoOwner()))
log.Info("is user admin:" + strconv.FormatBool(ctx.IsUserSiteAdmin()))
if err != nil {

return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin()
} else {
log.Info("is job creator:" + strconv.FormatBool(ctx.User.ID == job.UserID))
return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin() || ctx.User.ID == job.UserID
}

}

func CanDeleteDebugJob(ctx *context.Context, job *models.Cloudbrain) bool {

if job.Status != string(models.JobStopped) && job.Status != string(models.JobFailed) && job.Status != string(models.ModelArtsStartFailed) && job.Status != string(models.ModelArtsCreateFailed) {
return false
}
return isAdminOrOwnerOrJobCreater(ctx, job, nil)
}

func CanDeleteTrainJob(ctx *context.Context, job *models.Cloudbrain) bool {
func CanDeleteJob(ctx *context.Context, job *models.Cloudbrain) bool {

return isAdminOrOwnerOrJobCreater(ctx, job, nil)
}
@@ -65,7 +64,9 @@ func CanModifyJob(ctx *context.Context, job *models.Cloudbrain) bool {
}

func isAdminOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool {

if !ctx.IsSigned {
return false
}
if err != nil {
return ctx.IsUserSiteAdmin()
} else {
@@ -116,7 +117,7 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath,
log.Error("no such resourceSpecId(%d)", resourceSpecId, ctx.Data["MsgID"])
return errors.New("no such resourceSpec")
}
jobResult, err := CreateJob(jobName, models.CreateJobParams{
JobName: jobName,
RetryCount: 1,
@@ -201,8 +202,8 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath,
JobName: jobName,
SubTaskName: SubTaskName,
JobType: jobType,
Type: models.TypeCloudBrainOne,
Uuid: uuid,
Type: models.TypeCloudBrainOne,
Uuid: uuid,
})

if err != nil {


+ 1
- 1
routers/repo/cloudbrain.go View File

@@ -78,7 +78,7 @@ func CloudBrainIndex(ctx *context.Context) {
ciTasks[i].CanDebug = false
}

ciTasks[i].CanDel = cloudbrain.CanDeleteDebugJob(ctx, &task.Cloudbrain)
ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain)

}



+ 2
- 2
routers/repo/modelarts.go View File

@@ -74,7 +74,7 @@ func NotebookIndex(ctx *context.Context) {
} else {
ciTasks[i].CanDebug = false
}
ciTasks[i].CanDel = cloudbrain.CanDeleteDebugJob(ctx, &task.Cloudbrain)
ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain)
}

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
@@ -306,7 +306,7 @@ func TrainJobIndex(ctx *context.Context) {
}

for i, task := range tasks {
tasks[i].CanDel = cloudbrain.CanDeleteTrainJob(ctx, &task.Cloudbrain)
tasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain)
tasks[i].CanModify = cloudbrain.CanModifyJob(ctx, &task.Cloudbrain)
}



Loading…
Cancel
Save