tachybase_todo/packages/plugins/@nocobase/plugin-custom-request/src/server/plugin.ts
Dunqing 8ab69500c7
fix(custom-request): permission issues (#3306)
* fix(custom-request-plugin): cannot see custom request action in non-root role when acl doesn't set

* fix: list all roles

* feat: display all roles

* feat: support

* fix: remove unused code

* fix: options is null

* fix: translation

* fix: migration error

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
2024-01-13 18:13:18 +08:00

55 lines
1.3 KiB
TypeScript

import { Logger, LoggerOptions } from '@nocobase/logger';
import { InstallOptions, Plugin } from '@nocobase/server';
import { resolve } from 'path';
import { listByCurrentRole } from './actions/listByCurrentRole';
import { send } from './actions/send';
export class CustomRequestPlugin extends Plugin {
logger: Logger;
afterAdd() {}
beforeLoad() {
this.logger = this.getLogger();
}
getLogger(): Logger {
const logger = this.createLogger({
dirname: 'custom-request',
filename: '%DATE%.log',
transports: [...(process.env.NODE_ENV === 'production' ? ['dailyRotateFile'] : ['console'])],
} as LoggerOptions);
return logger;
}
async load() {
await this.importCollections(resolve(__dirname, 'collections'));
this.app.resource({
name: 'customRequests',
actions: {
send: send.bind(this),
listByCurrentRole,
},
});
this.app.acl.registerSnippet({
name: `ui.${this.name}`,
actions: ['customRequests:*', 'roles:list'],
});
this.app.acl.allow('customRequests', ['send', 'listByCurrentRole'], 'loggedIn');
}
async install(options?: InstallOptions) {}
async afterEnable() {}
async afterDisable() {}
async remove() {}
}
export default CustomRequestPlugin;