2023-12-07 21:46:58 +08:00
|
|
|
import { Plugin } from '@nocobase/server';
|
|
|
|
import actions from '@nocobase/actions';
|
|
|
|
import { HandlerType } from '@nocobase/resourcer';
|
|
|
|
import WorkflowPlugin, { JOB_STATUS } from '@nocobase/plugin-workflow';
|
|
|
|
|
2023-12-27 13:55:48 +08:00
|
|
|
import jobsCollection from './collections/jobs';
|
|
|
|
import usersCollection from './collections/users';
|
|
|
|
import usersJobsCollection from './collections/users_jobs';
|
2023-12-07 21:46:58 +08:00
|
|
|
import { submit } from './actions';
|
|
|
|
|
|
|
|
import ManualInstruction from './ManualInstruction';
|
|
|
|
|
|
|
|
export default class extends Plugin {
|
|
|
|
async load() {
|
|
|
|
this.app.db.collection(usersJobsCollection);
|
|
|
|
this.app.db.extendCollection(usersCollection);
|
|
|
|
this.app.db.extendCollection(jobsCollection);
|
|
|
|
|
|
|
|
this.app.resource({
|
|
|
|
name: 'users_jobs',
|
|
|
|
actions: {
|
|
|
|
list: {
|
|
|
|
filter: {
|
|
|
|
$or: [
|
|
|
|
{
|
|
|
|
'workflow.enabled': true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'workflow.enabled': false,
|
|
|
|
status: {
|
|
|
|
$ne: JOB_STATUS.PENDING,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
handler: actions.list as HandlerType,
|
|
|
|
},
|
|
|
|
submit,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-12-27 13:55:48 +08:00
|
|
|
this.app.acl.allow('users_jobs', ['list', 'get', 'submit'], 'loggedIn');
|
|
|
|
|
|
|
|
const workflowPlugin = this.app.getPlugin<WorkflowPlugin>(WorkflowPlugin);
|
|
|
|
workflowPlugin.registerInstruction('manual', ManualInstruction);
|
2023-12-07 21:46:58 +08:00
|
|
|
}
|
|
|
|
}
|