| @@ -33,7 +33,7 @@ type AiModelManage struct { | |||
| CodeBranch string `xorm:"varchar(400) NULL" json:"codeBranch"` | |||
| CodeCommitID string `xorm:"NULL" json:"codeCommitID"` | |||
| UserId int64 `xorm:"NOT NULL" json:"userId"` | |||
| IsPrivate bool `xorm:"DEFAULT false" json:"isPrivate"` | |||
| IsPrivate bool `xorm:"DEFAULT true" json:"isPrivate"` | |||
| UserName string `json:"userName"` | |||
| UserRelAvatarLink string `json:"userRelAvatarLink"` | |||
| TrainTaskInfo string `xorm:"text NULL" json:"trainTaskInfo"` | |||
| @@ -41,6 +41,7 @@ type AiModelManage struct { | |||
| UpdatedUnix timeutil.TimeStamp `xorm:"updated" json:"updatedUnix"` | |||
| IsCanOper bool `json:"isCanOper"` | |||
| IsCanDelete bool `json:"isCanDelete"` | |||
| IsCanDownload bool `json:"isCanDownload"` | |||
| } | |||
| type AiModelConvert struct { | |||
| @@ -620,7 +620,7 @@ func ShowModelConvertInfo(ctx *context.Context) { | |||
| return | |||
| } | |||
| ctx.Data["Name"] = job.Name | |||
| ctx.Data["canDownload"] = isOper(ctx, job.UserId) | |||
| ctx.Data["canDownload"] = isOperModifyOrDelete(ctx, job.UserId) | |||
| user, err := models.GetUserByID(job.UserId) | |||
| if err == nil { | |||
| job.UserName = user.Name | |||
| @@ -755,7 +755,7 @@ func GetModelConvertPageData(ctx *context.Context) ([]*models.AiModelConvert, in | |||
| } | |||
| userIds := make([]int64, len(modelResult)) | |||
| for i, model := range modelResult { | |||
| model.IsCanOper = isOper(ctx, model.UserId) | |||
| model.IsCanOper = isOperModifyOrDelete(ctx, model.UserId) | |||
| model.IsCanDelete = isCanDelete(ctx, model.UserId) | |||
| userIds[i] = model.UserId | |||
| } | |||
| @@ -581,7 +581,7 @@ func DownloadMultiModelFile(ctx *context.Context) { | |||
| ctx.ServerError("no such model:", err) | |||
| return | |||
| } | |||
| if !isOper(ctx, task.UserId) { | |||
| if !isCanDownload(ctx, task) { | |||
| ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
| return | |||
| } | |||
| @@ -809,7 +809,7 @@ func DownloadSingleModelFile(ctx *context.Context) { | |||
| ctx.ServerError("no such model:", err) | |||
| return | |||
| } | |||
| if !isOper(ctx, task.UserId) { | |||
| if !isCanDownload(ctx, task) { | |||
| ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
| return | |||
| } | |||
| @@ -877,8 +877,9 @@ func QueryModelById(ctx *context.Context) { | |||
| id := ctx.Query("id") | |||
| model, err := models.QueryModelById(id) | |||
| if err == nil { | |||
| model.IsCanOper = isOper(ctx, model.UserId) | |||
| model.IsCanOper = isOperModifyOrDelete(ctx, model.UserId) | |||
| model.IsCanDelete = isCanDelete(ctx, model.UserId) | |||
| model.IsCanDownload = isCanDownload(ctx, model) | |||
| removeIpInfo(model) | |||
| ctx.JSON(http.StatusOK, model) | |||
| } else { | |||
| @@ -894,7 +895,8 @@ func ShowSingleModel(ctx *context.Context) { | |||
| userIds := make([]int64, len(models)) | |||
| for i, model := range models { | |||
| model.IsCanOper = isOper(ctx, model.UserId) | |||
| model.IsCanOper = isOperModifyOrDelete(ctx, model.UserId) | |||
| model.IsCanDownload = isCanDownload(ctx, model) | |||
| model.IsCanDelete = isCanDelete(ctx, model.UserId) | |||
| userIds[i] = model.UserId | |||
| } | |||
| @@ -944,7 +946,8 @@ func ShowOneVersionOtherModel(ctx *context.Context) { | |||
| userIds := make([]int64, len(aimodels)) | |||
| for i, model := range aimodels { | |||
| model.IsCanOper = isOper(ctx, model.UserId) | |||
| model.IsCanOper = isOperModifyOrDelete(ctx, model.UserId) | |||
| model.IsCanDownload = isCanDownload(ctx, model) | |||
| model.IsCanDelete = isCanDelete(ctx, model.UserId) | |||
| userIds[i] = model.UserId | |||
| } | |||
| @@ -1004,6 +1007,19 @@ func isQueryRight(ctx *context.Context) bool { | |||
| } | |||
| } | |||
| func isCanDownload(ctx *context.Context, task *models.AiModelManage) bool { | |||
| if ctx.User == nil { | |||
| return false | |||
| } | |||
| if ctx.User.IsAdmin || ctx.User.ID == task.UserId { | |||
| return true | |||
| } | |||
| if !task.IsPrivate { | |||
| return true | |||
| } | |||
| return false | |||
| } | |||
| func isCanDelete(ctx *context.Context, modelUserId int64) bool { | |||
| if ctx.User == nil { | |||
| return false | |||
| @@ -1017,7 +1033,7 @@ func isCanDelete(ctx *context.Context, modelUserId int64) bool { | |||
| return false | |||
| } | |||
| func isOper(ctx *context.Context, modelUserId int64) bool { | |||
| func isOperModifyOrDelete(ctx *context.Context, modelUserId int64) bool { | |||
| if ctx.User == nil { | |||
| return false | |||
| } | |||
| @@ -1060,8 +1076,9 @@ func ShowModelPageInfo(ctx *context.Context) { | |||
| userIds := make([]int64, len(modelResult)) | |||
| for i, model := range modelResult { | |||
| model.IsCanOper = isOper(ctx, model.UserId) | |||
| model.IsCanOper = isOperModifyOrDelete(ctx, model.UserId) | |||
| model.IsCanDelete = isCanDelete(ctx, model.UserId) | |||
| model.IsCanDownload = isCanDownload(ctx, model) | |||
| userIds[i] = model.UserId | |||
| } | |||
| @@ -1105,7 +1122,7 @@ func ModifyModelInfo(ctx *context.Context) { | |||
| ctx.JSON(200, re) | |||
| return | |||
| } | |||
| if !isOper(ctx, task.UserId) { | |||
| if !isOperModifyOrDelete(ctx, task.UserId) { | |||
| re["msg"] = "No right to operation." | |||
| ctx.JSON(200, re) | |||
| return | |||
| @@ -157,12 +157,12 @@ | |||
| :class="{ disabled: !scope.row.isCanOper }" | |||
| >{{ i18n.modify }}</a> | |||
| <a class="op-btn" v-show="scope.row.modelType != 1" style="color:transparent;cursor:default;" >{{ i18n.modify }}</a> | |||
| <a class="op-btn" v-show="repoIsPrivate == false && scope.row.isPrivate==true">>{{ i18n.modelaccess_setpublic }}</a> | |||
| <a class="op-btn" v-show="repoIsPrivate == false && scope.row.isPrivate==false">>{{ i18n.modelaccess_setprivate }}</a> | |||
| <a class="op-btn" v-show="repoIsPrivate == false && scope.row.isPrivate==true && scope.row.isCanOper">>{{ i18n.modelaccess_setpublic }}</a> | |||
| <a class="op-btn" v-show="repoIsPrivate == false && scope.row.isPrivate==false && scope.row.isCanOper">>{{ i18n.modelaccess_setprivate }}</a> | |||
| <a class="op-btn" | |||
| :href="loadhref + scope.row.id" | |||
| :class="{ disabled: !scope.row.isCanOper }" | |||
| :class="{ disabled: !scope.row.isCanDownload }" | |||
| >{{ i18n.model_download }}</a> | |||
| <a class="op-btn" | |||
| :class="{ disabled: !scope.row.isCanDelete }" | |||
| @@ -182,8 +182,8 @@ | |||
| <span>{{ scope.row.FileName }}</span> | |||
| </div> | |||
| </a> | |||
| <a v-else :class="!canOperate ? 'disabled-download' : ''" | |||
| :href="canOperate ? `${repo}/modelmanage/${state.id}/downloadsingle?parentDir=${filePath.length > 1 ? encodeURIComponent(filePath.map(item => item.path).join('/').slice(1) + '/') : ''}&fileName=${scope.row.FileName}` : 'javascript:;'"> | |||
| <a v-else :class="!canDownload ? 'disabled-download' : ''" | |||
| :href="canDownload ? `${repo}/modelmanage/${state.id}/downloadsingle?parentDir=${filePath.length > 1 ? encodeURIComponent(filePath.map(item => item.path).join('/').slice(1) + '/') : ''}&fileName=${scope.row.FileName}` : 'javascript:;'"> | |||
| <div class="fitted" :title="scope.row.FileName"> | |||
| <i class="icon file" width="16" height="16" aria-hidden="true"></i> | |||
| <span>{{ scope.row.FileName }}</span> | |||
| @@ -228,6 +228,7 @@ export default { | |||
| return { | |||
| modelType: '0', // 1-本地, 0-线上 | |||
| canOperate: false, | |||
| canDownload:false, | |||
| canDelete: false, | |||
| isExpanded: false, | |||
| loading: false, | |||
| @@ -291,6 +292,7 @@ export default { | |||
| const data = this.modelList.filter((model) => model.version == version)[0]; | |||
| this.modelType = data.modelType; | |||
| this.canOperate = data.isCanOper; | |||
| this.canDownload = data.isCanDownload; | |||
| this.canDelete = data.isCanDelete; | |||
| this.state.type = data.type; | |||
| this.state.typeStr = data.type == 0 ? 'CPU/GPU' : data.type == 1 ? 'NPU' : ''; | |||