Browse Source

先用是否登录判断权限,然后在用身份判断,提高效率

pull/1043/head
ychao_1983 3 years ago
parent
commit
4d938521cd
1 changed files with 11 additions and 2 deletions
  1. +11
    -2
      modules/cloudbrain/cloudbrain.go

+ 11
- 2
modules/cloudbrain/cloudbrain.go View File

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


import ( import (
"errors" "errors"
"strconv"


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


@@ -30,10 +31,13 @@ var (
) )


func isAdminOrOwnerOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool { 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 { if err != nil {

return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin() return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin()
} else { } else {
log.Info("is job creator:" + strconv.FormatBool(ctx.User.ID == job.UserID))
return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin() || 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) { if job.Status != string(models.JobStopped) && job.Status != string(models.JobFailed) && job.Status != string(models.ModelArtsStartFailed) && job.Status != string(models.ModelArtsCreateFailed) {
return false return false
} }
if !ctx.IsSigned {
return false
}
return isAdminOrOwnerOrJobCreater(ctx, job, nil) return isAdminOrOwnerOrJobCreater(ctx, job, nil)
} }


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

if !ctx.IsSigned {
return false
}
return isAdminOrOwnerOrJobCreater(ctx, job, nil) return isAdminOrOwnerOrJobCreater(ctx, job, nil)
} }




Loading…
Cancel
Save