tachybase_todo/packages/plugin-users/src/server.ts
Junyi c5f089d7b7
feat: add permissions plugin (#53)
* test: skip bug test cases for ci passing

* feat: add base structure of plugin-permissions

* fix: user token parsing

* Refactor action parameter for better mergeParams (#55)

* refactor: add parameter types to handle parameters in action [WIP]

* fix: action parameter

* fix: test cases

* test: try to fix build error

* remove unused packages

* fix: revert compatibility back

Co-authored-by: chenos <chenlinxh@gmail.com>

* 补充权限界面相关功能

* bugfix

* fix: developer mode does not work

* feat: add action scope and fields limitation in permission

* 改进权限配置表单

* feat: get/update action for role.collection

* add scope select component

* add role users tabs

* typings

* test: temp skip

Co-authored-by: chenos <chenlinxh@gmail.com>
2021-01-13 16:23:15 +08:00

51 lines
1.5 KiB
TypeScript

import path from 'path';
import Database, { registerFields } from '@nocobase/database';
import Resourcer from '@nocobase/resourcer';
import * as fields from './fields';
// import hooks from './hooks';
import login from './actions/login';
import register from './actions/register';
import logout from './actions/logout';
import check from './actions/check';
import { makeOptions } from './hooks/collection-after-create';
import * as middlewares from './middlewares';
export default async function (options = {}) {
const database: Database = this.database;
const resourcer: Resourcer = this.resourcer;
registerFields(fields);
database.import({
directory: path.resolve(__dirname, 'collections'),
});
database.addHook('afterTableInit', (table) => {
let { createdBy, updatedBy, internal } = table.getOptions();
// 非内置表,默认创建 createdBy 和 updatedBy
if (!internal) {
if (typeof createdBy === 'undefined') {
createdBy = true;
}
if (typeof updatedBy === 'undefined') {
updatedBy = true;
}
}
const fieldsToMake = { createdBy, updatedBy };
Object.keys(fieldsToMake)
.filter(type => Boolean(fieldsToMake[type]))
.map(type => table.addField(makeOptions(type, fieldsToMake[type])));
});
resourcer.registerActionHandlers({
'users:login': login,
'users:register': register,
'users:logout': logout,
'users:check': check,
});
resourcer.use(middlewares.parseToken(options));
}