Browse Source

Merge branch 'V20211213' of git.openi.org.cn:OpenI/aiforge into isolation-compute

isolation-compute
lewis 4 years ago
parent
commit
7c3b996c3b
5 changed files with 60 additions and 17 deletions
  1. +1
    -0
      models/cloudbrain.go
  2. +16
    -6
      models/user.go
  3. +28
    -8
      modules/cloudbrain/cloudbrain.go
  4. +4
    -2
      routers/repo/cloudbrain.go
  5. +11
    -1
      routers/repo/modelarts.go

+ 1
- 0
models/cloudbrain.go View File

@@ -91,6 +91,7 @@ type Cloudbrain struct {
DeletedAt time.Time `xorm:"deleted"`
CanDebug bool `xorm:"-"`
CanDel bool `xorm:"-"`
CanModify bool `xorm:"-"`
Type int

VersionID int64 //版本id


+ 16
- 6
models/user.go View File

@@ -145,7 +145,7 @@ type User struct {
AllowImportLocal bool // Allow migrate repository by local path
AllowCreateOrganization bool `xorm:"DEFAULT true"`
ProhibitLogin bool `xorm:"NOT NULL DEFAULT false"`
IsOperator bool `xorm:"NOT NULL DEFAULT false"` //运营人员
IsOperator bool `xorm:"NOT NULL DEFAULT false"` //运营人员

// Avatar
Avatar string `xorm:"VARCHAR(2048) NOT NULL"`
@@ -929,8 +929,17 @@ var (
"template",
"user",
"vendor",
}
reservedUserPatterns = []string{"*.keys", "*.gpg"}
"dashbord",
"operation",
"blockchain",
"avatar",
"swagger.v1.json",
"secure",
"serviceworker.js",
"self",
"repo-avatars",
}
reservedUserPatterns = []string{"*.keys", "*.gpg", "*.png"}
)

// isUsableName checks if name is reserved or pattern of name is not allowed
@@ -1552,11 +1561,11 @@ func GetUserByActivateEmail(email string) (*User, error) {
if err := ctx.e.Join("INNER", "email_address", "email_address.uid = \"user\".id").
Where("email_address.email= ?", email).
Find(&users); err != nil {
return nil,err
return nil, err
}
if len(users) >= 1 {
return &users[0],nil
}else {
return &users[0], nil
} else {
// Finally, if email address is the protected email address:用户邮件地址设置为隐藏电子邮件地址
if strings.HasSuffix(email, fmt.Sprintf("@%s", setting.Service.NoReplyAddress)) {
username := strings.TrimSuffix(email, fmt.Sprintf("@%s", setting.Service.NoReplyAddress))
@@ -1572,6 +1581,7 @@ func GetUserByActivateEmail(email string) (*User, error) {
return nil, errors.New("cannot find user by email")
}
}

// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(email string) (*User, error) {
return GetUserByEmailContext(DefaultDBContext(), email)


+ 28
- 8
modules/cloudbrain/cloudbrain.go View File

@@ -29,9 +29,7 @@ var (
ResourceSpecs *models.ResourceSpecs
)

func isAdminOrOwnerOrJobCreater(ctx *context.Context, jobId string) bool {

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

if err != nil {
return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin()
@@ -41,9 +39,29 @@ func isAdminOrOwnerOrJobCreater(ctx *context.Context, jobId string) bool {

}

func isAdminOrJobCreater(ctx *context.Context, jobId string) bool {
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 {

return isAdminOrOwnerOrJobCreater(ctx, job, nil)
}

func CanCreateOrDebugJob(ctx *context.Context) bool {
return ctx.Repo.CanWrite(models.UnitTypeCloudBrain)
}

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

job, err := models.GetCloudbrainByJobID(jobId)
return isAdminOrJobCreater(ctx, job, nil)
}

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

if err != nil {
return ctx.IsUserSiteAdmin()
@@ -57,7 +75,9 @@ func AdminOrOwnerOrJobCreaterRight(ctx *context.Context) {

var jobID = ctx.Params(":jobid")

if !isAdminOrOwnerOrJobCreater(ctx, jobID) {
job, err := models.GetCloudbrainByJobID(jobID)

if !isAdminOrOwnerOrJobCreater(ctx, job, err) {

ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
}
@@ -67,8 +87,8 @@ func AdminOrOwnerOrJobCreaterRight(ctx *context.Context) {
func AdminOrJobCreaterRight(ctx *context.Context) {

var jobID = ctx.Params(":jobid")
if !isAdminOrJobCreater(ctx, jobID) {
job, err := models.GetCloudbrainByJobID(jobID)
if !isAdminOrJobCreater(ctx, job, err) {

ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
}


+ 4
- 2
routers/repo/cloudbrain.go View File

@@ -74,12 +74,13 @@ func CloudBrainIndex(ctx *context.Context) {
timestamp := time.Now().Unix()
for i, task := range ciTasks {
if task.Status == string(models.JobRunning) && (timestamp-int64(task.Cloudbrain.CreatedUnix) > 10) {
ciTasks[i].CanDebug = true
ciTasks[i].CanDebug = cloudbrain.CanCreateOrDebugJob(ctx)
} else {
ciTasks[i].CanDebug = false
}

ciTasks[i].CanDel = models.CanDelJob(ctx.IsSigned, ctx.User, task)
ciTasks[i].CanDel = cloudbrain.CanDeleteDebugJob(ctx, &task.Cloudbrain)

}

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
@@ -88,6 +89,7 @@ func CloudBrainIndex(ctx *context.Context) {

ctx.Data["PageIsCloudBrain"] = true
ctx.Data["Tasks"] = ciTasks
ctx.Data["CanCreate"] = cloudbrain.CanCreateOrDebugJob(ctx)
ctx.HTML(200, tplCloudBrainIndex)
}



+ 11
- 1
routers/repo/modelarts.go View File

@@ -11,6 +11,8 @@ import (
"strings"
"time"

"code.gitea.io/gitea/modules/cloudbrain"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/base"
@@ -68,10 +70,11 @@ func NotebookIndex(ctx *context.Context) {

for i, task := range ciTasks {
if task.Status == string(models.JobRunning) {
ciTasks[i].CanDebug = true
ciTasks[i].CanDebug = cloudbrain.CanCreateOrDebugJob(ctx)
} else {
ciTasks[i].CanDebug = false
}
ciTasks[i].CanDel = cloudbrain.CanDeleteDebugJob(ctx, &task.Cloudbrain)
}

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
@@ -80,6 +83,7 @@ func NotebookIndex(ctx *context.Context) {

ctx.Data["PageIsCloudBrain"] = true
ctx.Data["Tasks"] = ciTasks
ctx.Data["CanCreate"] = cloudbrain.CanCreateOrDebugJob(ctx)
ctx.HTML(200, tplModelArtsNotebookIndex)
}

@@ -301,12 +305,18 @@ func TrainJobIndex(ctx *context.Context) {
return
}

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

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager

ctx.Data["PageIsCloudBrain"] = true
ctx.Data["Tasks"] = tasks
ctx.Data["CanCreate"] = cloudbrain.CanCreateOrDebugJob(ctx)
ctx.HTML(200, tplModelArtsTrainJobIndex)
}



Loading…
Cancel
Save