* fix: update method of permission * 页面访问权限 * feat: add tabs update in role * refactor: change main action permission check into single file * feat: add pluginLoaded event listener for init page permissions * refactor: change to can api * refactor: use constants for role types * refactor: can api * 只处理 actions 表里的权限,其余跳过 * 注释掉 fields * bugfix * add: 详情模块编辑按钮权限判断 * test: add cases * fix: add association permission judgment * fix: add disabled property to drawer select Co-authored-by: chenos <chenlinxh@gmail.com>
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import Koa from 'koa';
|
|
import Database, { DatabaseOptions } from '@nocobase/database';
|
|
import Resourcer from '@nocobase/resourcer';
|
|
|
|
export interface ApplicationOptions {
|
|
database: DatabaseOptions;
|
|
resourcer?: any;
|
|
}
|
|
|
|
export class Application extends Koa {
|
|
// static const EVENT_PLUGINS_LOADED = Symbol('pluginsLoaded');
|
|
|
|
public readonly database: Database;
|
|
|
|
public readonly resourcer: Resourcer;
|
|
|
|
protected plugins = new Map<string, any>();
|
|
|
|
constructor(options: ApplicationOptions) {
|
|
super();
|
|
this.database = new Database(options.database);
|
|
this.resourcer = new Resourcer();
|
|
// this.runHook('afterInit');
|
|
}
|
|
|
|
registerPlugin(key: string | object, plugin?: any) {
|
|
if (typeof key === 'object') {
|
|
Object.keys(key).forEach((k) => {
|
|
this.registerPlugin(k, key[k]);
|
|
});
|
|
} else {
|
|
const config = {};
|
|
if (Array.isArray(plugin)) {
|
|
const [entry, options = {}] = plugin;
|
|
Object.assign(config, { entry, options });
|
|
} else {
|
|
Object.assign(config, { entry: plugin, options: {} });
|
|
}
|
|
this.plugins.set(key, config);
|
|
}
|
|
}
|
|
|
|
getPluginInstance(key: string) {
|
|
const plugin = this.plugins.get(key);
|
|
return plugin && plugin.instance;
|
|
}
|
|
|
|
async loadPlugins() {
|
|
const allPlugins = this.plugins.values();
|
|
for (const plugin of allPlugins) {
|
|
plugin.instance = await this.loadPlugin(plugin);
|
|
}
|
|
}
|
|
|
|
protected async loadPlugin({ entry, options = {} }: { entry: string | Function, options: any }) {
|
|
const main = typeof entry === 'function'
|
|
? entry
|
|
: require(`${entry}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default;
|
|
|
|
return await main.call(this, options);
|
|
}
|
|
}
|
|
|
|
export default Application;
|