fix: 限制应用安装修改

This commit is contained in:
zhengkunwang223 2022-12-01 16:45:00 +08:00 committed by zhengkunwang223
parent 6d9217d419
commit 2e6e7b5eb7
9 changed files with 47 additions and 7 deletions

View file

@ -23,6 +23,7 @@ type AppDTO struct {
type AppDetailDTO struct {
model.AppDetail
Enable bool `json:"enable"`
Params interface{} `json:"params"`
}

View file

@ -124,6 +124,16 @@ func (a AppService) GetAppDetail(appId uint, version string) (dto.AppDetailDTO,
_ = json.Unmarshal([]byte(detail.Params), &paramMap)
appDetailDTO.AppDetail = detail
appDetailDTO.Params = paramMap
appDetailDTO.Enable = true
app, err := appRepo.GetFirst(commonRepo.WithByID(detail.AppId))
if err != nil {
return appDetailDTO, err
}
if err := checkLimit(app); err != nil {
appDetailDTO.Enable = false
}
return appDetailDTO, nil
}

View file

@ -347,17 +347,24 @@ func getContainerNames(install model.AppInstall) ([]string, error) {
return containerNames, nil
}
func checkRequiredAndLimit(app model.App) error {
func checkLimit(app model.App) error {
if app.Limit > 0 {
installs, err := appInstallRepo.GetBy(appInstallRepo.WithAppId(app.ID))
if err != nil {
return err
}
if len(installs) >= app.Limit {
return errors.New(fmt.Sprintf("app install limit %d", app.Limit))
return buserr.New(constant.ErrAppLimit, "", nil)
}
}
return nil
}
func checkRequiredAndLimit(app model.App) error {
if err := checkLimit(app); err != nil {
return err
}
if app.Required != "" {
var requiredArray []string
@ -383,7 +390,7 @@ func checkRequiredAndLimit(app model.App) error {
_, err = appInstallRepo.GetFirst(appInstallRepo.WithDetailIdsIn(detailIds))
if err != nil {
return errors.New(fmt.Sprintf("%s is required", requireApp.Key))
return buserr.New(constant.ErrAppRequired, requireApp.Name, nil)
}
}
}

View file

@ -44,5 +44,7 @@ var (
// app
var (
ErrPortInUsed = "ErrPortInUsed"
ErrPortInUsed = "ErrPortInUsed"
ErrAppLimit = "ErrAppLimit"
ErrAppRequired = "ErrAppRequired"
)

View file

@ -15,4 +15,6 @@ ErrNotSupportType: "The system does not support the current type: {{ .detail }}"
#app
ErrPortInUsed: "{{ .detail }} 端口已被占用"
ErrPortInUsed: "{{ .detail }} port already in use"
ErrAppLimit: "App exceeds install limit"
ErrAppRequired: "{{ .detail }} app is required"

View file

@ -16,3 +16,5 @@ ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}"
#app
ErrPortInUsed: "{{ .detail }} 已被占用!"
ErrAppLimit: "应用超出安装数量限制"
ErrAppRequired: "请先安装 {{ .detail }} 应用"

View file

@ -36,6 +36,7 @@ export namespace App {
readme: string;
params: AppParams;
dockerCompose: string;
enbale: boolean;
}
export interface AppReq extends ReqPage {

View file

@ -732,6 +732,7 @@ export default {
checkInstalledWarn: '未检测到 {0} ,请进入应用商店点击安装!',
gotoInstalled: '去安装',
search: '搜索',
limitHelper: '该应用已安装不支持重复安装',
},
website: {
website: '网站',

View file

@ -42,7 +42,21 @@
<el-descriptions-item :label="$t('app.author')">{{ app.author }}</el-descriptions-item>
</el-descriptions>
<div>
<el-button @click="openInstall" type="primary">{{ $t('app.install') }}</el-button>
<el-button :disabled="!appDetail.enable" @click="openInstall" type="primary">
{{ $t('app.install') }}
</el-button>
</div>
<br />
<div>
<el-alert
style="width: 300px"
v-if="!appDetail.enable"
:title="$t('app.limitHelper')"
type="warning"
show-icon
:closable="false"
/>
<!-- <span v-if="!appDetail.enable">{{ $t('app.limitHelper') }}</span> -->
</div>
</div>
</el-col>