fix: 解决本地运行环境网站被删除之后 误删其他应用的BUG (#566)

This commit is contained in:
zhengkunwang223 2023-04-10 17:32:22 +08:00 committed by GitHub
parent d00e5b0421
commit 12d010351a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 11 deletions

View file

@ -138,9 +138,7 @@ func (w WebsiteService) CreateWebsite(ctx context.Context, create request.Websit
Remark: create.Remark,
Status: constant.WebRunning,
ExpireDate: defaultDate,
AppInstallID: create.AppInstallID,
WebsiteGroupID: create.WebsiteGroupID,
RuntimeID: create.RuntimeID,
Protocol: constant.ProtocolHTTP,
Proxy: create.Proxy,
AccessLog: true,
@ -194,6 +192,7 @@ func (w WebsiteService) CreateWebsite(ctx context.Context, create request.Websit
if err != nil {
return err
}
website.RuntimeID = runtime.ID
if runtime.Resource == constant.ResourceAppstore {
var req request.AppInstallCreate
reg, _ := regexp.Compile(`[^a-z0-9_-]+`)
@ -313,11 +312,7 @@ func (w WebsiteService) DeleteWebsite(ctx context.Context, req request.WebsiteDe
return err
}
if req.DeleteApp {
websites, _ := websiteRepo.GetBy(websiteRepo.WithAppInstallId(website.AppInstallID))
if len(websites) > 1 {
return buserr.New(constant.ErrAppDelete)
}
if checkIsLinkApp(website) && req.DeleteApp {
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return err

View file

@ -493,3 +493,14 @@ func opWebsite(website *model.Website, operate string) error {
}
return nginxCheckAndReload(nginxInstall.SiteConfig.OldContent, config.FilePath, nginxInstall.Install.ContainerName)
}
func checkIsLinkApp(website model.Website) bool {
if website.Type == constant.Deployment {
return true
}
if website.Type == constant.Runtime {
runtime, _ := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID))
return runtime.Resource == constant.AppResourceRemote
}
return false
}

View file

@ -11,16 +11,17 @@
value: 'deployment',
},
{
label: i18n.global.t('website.static'),
value: 'static',
label: i18n.global.t('runtime.runtime'),
value: 'runtime',
},
{
label: i18n.global.t('website.proxy'),
value: 'proxy',
},
{
label: i18n.global.t('runtime.runtime'),
value: 'runtime',
label: i18n.global.t('website.static'),
value: 'static',
},
]"
:key="item.value"