2022-04-24 23:17:42 +08:00
|
|
|
import { InstallOptions, Plugin } from '@nocobase/server';
|
2022-02-11 18:13:14 +08:00
|
|
|
import { resolve } from 'path';
|
2021-08-13 23:14:07 +08:00
|
|
|
|
2022-02-11 18:13:14 +08:00
|
|
|
export class SystemSettingsPlugin extends Plugin {
|
2022-05-19 00:40:55 +08:00
|
|
|
getInitAppLang(options) {
|
|
|
|
return options?.cliArgs?.[0]?.opts?.lang || process.env.INIT_APP_LANG || 'en-US';
|
|
|
|
}
|
|
|
|
|
2022-04-25 19:05:33 +08:00
|
|
|
async install(options?: InstallOptions) {
|
2022-02-28 21:49:50 +08:00
|
|
|
await this.db.getRepository('systemSettings').create({
|
|
|
|
values: {
|
|
|
|
title: 'NocoBase',
|
2022-05-19 00:40:55 +08:00
|
|
|
appLang: this.getInitAppLang(options),
|
2022-07-14 20:57:26 +08:00
|
|
|
enabledLanguages: [this.getInitAppLang(options)],
|
2022-02-28 21:49:50 +08:00
|
|
|
logo: {
|
|
|
|
title: 'nocobase-logo',
|
|
|
|
filename: '682e5ad037dd02a0fe4800a3e91c283b.png',
|
|
|
|
extname: '.png',
|
|
|
|
mimetype: 'image/png',
|
|
|
|
url: 'https://nocobase.oss-cn-beijing.aliyuncs.com/682e5ad037dd02a0fe4800a3e91c283b.png',
|
2021-09-23 00:16:04 +08:00
|
|
|
},
|
2022-02-28 21:49:50 +08:00
|
|
|
},
|
2021-09-11 18:53:26 +08:00
|
|
|
});
|
2022-02-07 01:14:00 +08:00
|
|
|
}
|
|
|
|
|
2022-04-24 23:17:42 +08:00
|
|
|
beforeLoad() {
|
|
|
|
const cmd = this.app.findCommand('install');
|
|
|
|
if (cmd) {
|
2022-05-19 00:40:55 +08:00
|
|
|
cmd.option('-l, --lang [lang]');
|
2022-04-24 23:17:42 +08:00
|
|
|
}
|
2023-01-09 07:35:48 +08:00
|
|
|
|
|
|
|
this.app.acl.registerSnippet({
|
|
|
|
name: `pm.${this.name}.system-settings`,
|
|
|
|
actions: ['systemSettings:update'],
|
|
|
|
});
|
2022-04-24 23:17:42 +08:00
|
|
|
}
|
|
|
|
|
2022-02-07 01:14:00 +08:00
|
|
|
async load() {
|
2023-01-09 07:35:48 +08:00
|
|
|
await this.app.db.import({
|
|
|
|
directory: resolve(__dirname, 'collections'),
|
|
|
|
});
|
|
|
|
|
|
|
|
this.app.acl.addFixedParams('systemSettings', 'destroy', () => {
|
|
|
|
return {
|
|
|
|
'id.$ne': 1,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
this.app.acl.allow('systemSettings', 'get', 'public');
|
2022-02-07 01:14:00 +08:00
|
|
|
}
|
|
|
|
}
|
2022-02-11 18:13:14 +08:00
|
|
|
|
|
|
|
export default SystemSettingsPlugin;
|