Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.1.2
zouap 4 years ago
parent
commit
962cd3bbd5
1 changed files with 16 additions and 16 deletions
  1. +16
    -16
      routers/repo/ai_model_manage.go

+ 16
- 16
routers/repo/ai_model_manage.go View File

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


Loading…
Cancel
Save