refactor: deps approvals (#1206)

Reviewed-on: daoyoucloud/tachybase#1206
This commit is contained in:
sealday 2024-06-18 18:22:30 +08:00
parent 3712280e89
commit 509bcc29a8
3 changed files with 14 additions and 18 deletions

View File

@ -1027,6 +1027,9 @@ export class PluginManager {
} }
this.app.log.debug(`upgrade plugin [${plugin.name}]`); this.app.log.debug(`upgrade plugin [${plugin.name}]`);
await plugin.upgrade(); await plugin.upgrade();
for (const feature of plugin.featureInstances) {
await feature.upgrade();
}
plugin.state.upgraded = true; plugin.state.upgraded = true;
} }
await this.repository.update({ await this.repository.update({

View File

@ -1,6 +1,5 @@
import { resolve } from 'path';
import type { CollectionRepository } from '@tachybase/plugin-collection-manager'; import type { CollectionRepository } from '@tachybase/plugin-collection-manager';
import { Plugin } from '@tachybase/server'; import { InstallOptions, Plugin } from '@tachybase/server';
import { import {
aggregateSearch, aggregateSearch,
@ -32,14 +31,14 @@ export class DepartmentsPlugin extends Plugin {
}); });
} }
async load() { async load() {
this.app.resource({ this.app.resourcer.define({
name: 'users', name: 'users',
actions: { actions: {
listExcludeDept: listExcludeDept, listExcludeDept: listExcludeDept,
setMainDepartment: setMainDepartmentAction, setMainDepartment: setMainDepartmentAction,
}, },
}); });
this.app.resource({ this.app.resourcer.define({
name: 'departments', name: 'departments',
actions: { actions: {
aggregateSearch: aggregateSearch, aggregateSearch: aggregateSearch,
@ -84,7 +83,12 @@ export class DepartmentsPlugin extends Plugin {
this.app.cache.del(`departments:${userId}`); this.app.cache.del(`departments:${userId}`);
}); });
} }
async install(options) {
async upgrade() {
await this.install();
}
async install(options?: InstallOptions) {
const collectionRepo = this.db.getRepository<CollectionRepository>('collections'); const collectionRepo = this.db.getRepository<CollectionRepository>('collections');
if (collectionRepo) { if (collectionRepo) {
await collectionRepo.db2cm('departments'); await collectionRepo.db2cm('departments');

View File

@ -1,7 +1,7 @@
import './actions'; import './actions';
import path from 'path'; import path from 'path';
import Application, { InstallOptions, NoticeLevel, Plugin, type PluginOptions } from '@tachybase/server'; import { Plugin } from '@tachybase/server';
import { Container } from '@tachybase/utils'; import { Container } from '@tachybase/utils';
import { DepartmentsPlugin } from './features/departments'; import { DepartmentsPlugin } from './features/departments';
@ -13,22 +13,14 @@ import { SqlLoader } from './services/sql-loader';
import { WebControllerService as WebService } from './services/web-service'; import { WebControllerService as WebService } from './services/web-service';
export class PluginCoreServer extends Plugin { export class PluginCoreServer extends Plugin {
pluginDepartments: DepartmentsPlugin;
constructor(app: Application, options?: PluginOptions) {
super(app, options);
this.pluginDepartments = new DepartmentsPlugin(app, options);
}
async afterAdd() { async afterAdd() {
this.db.registerFieldTypes({ this.db.registerFieldTypes({
calc: CalcField, calc: CalcField,
tstzrange: TstzrangeField, tstzrange: TstzrangeField,
}); });
} this.addFeature(DepartmentsPlugin);
beforeLoad() {
this.pluginDepartments.beforeLoad();
} }
async load() { async load() {
await this.pluginDepartments.load();
try { try {
await Container.get(ConnectionManager).load(); await Container.get(ConnectionManager).load();
const fontManger = Container.get(FontManager); const fontManger = Container.get(FontManager);
@ -43,9 +35,6 @@ export class PluginCoreServer extends Plugin {
console.warn(err); console.warn(err);
} }
} }
async install(options?: InstallOptions) {
await this.pluginDepartments.install(options);
}
async afterEnable() {} async afterEnable() {}
async afterDisable() {} async afterDisable() {}
async remove() {} async remove() {}