diff --git a/packages/plugins/@tachybase/plugin-acl/src/server/server.ts b/packages/plugins/@tachybase/plugin-acl/src/server/server.ts index 92c87e2f2..ec7f79559 100644 --- a/packages/plugins/@tachybase/plugin-acl/src/server/server.ts +++ b/packages/plugins/@tachybase/plugin-acl/src/server/server.ts @@ -253,6 +253,20 @@ export class PluginACL extends Plugin { }); }); + // 只有初始化的时候才执行 + this.app.db.on('roles.afterCreateWithAssociations', async (model, options) => { + const { transaction } = options; + await this.app.db.getRepository('dataSourcesRoles').updateOrCreate({ + values: { + roleName: model.get('name'), + dataSourceKey: 'main', + strategy: model.get('strategy'), + }, + filterKeys: ['roleName', 'dataSourceKey'], + transaction, + }); + }); + this.app.db.on('roles.afterSaveWithAssociations', async (model, options) => { const { transaction } = options; @@ -265,7 +279,6 @@ export class PluginACL extends Plugin { values: { roleName: model.get('name'), dataSourceKey: 'main', - strategy: model.get('strategy'), }, filterKeys: ['roleName', 'dataSourceKey'], transaction,