feat(ai-agent): add permissions for AI Agent management and update related logic
This commit is contained in:
@@ -96,7 +96,7 @@ func ensureRoles(tx *gorm.DB) (map[string]*models.Role, error) {
|
||||
now := time.Now()
|
||||
|
||||
for _, spec := range constants.Roles {
|
||||
role := repositories.RoleRepository.FindOne(tx, sqls.NewCnd().Eq("code", spec.Code))
|
||||
role := repositories.RoleRepository.GetByCode(tx, spec.Code)
|
||||
if role == nil {
|
||||
role = &models.Role{
|
||||
Name: spec.Name,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"cs-agent/internal/pkg/constants"
|
||||
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(4, "sync ai agent permissions", func() error {
|
||||
return sqls.WithTransaction(func(ctx *sqls.TxContext) error {
|
||||
permissions, err := ensurePermissions(ctx.Tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
roles, err := ensureRoles(ctx.Tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = ensureRolePermissions(ctx.Tx, roles, permissions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ensureBootstrapAdmin(ctx.Tx, roles[constants.RoleCodeSuperAdmin])
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user