From ce3d878e8f3e55e1e0f3d2a417686adde5b508f0 Mon Sep 17 00:00:00 2001 From: zouap Date: Mon, 6 Dec 2021 15:24:23 +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 --- models/ai_model_manage.go | 1 + routers/repo/ai_model_manage.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/models/ai_model_manage.go b/models/ai_model_manage.go index 8f4fbd113..af96444ac 100644 --- a/models/ai_model_manage.go +++ b/models/ai_model_manage.go @@ -35,6 +35,7 @@ type AiModelManage struct { TrainTaskInfo string `xorm:"text NULL"` CreatedUnix timeutil.TimeStamp `xorm:"created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + IsCanOper bool } type AiModelQueryOptions struct { diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index c7a0891a6..b122ed460 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -404,7 +404,7 @@ func ShowModelTemplate(ctx *context.Context) { func isQueryRight(ctx *context.Context) bool { if ctx.Repo.Repository.IsPrivate { - if ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() { + if ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() || ctx.Repo.CanAccess(models.UnitTypeCloudBrain) { return true } return false @@ -413,6 +413,13 @@ func isQueryRight(ctx *context.Context) bool { } } +func isOper(ctx *context.Context, modelUserId int64) bool { + if ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() || ctx.User.ID == modelUserId { + return true + } + return false +} + func ShowModelPageInfo(ctx *context.Context) { log.Info("ShowModelInfo start.") if !isQueryRight(ctx) { @@ -439,6 +446,10 @@ func ShowModelPageInfo(ctx *context.Context) { return } + for _, model := range modelResult { + model.IsCanOper = isOper(ctx, model.UserId) + } + mapInterface := make(map[string]interface{}) mapInterface["data"] = modelResult mapInterface["count"] = count