1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-16 18:54:43 +08:00

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 { type AppDetailDTO struct {
model.AppDetail model.AppDetail
Enable bool `json:"enable"`
Params interface{} `json:"params"` 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) _ = json.Unmarshal([]byte(detail.Params), &paramMap)
appDetailDTO.AppDetail = detail appDetailDTO.AppDetail = detail
appDetailDTO.Params = paramMap 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 return appDetailDTO, nil
} }

View File

@ -347,17 +347,24 @@ func getContainerNames(install model.AppInstall) ([]string, error) {
return containerNames, nil return containerNames, nil
} }
func checkRequiredAndLimit(app model.App) error { func checkLimit(app model.App) error {
if app.Limit > 0 { if app.Limit > 0 {
installs, err := appInstallRepo.GetBy(appInstallRepo.WithAppId(app.ID)) installs, err := appInstallRepo.GetBy(appInstallRepo.WithAppId(app.ID))
if err != nil { if err != nil {
return err return err
} }
if len(installs) >= app.Limit { 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 != "" { if app.Required != "" {
var requiredArray []string var requiredArray []string
@ -383,7 +390,7 @@ func checkRequiredAndLimit(app model.App) error {
_, err = appInstallRepo.GetFirst(appInstallRepo.WithDetailIdsIn(detailIds)) _, err = appInstallRepo.GetFirst(appInstallRepo.WithDetailIdsIn(detailIds))
if err != nil { 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 // app
var ( 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 #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 #app
ErrPortInUsed: "{{ .detail }} 已被占用!" ErrPortInUsed: "{{ .detail }} 已被占用!"
ErrAppLimit: "应用超出安装数量限制"
ErrAppRequired: "请先安装 {{ .detail }} 应用"

View File

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

View File

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

View File

@ -42,7 +42,21 @@
<el-descriptions-item :label="$t('app.author')">{{ app.author }}</el-descriptions-item> <el-descriptions-item :label="$t('app.author')">{{ app.author }}</el-descriptions-item>
</el-descriptions> </el-descriptions>
<div> <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>
</div> </div>
</el-col> </el-col>