Commit dd6f0a6d authored by chenos's avatar chenos
Browse files

fix(cli): skip when role does not exist

parent 7c21c5cf
main 0.7 0.7.6 Dunqing-feat-select-m2o-next audit-logs auditlogs changed-with-associations chore/error-message doc/api-database doc/db-repository doc/dev-res-action doc/new-user-manual doc/plugin-workflow doc/relation-repository example/custom-signup-page example/util examples excel-function feat-add-block-title-feature feat-add-default-sort feat-association-field-block feat-association-field-features feat-default-value feat-fix-time-and-collection-pagination feat-fk-input feat-form-validator feat-kanban-add-description feat-m2o-sub-form-mode feat-record-block-initializers-fields-pick feat-relation-field-uischema feat/associate-operate feat/batch-operation feat/cache feat/changed-with-associations feat/collection-inherits feat/collection-templates feat/database feat/dev-ci feat/field-unique feat/grap-collection feat/inherit-collection feat/logger feat/plugin-export feat/plugin-file-manager feat/plugin-import feat/plugin-import-2 feat/plugin-manager-0823 feat/plugin-user-groups feat/plugin-verification feat/plugin-workflow-collection-field feat/pm feat/pnpm-support feat/reference-check feat/request-logs feat/resize-grid-columns feat/safer-update feat/submodule-graph-collection feat/tree-table-block feat/workflow-request fix-formula-bug fix-link-to-default-value fix-template-with-fields-only fix-timezone fix/association-deleted fix/attachment-upload fix/block-select-collection-menu fix/bulk-update-db-locked fix/collection-manager fix/collection-manager-0719 fix/collection-manager-del-foreign-key fix/create-inherits fix/custom-assign-value fix/database-find-with-appends fix/database-view-error fix/destroy-fields-by-array fix/docker-ci fix/export-date fix/export-percent fix/form-sys-fields-default-edit-mode fix/menu-schema fix/merge-include fix/plugin-cm fix/table-data fix/table-field-overflow perf/cache-schema perf/token pre-release refactor/client refactor/plugin-workflow refactor/plugin-workflow-ui rollback table-demo tree tree-demo v0.8.0-alpha.13 v0.8.0-alpha.11 v0.8.0-alpha.9 v0.8.0-alpha.8 v0.8.0-alpha.7 v0.8.0-alpha.6 v0.8.0-alpha.5 v0.8.0-alpha.3 v0.8.0-alpha.2 v0.8.0-alpha.1 v0.7.7-alpha.1 v0.7.6-alpha.2 v0.7.5-alpha.1.1666403334 v0.7.5-alpha.1 v0.7.4-alpha.7 v0.7.4-alpha.4 v0.7.4-alpha.1 v0.7.3-alpha.1 v0.7.2-alpha.2 v0.7.2-alpha.1 v0.7.1-alpha.5 v0.7.1-alpha.4
No related merge requests found
Showing with 10 additions and 3 deletions
+10 -3
import { Database, Model } from '@nocobase/database';
import { ACL, ACLResource, ACLRole } from '@nocobase/acl';
import { RoleResourceActionModel } from './RoleResourceActionModel';
import { Model } from '@nocobase/database';
import { AssociationFieldsActions, GrantHelper } from '../server';
import { RoleResourceActionModel } from './RoleResourceActionModel';
export class RoleResourceModel extends Model {
async revoke(options: { role: ACLRole; resourceName: string; grantHelper: GrantHelper }) {
......@@ -36,6 +36,11 @@ export class RoleResourceModel extends Model {
const roleName = this.get('roleName') as string;
const role = acl.getRole(roleName);
if (!role) {
console.log(`${roleName} role does not exist`);
return;
}
// revoke resource of role
await this.revoke({ role, resourceName, grantHelper });
......
......@@ -180,7 +180,9 @@ export class PluginACL extends Plugin {
this.app.db.on('rolesResources.afterDestroy', async (model, options) => {
const role = this.acl.getRole(model.get('roleName'));
role.revokeResource(model.get('name'));
if (role) {
role.revokeResource(model.get('name'));
}
});
this.app.db.on('collections.afterDestroy', async (model, options) => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment