Skip to content

Commit

Permalink
feat: 证书未删除禁止删除网站
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Nov 5, 2023
1 parent 0a3573b commit a347b54
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/models/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ type Website struct {
Remark string `gorm:"default:''" json:"remark"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`

Cert *Cert `gorm:"foreignKey:WebsiteID" json:"cert"`
}
6 changes: 5 additions & 1 deletion app/services/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,14 @@ server
// Delete 删除网站
func (r *WebsiteImpl) Delete(id int) error {
var website models.Website
if err := facades.Orm().Query().Where("id", id).FirstOrFail(&website); err != nil {
if err := facades.Orm().Query().With("Cert").Where("id", id).FirstOrFail(&website); err != nil {
return err
}

if website.Cert != nil {
return errors.New("网站" + website.Name + "已绑定SSL证书,请先删除证书")
}

if _, err := facades.Orm().Query().Delete(&website); err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,6 @@ github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c h1:obhFK91
github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c/go.mod h1:YSWsLXlG16u5CWFaXNZHhEQD10+NwF3xfgDV816OwLE=
github.com/goravel/file-rotatelogs/v2 v2.4.1 h1:ogkeIFcTHSBRUBpZYiyJbpul8hkVXxHPuDbOaP78O1M=
github.com/goravel/file-rotatelogs/v2 v2.4.1/go.mod h1:euk9qr52WrzM8ICs1hecFcR4CZ/ZZOPdacHfvHgbOf0=
github.com/goravel/framework v1.13.1-0.20231104153423-7bfd9573b12d h1:20bsAUUZWGcB8LvCP3nbO+fxGPuwYITiUJGnyx2xUgQ=
github.com/goravel/framework v1.13.1-0.20231104153423-7bfd9573b12d/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ=
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1 h1:Bi86UTQtrQIo74ler6NbbXTy0dOGGZaNwtRcBOuZom8=
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
Expand Down

0 comments on commit a347b54

Please sign in to comment.