You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/api/policy/del.go

36 lines
786 B
Go

//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//
package policy
import (
"github.com/veypi/vbase/cfg"
"github.com/veypi/vbase/models"
"github.com/veypi/vigo"
)
type DeleteRequest struct {
PolicyID string `src:"path@policy_id" desc:"策略ID"`
}
func del(x *vigo.X, req *DeleteRequest) error {
var policy models.Policy
if err := cfg.DB().First(&policy, "id = ?", req.PolicyID).Error; err != nil {
return vigo.ErrNotFound
}
// 系统策略不允许删除
if policy.Scope == models.PolicyScopePlatform {
return vigo.ErrForbidden.WithString("system policies cannot be deleted")
}
if err := cfg.DB().Delete(&policy).Error; err != nil {
return vigo.ErrInternalServer.WithError(err)
}
return nil
}