From 04e41d90539d015811d95c745fd34e0ed37f5daf Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 9 Dec 2022 09:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=8F=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/ai_model_manage.go | 9 +++++---- routers/repo/ai_model_manage.go | 19 +++++++++++++++++++ .../local/modelmanage-local-create-1.vue | 13 ++++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/models/ai_model_manage.go b/models/ai_model_manage.go index 6f791010f..f6836781c 100644 --- a/models/ai_model_manage.go +++ b/models/ai_model_manage.go @@ -89,6 +89,7 @@ type AiModelQueryOptions struct { Type int Status int IsOnlyThisRepo bool + IsQueryPrivate bool } func (a *AiModelConvert) IsGpuTrainTask() bool { @@ -428,10 +429,10 @@ func QueryModel(opts *AiModelQueryOptions) ([]*AiModelManage, int64, error) { builder.Eq{"ai_model_manage.status": opts.Status}, ) } - if !opts.IsOnlyThisRepo { - orCon := builder.NewCond() - orCon = orCon.And(builder.Eq{"ai_model_manage.is_private": false}) - cond = cond.Or(orCon) + if !opts.IsQueryPrivate { + cond = cond.And( + builder.Eq{"ai_model_manage.is_private": false}, + ) } count, err := sess.Where(cond).Count(new(AiModelManage)) if err != nil { diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index f56b93355..63ef4bf80 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -1014,6 +1014,23 @@ func isCanDownload(ctx *context.Context, task *models.AiModelManage) bool { return false } +func isQueryPrivateModel(ctx *context.Context) bool { + if ctx.User == nil { + return false + } + isCollaborator, err := ctx.Repo.Repository.IsCollaborator(ctx.User.ID) + if err != nil { + log.Info("query error.") + } + if ctx.User.IsAdmin || isCollaborator { + return true + } + if ctx.Repo.IsOwner() { + return true + } + return false +} + func isCanDelete(ctx *context.Context, modelUserId int64) bool { if ctx.User == nil { return false @@ -1054,6 +1071,7 @@ func ShowModelPageInfo(ctx *context.Context) { if pageSize <= 0 { pageSize = setting.UI.IssuePagingNum } + isQueryPrivate := isQueryPrivateModel(ctx) repoId := ctx.Repo.Repository.ID Type := -1 modelResult, count, err := models.QueryModel(&models.AiModelQueryOptions{ @@ -1066,6 +1084,7 @@ func ShowModelPageInfo(ctx *context.Context) { New: MODEL_LATEST, IsOnlyThisRepo: true, Status: -1, + IsQueryPrivate: isQueryPrivate, }) if err != nil { ctx.ServerError("Cloudbrain", err) diff --git a/web_src/vuepages/pages/modelmanage/local/modelmanage-local-create-1.vue b/web_src/vuepages/pages/modelmanage/local/modelmanage-local-create-1.vue index 32c64d4c7..fbbdecfe2 100644 --- a/web_src/vuepages/pages/modelmanage/local/modelmanage-local-create-1.vue +++ b/web_src/vuepages/pages/modelmanage/local/modelmanage-local-create-1.vue @@ -90,7 +90,7 @@
- +
@@ -99,7 +99,7 @@
- +
@@ -152,7 +152,7 @@ export default { engine: '0', label: '', description: '', - isPrivate : 'false', + isPrivate : false, }, nameErr: false, isShowVersion: false, @@ -257,6 +257,13 @@ export default { this.state.label = data.label; this.state.description = data.description; this.state.isPrivate = data.isPrivate; + if(data.isPrivate){ + $('#isPrivate_true').attr("checked",true); + $('#isPrivate_false').attr("checked",false); + }else{ + $('#isPrivate_true').attr("checked",false); + $('#isPrivate_false').attr("checked",true); + } } }).catch(err => { this.loading = false;