Browse Source

增加协作者权限

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.12.1^2
zouap 2 years ago
parent
commit
04e41d9053
3 changed files with 34 additions and 7 deletions
  1. +5
    -4
      models/ai_model_manage.go
  2. +19
    -0
      routers/repo/ai_model_manage.go
  3. +10
    -3
      web_src/vuepages/pages/modelmanage/local/modelmanage-local-create-1.vue

+ 5
- 4
models/ai_model_manage.go View File

@@ -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 {


+ 19
- 0
routers/repo/ai_model_manage.go View File

@@ -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)


+ 10
- 3
web_src/vuepages/pages/modelmanage/local/modelmanage-local-create-1.vue View File

@@ -90,7 +90,7 @@
<div class="r-title"><label>{{ $t('modelManage.modelAccess') }}</label></div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="isPrivate" checked="checked" value="false">
<input id="isPrivate_false" type="radio" name="isPrivate" checked="checked" value="false">
<label>{{ $t('modelManage.modelAccessPublic') }}</label>
</div>
</div>
@@ -99,7 +99,7 @@
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="isPrivate" value="true">
<input id="isPrivate_true" type="radio" name="isPrivate" value="true">
<label>{{ $t('modelManage.modelAccessPrivate') }}</label>
</div>
</div>
@@ -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;


Loading…
Cancel
Save