优化结构
This commit is contained in:
@@ -33,6 +33,10 @@ func Migrations() []migration.Step {
|
||||
}
|
||||
}
|
||||
|
||||
// Kept as a migration version for existing installations; the canonical
|
||||
// communication surface seeder is idempotent and now owns the test endpoint.
|
||||
func ensureCommunicationTestSurface(db *gorm.DB) error { return ensureCommunicationSurface(db) }
|
||||
|
||||
func ensureCommunicationSurface(db *gorm.DB) error {
|
||||
if db == nil || !db.Migrator().HasTable(&menuPO{}) || !db.Migrator().HasTable(&apiPO{}) {
|
||||
return nil
|
||||
@@ -128,47 +132,3 @@ func ensureCommunicationSurface(db *gorm.DB) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func ensureCommunicationTestSurface(db *gorm.DB) error {
|
||||
if db == nil || !db.Migrator().HasTable(&menuPO{}) || !db.Migrator().HasTable(&apiPO{}) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
var existingMenus int64
|
||||
if err := tx.Model(&menuPO{}).Where("name IN ?", []string{"extensions", "integrationConfig"}).Count(&existingMenus).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if existingMenus == 0 {
|
||||
return nil
|
||||
}
|
||||
api := apiPO{
|
||||
Path: "/integration/configs/:kind/:provider/test",
|
||||
Method: "POST",
|
||||
APIGroup: "集成配置",
|
||||
Description: "测试通信集成连接",
|
||||
}
|
||||
if err := tx.Where("path = ? AND method = ?", api.Path, api.Method).FirstOrCreate(&api).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !tx.Migrator().HasTable(&authorityPO{}) || !tx.Migrator().HasTable(&casbinRulePO{}) {
|
||||
return nil
|
||||
}
|
||||
var authority authorityPO
|
||||
if err := tx.Where("authority_id = ?", 888).First(&authority).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
exists, err := policyExists(tx, authority.AuthorityID, api.Path, api.Method)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if exists {
|
||||
return nil
|
||||
}
|
||||
rule := newPolicyRule(authority.AuthorityID, api.Path, api.Method)
|
||||
return tx.Create(&rule).Error
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user