From 4d938521cde74cda45e63fb2e2c2ee934e807cef Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 8 Dec 2021 10:47:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=85=88=E7=94=A8=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=88=A4=E6=96=AD=E6=9D=83=E9=99=90=EF=BC=8C?= =?UTF-8?q?=E7=84=B6=E5=90=8E=E5=9C=A8=E7=94=A8=E8=BA=AB=E4=BB=BD=E5=88=A4?= =?UTF-8?q?=E6=96=AD=EF=BC=8C=E6=8F=90=E9=AB=98=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/cloudbrain/cloudbrain.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index cbc9580f9..8a5e11997 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -2,6 +2,7 @@ package cloudbrain import ( "errors" + "strconv" "code.gitea.io/gitea/modules/setting" @@ -30,10 +31,13 @@ var ( ) func isAdminOrOwnerOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool { - + 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 } @@ -44,11 +48,16 @@ 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 } + if !ctx.IsSigned { + return false + } return isAdminOrOwnerOrJobCreater(ctx, job, nil) } func CanDeleteTrainJob(ctx *context.Context, job *models.Cloudbrain) bool { - + if !ctx.IsSigned { + return false + } return isAdminOrOwnerOrJobCreater(ctx, job, nil) } From ace4ec5ca6b8a3ff1e4667e92916ead67e31f6ad Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 8 Dec 2021 10:59:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/cloudbrain/cloudbrain.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 8a5e11997..96dfce615 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -31,6 +31,9 @@ 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 { @@ -48,16 +51,12 @@ 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 } - if !ctx.IsSigned { - return false - } + return isAdminOrOwnerOrJobCreater(ctx, job, nil) } func CanDeleteTrainJob(ctx *context.Context, job *models.Cloudbrain) bool { - if !ctx.IsSigned { - return false - } + return isAdminOrOwnerOrJobCreater(ctx, job, nil) } @@ -74,7 +73,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 { @@ -125,7 +126,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, @@ -210,8 +211,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 { From 19f9541eb74b4b52701d694ed03229fa4fc1f60a Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 8 Dec 2021 11:25:33 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=9D=83=E9=99=90?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/cloudbrain/cloudbrain.go | 11 +---------- routers/repo/cloudbrain.go | 2 +- routers/repo/modelarts.go | 4 ++-- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 96dfce615..0f1c700d2 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -46,16 +46,7 @@ func isAdminOrOwnerOrJobCreater(ctx *context.Context, job *models.Cloudbrain, er } -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) } diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index a3af588fb..ae7163d77 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -79,7 +79,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) } diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index f0b807d96..483efbc20 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -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) }