Browse Source

fix-1941

tags/v1.22.5.2^2
liuzx 4 years ago
parent
commit
de5819675f
2 changed files with 17 additions and 0 deletions
  1. +5
    -0
      models/cloudbrain.go
  2. +12
    -0
      routers/org/setting.go

+ 5
- 0
models/cloudbrain.go View File

@@ -1566,6 +1566,11 @@ func GetCloudbrainCountByUserID(userID int64, jobType string) (int, error) {
return int(count), err
}

func GetCloudbrainRunCountByUserID(userID int64) (int, error) {
count, err := x.In("status", JobWaiting, JobRunning).And("user_id = ?", userID).Count(new(Cloudbrain))
return int(count), err
}

func GetBenchmarkCountByUserID(userID int64) (int, error) {
count, err := x.In("status", JobWaiting, JobRunning).And("(job_type = ? or job_type = ? or job_type = ?) and user_id = ? and type = ?", string(JobTypeBenchmark), string(JobTypeBrainScore), string(JobTypeSnn4imagenet), userID, TypeCloudBrainOne).Count(new(Cloudbrain))
return int(count), err


+ 12
- 0
routers/org/setting.go View File

@@ -73,6 +73,18 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
ctx.Org.OrgLink = setting.AppSubURL + "/org/" + form.Name
log.Trace("Organization name changed: %s -> %s", org.Name, form.Name)
}

count, err := models.GetCloudbrainRunCountByUserID(ctx.User.ID)
if err != nil {
ctx.ServerError("GetCloudbrainCountByUserID failed", err)
return
} else {
if count >= 1 {
log.Error("the user already has running or waiting task", ctx.Data["MsgID"])
ctx.RenderWithErr(ctx.Tr("The cloudbrain tasks needs to be stopped before you delete the project"), tplSettingsOptions, &form)
return
}
}
// In case it's just a case change.
org.Name = form.Name
org.LowerName = strings.ToLower(form.Name)


Loading…
Cancel
Save