mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #355 in YUNIONIO/onecloud from ~QIUJIAN/onecloud:hotfix/qj-resolve-conflict-20180824-2.2.0 to release/2.2.0
* commit '3ac638239b9d711d988d1664c67c79e9161e37b5': 修正:保护系统默认创建的default资源,不允许删除
This commit is contained in:
@@ -57,6 +57,9 @@ func (self *SCloudregion) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if self.GetZoneCount() > 0 || self.GetVpcCount() > 0 {
|
||||
return httperrors.NewNotEmptyError("not empty cloud region")
|
||||
}
|
||||
if self.Id == "default" {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default cloud region")
|
||||
}
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -367,3 +367,14 @@ func (manager *SSecurityGroupManager) InitializeData() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
cnt := self.GetGuestsCount()
|
||||
if cnt > 0 {
|
||||
return httperrors.NewNotEmptyError("the security group is in use")
|
||||
}
|
||||
if self.Id == "default" {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default security group")
|
||||
}
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ func (self *SVpc) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if self.GetNetworkCount() > 0 {
|
||||
return httperrors.NewNotEmptyError("VPC not empty")
|
||||
}
|
||||
if self.Id == "default" {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default vpc")
|
||||
}
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -198,3 +198,8 @@ func NewGeneralError(err error) *httputils.JSONClientError {
|
||||
return NewInternalServerError(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func NewProtectedResourceError(msg string, params ...interface{}) *httputils.JSONClientError {
|
||||
msg, err := errorMessage(msg, params...)
|
||||
return NewJsonClientError(403, "ProtectedResourceError(", msg, err)
|
||||
}
|
||||
|
||||
@@ -98,3 +98,7 @@ func OutOfQuotaError(w http.ResponseWriter, msg string, params ...interface{}) {
|
||||
func TimeoutError(w http.ResponseWriter, msg string, params ...interface{}) {
|
||||
JsonClientError(w, NewTimeoutError(msg, params...))
|
||||
}
|
||||
|
||||
func ProtectedResourceError(w http.ResponseWriter, msg string, params ...interface{}) {
|
||||
JsonClientError(w, NewProtectedResourceError(msg, params...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user