diff --git a/backend/app/api/v1/website_ssl.go b/backend/app/api/v1/website_ssl.go index cf8ed2436..177555dbf 100644 --- a/backend/app/api/v1/website_ssl.go +++ b/backend/app/api/v1/website_ssl.go @@ -132,17 +132,17 @@ func (b *BaseApi) GetDNSResolve(c *gin.Context) { // @Summary Delete website ssl // @Description 删除网站 ssl // @Accept json -// @Param request body request.WebsiteResourceReq true "request" +// @Param request body request.WebsiteBatchDelReq true "request" // @Success 200 // @Security ApiKeyAuth // @Router /websites/ssl/del [post] -// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"website_ssls","output_column":"primary_domain","output_value":"domain"}],"formatZH":"删除 ssl [domain]","formatEN":"Delete ssl [domain]"} +// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"website_ssls","output_column":"primary_domain","output_value":"domain"}],"formatZH":"删除 ssl [domain]","formatEN":"Delete ssl [domain]"} func (b *BaseApi) DeleteWebsiteSSL(c *gin.Context) { - var req request.WebsiteResourceReq + var req request.WebsiteBatchDelReq if err := helper.CheckBindAndValidate(&req, c); err != nil { return } - if err := websiteSSLService.Delete(req.ID); err != nil { + if err := websiteSSLService.Delete(req.IDs); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } diff --git a/backend/app/dto/request/website_ssl.go b/backend/app/dto/request/website_ssl.go index 2ed411156..3a1535fb0 100644 --- a/backend/app/dto/request/website_ssl.go +++ b/backend/app/dto/request/website_ssl.go @@ -58,6 +58,10 @@ type WebsiteResourceReq struct { ID uint `json:"id" validate:"required"` } +type WebsiteBatchDelReq struct { + IDs []uint `json:"ids" validate:"required"` +} + type WebsiteSSLUpdate struct { ID uint `json:"id" validate:"required"` AutoRenew bool `json:"autoRenew"` diff --git a/backend/app/service/website_ca.go b/backend/app/service/website_ca.go index ac57d30d4..8a7577599 100644 --- a/backend/app/service/website_ca.go +++ b/backend/app/service/website_ca.go @@ -149,6 +149,7 @@ func (w WebsiteCAService) GetCA(id uint) (response.WebsiteCADTO, error) { } func (w WebsiteCAService) Delete(id uint) error { + return websiteCARepo.DeleteBy(commonRepo.WithByID(id)) } diff --git a/backend/app/service/website_ssl.go b/backend/app/service/website_ssl.go index 7a80a35d3..1aba60e61 100644 --- a/backend/app/service/website_ssl.go +++ b/backend/app/service/website_ssl.go @@ -38,7 +38,7 @@ type IWebsiteSSLService interface { Renew(sslId uint) error GetDNSResolve(req request.WebsiteDNSReq) ([]response.WebsiteDNSRes, error) GetWebsiteSSL(websiteId uint) (response.WebsiteSSLDTO, error) - Delete(id uint) error + Delete(ids []uint) error Update(update request.WebsiteSSLUpdate) error Upload(req request.WebsiteSSLUpload) error ObtainSSL(apply request.WebsiteSSLApply) error @@ -299,6 +299,8 @@ func (w WebsiteSSLService) Renew(sslId uint) error { if err := client.UseHTTP(path.Join(constant.AppInstallDir, constant.AppOpenresty, appInstall.Name, "root")); err != nil { return err } + case constant.SelfSigned: + } resource, err := client.RenewSSL(websiteSSL.CertURL) @@ -380,11 +382,23 @@ func (w WebsiteSSLService) GetWebsiteSSL(websiteId uint) (response.WebsiteSSLDTO return res, nil } -func (w WebsiteSSLService) Delete(id uint) error { - if websites, _ := websiteRepo.GetBy(websiteRepo.WithWebsiteSSLID(id)); len(websites) > 0 { - return buserr.New(constant.ErrSSLCannotDelete) +func (w WebsiteSSLService) Delete(ids []uint) error { + var names []string + for _, id := range ids { + if websites, _ := websiteRepo.GetBy(websiteRepo.WithWebsiteSSLID(id)); len(websites) > 0 { + oldSSL, _ := websiteSSLRepo.GetFirst(commonRepo.WithByID(id)) + if oldSSL.ID > 0 { + names = append(names, oldSSL.PrimaryDomain) + } + continue + } else { + _ = websiteSSLRepo.DeleteBy(commonRepo.WithByID(id)) + } } - return websiteSSLRepo.DeleteBy(commonRepo.WithByID(id)) + if len(names) > 0 { + return buserr.WithName("ErrSSLCannotDelete", strings.Join(names, ",")) + } + return nil } func (w WebsiteSSLService) Update(update request.WebsiteSSLUpdate) error { diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index 1c9426229..9f2c19b3e 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -85,7 +85,7 @@ ErrDomainIsUsed: "Domain is already used by website {{ .name }}" ErrDomainFormat: "{{ .name }} domain format error" #ssl -ErrSSLCannotDelete: "The certificate is being used by the website and cannot be removed" +ErrSSLCannotDelete: "The certificate {{ .name }} is being used by the website and cannot be removed" ErrAccountCannotDelete: "The certificate associated with the account cannot be deleted" ErrSSLApply: "The certificate continues to be signed successfully, but openresty reload fails, please check the configuration!" ErrEmailIsExist: 'Email is already exist' diff --git a/backend/i18n/lang/zh-Hant.yaml b/backend/i18n/lang/zh-Hant.yaml index aaee15f60..5d9c591ff 100644 --- a/backend/i18n/lang/zh-Hant.yaml +++ b/backend/i18n/lang/zh-Hant.yaml @@ -85,7 +85,7 @@ ErrDomainIsUsed: "域名已被網站【{{ .name }}】使用" ErrDomainFormat: "{{ .name }} 域名格式不正確" #ssl -ErrSSLCannotDelete: "證書正在被網站使用,無法刪除" +ErrSSLCannotDelete: "{{ .name }} 證書正在被網站使用,無法刪除" ErrAccountCannotDelete: "帳號關聯證書,無法刪除" ErrSSLApply: "證書續簽成功,openresty reload失敗,請檢查配置!" ErrEmailIsExist: '郵箱已存在' diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index 411cdf2cc..a65b08d00 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -85,7 +85,7 @@ ErrDomainIsUsed: "域名已被网站【{{ .name }}】使用" ErrDomainFormat: "{{ .name }} 域名格式不正确" #ssl -ErrSSLCannotDelete: "证书正在被网站使用,无法删除" +ErrSSLCannotDelete: "{{ .name }} 证书正在被网站使用,无法删除" ErrAccountCannotDelete: "账号关联证书,无法删除" ErrSSLApply: "证书续签成功,openresty reload失败,请检查配置!" ErrEmailIsExist: '邮箱已存在' diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index f086fade6..ea118b48a 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1,5 +1,5 @@ -// Code generated by swaggo/swag. DO NOT EDIT. - +// Package docs GENERATED BY SWAG; DO NOT EDIT +// This file was generated by swaggo/swag package docs import "github.com/swaggo/swag" @@ -12850,7 +12850,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.WebsiteResourceReq" + "$ref": "#/definitions/request.WebsiteBatchDelReq" } } ], @@ -12864,14 +12864,14 @@ const docTemplate = `{ { "db": "website_ssls", "input_column": "id", - "input_value": "id", - "isList": false, + "input_value": "ids", + "isList": true, "output_column": "primary_domain", "output_value": "domain" } ], "bodyKeys": [ - "id" + "ids" ], "formatEN": "Delete ssl [domain]", "formatZH": "删除 ssl [domain]", @@ -18907,6 +18907,20 @@ const docTemplate = `{ } } }, + "request.WebsiteBatchDelReq": { + "type": "object", + "required": [ + "ids" + ], + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.WebsiteCACreate": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 0a52636b0..f1d598250 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -12843,7 +12843,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.WebsiteResourceReq" + "$ref": "#/definitions/request.WebsiteBatchDelReq" } } ], @@ -12857,14 +12857,14 @@ { "db": "website_ssls", "input_column": "id", - "input_value": "id", - "isList": false, + "input_value": "ids", + "isList": true, "output_column": "primary_domain", "output_value": "domain" } ], "bodyKeys": [ - "id" + "ids" ], "formatEN": "Delete ssl [domain]", "formatZH": "删除 ssl [domain]", @@ -18900,6 +18900,20 @@ } } }, + "request.WebsiteBatchDelReq": { + "type": "object", + "required": [ + "ids" + ], + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.WebsiteCACreate": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index e88c98a30..5a4a1d49d 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -3724,6 +3724,15 @@ definitions: - keyType - type type: object + request.WebsiteBatchDelReq: + properties: + ids: + items: + type: integer + type: array + required: + - ids + type: object request.WebsiteCACreate: properties: city: @@ -12840,7 +12849,7 @@ paths: name: request required: true schema: - $ref: '#/definitions/request.WebsiteResourceReq' + $ref: '#/definitions/request.WebsiteBatchDelReq' responses: "200": description: OK @@ -12853,12 +12862,12 @@ paths: BeforeFunctions: - db: website_ssls input_column: id - input_value: id - isList: false + input_value: ids + isList: true output_column: primary_domain output_value: domain bodyKeys: - - id + - ids formatEN: Delete ssl [domain] formatZH: 删除 ssl [domain] paramKeys: [] diff --git a/frontend/src/components/del-dialog/index.vue b/frontend/src/components/del-dialog/index.vue index 262f8556e..ffc777327 100644 --- a/frontend/src/components/del-dialog/index.vue +++ b/frontend/src/components/del-dialog/index.vue @@ -1,6 +1,6 @@