mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
treewide: DeleteFailReason as an object with translated details
This commit is contained in:
+3
-1
@@ -16,6 +16,8 @@ package apis
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type ModelBaseDetails struct {
|
||||
@@ -26,7 +28,7 @@ type ModelBaseDetails struct {
|
||||
CanDelete bool `json:"can_delete"`
|
||||
|
||||
// 资源不能删除的原因
|
||||
DeleteFailReason string `json:"delete_fail_reason"`
|
||||
DeleteFailReason httperrors.Error `json:"delete_fail_reason"`
|
||||
|
||||
// 资源是否可以更新, 若为false,update_fail_reason会返回资源不能删除的原因
|
||||
// example: true
|
||||
|
||||
@@ -778,7 +778,7 @@ func getModelExtraDetails(item IModel, ctx context.Context, showReason bool) api
|
||||
if err != nil {
|
||||
out.CanDelete = false
|
||||
if showReason {
|
||||
out.DeleteFailReason = err.Error()
|
||||
out.DeleteFailReason = httperrors.NewErrorFromGeneralError(ctx, err)
|
||||
}
|
||||
}
|
||||
err = item.ValidateUpdateCondition(ctx)
|
||||
|
||||
@@ -368,17 +368,18 @@ func (man *SCommonAlertManager) FetchCustomizeColumns(
|
||||
alertRows := man.SAlertManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
for i := range rows {
|
||||
rows[i].AlertDetails = alertRows[i]
|
||||
rows[i], _ = objs[i].(*SCommonAlert).GetMoreDetails(rows[i])
|
||||
rows[i], _ = objs[i].(*SCommonAlert).GetMoreDetails(ctx, rows[i])
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
func (alert *SCommonAlert) validateDeleteCondition(out *monitor.CommonAlertDetails) {
|
||||
func (alert *SCommonAlert) validateDeleteCondition(ctx context.Context, out *monitor.CommonAlertDetails) {
|
||||
alert_type := alert.getAlertType()
|
||||
switch alert_type {
|
||||
case monitor.CommonAlertSystemAlertType:
|
||||
je := httperrors.NewInputParameterError("Cannot delete system alert")
|
||||
out.CanDelete = false
|
||||
out.DeleteFailReason = httperrors.NewInputParameterError("Cannot delete system alert").Error()
|
||||
out.DeleteFailReason = httperrors.NewErrorFromJCError(ctx, je)
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -398,8 +399,8 @@ func (alert *SCommonAlert) AllowDeleteItem(ctx context.Context, userCred mcclien
|
||||
}
|
||||
}
|
||||
|
||||
func (alert *SCommonAlert) GetMoreDetails(out monitor.CommonAlertDetails) (monitor.CommonAlertDetails, error) {
|
||||
alert.validateDeleteCondition(&out)
|
||||
func (alert *SCommonAlert) GetMoreDetails(ctx context.Context, out monitor.CommonAlertDetails) (monitor.CommonAlertDetails, error) {
|
||||
alert.validateDeleteCondition(ctx, &out)
|
||||
|
||||
var err error
|
||||
alertNotis, err := alert.GetNotifications()
|
||||
|
||||
Reference in New Issue
Block a user