diff --git a/models/cloudbrain.go b/models/cloudbrain.go index e28ba3ea5..b9f0d0b86 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -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 diff --git a/routers/org/setting.go b/routers/org/setting.go index 348d8cc8d..3213bf03d 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -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)