From 962cd3bbd5ef3168ad353e7c146a2c4129329104 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 13 Jan 2022 15:57:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/ai_model_manage.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index 16dcb0d12..3b85579d7 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -210,23 +210,10 @@ func DeleteModel(ctx *context.Context) { } } -func isCanDelete(ctx *context.Context, model *models.AiModelManage) bool { - if ctx.User == nil { - return false - } - if ctx.User.IsAdmin || ctx.User.ID == model.UserId { - return true - } - if ctx.Repo.IsOwner() { - return true - } - return false -} - func deleteModelByID(ctx *context.Context, id string) error { log.Info("delete model start. id=" + id) model, err := models.QueryModelById(id) - if !isCanDelete(ctx, model) { + if !isCanDelete(ctx, model.UserId) { return errors.New(ctx.Tr("repo.model_noright")) } if err == nil { @@ -439,7 +426,7 @@ func ShowSingleModel(ctx *context.Context) { userIds := make([]int64, len(models)) for i, model := range models { model.IsCanOper = isOper(ctx, model.UserId) - model.IsCanDelete = isCanDelete(ctx, model) + model.IsCanDelete = isCanDelete(ctx, model.UserId) userIds[i] = model.UserId } userNameMap := queryUserName(userIds) @@ -482,7 +469,7 @@ func ShowOneVersionOtherModel(ctx *context.Context) { userIds := make([]int64, len(aimodels)) for i, model := range aimodels { model.IsCanOper = isOper(ctx, model.UserId) - model.IsCanDelete = isCanDelete(ctx, model) + model.IsCanDelete = isCanDelete(ctx, model.UserId) userIds[i] = model.UserId } userNameMap := queryUserName(userIds) @@ -539,6 +526,19 @@ func isQueryRight(ctx *context.Context) bool { } } +func isCanDelete(ctx *context.Context, modelUserId int64) bool { + if ctx.User == nil { + return false + } + if ctx.User.IsAdmin || ctx.User.ID == modelUserId { + return true + } + if ctx.Repo.IsOwner() { + return true + } + return false +} + func isOper(ctx *context.Context, modelUserId int64) bool { if ctx.User == nil { return false