mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:25:52 +00:00
feat: add scope hook
This commit is contained in:
parent
ae257567bf
commit
95be672222
@ -36,7 +36,7 @@ const transforms = {
|
||||
const dataSource = field.get('dataSource').filter(item => item.key !== 'developerMode');
|
||||
field.set('dataSource', dataSource);
|
||||
}
|
||||
if (field.get('name') === 'filter' && field.get('collection_name') === 'views') {
|
||||
if (field.get('component.type') === 'filter') {
|
||||
const { values } = ctx.action.params;
|
||||
const options = Field.parseApiJson(ctx.state.developerMode ? {
|
||||
filter: {
|
||||
|
@ -10,11 +10,11 @@ export default extend({
|
||||
target: 'actions_scopes',
|
||||
title: '数据范围',
|
||||
sourceKey: 'name',
|
||||
// actions: {
|
||||
// list: {
|
||||
// sort: 'sort',
|
||||
// },
|
||||
// },
|
||||
actions: {
|
||||
list: {
|
||||
sort: 'id',
|
||||
},
|
||||
},
|
||||
component: {
|
||||
type: 'drawerSelect',
|
||||
},
|
||||
|
@ -52,6 +52,35 @@ class Permissions {
|
||||
resourcer.registerActionHandler(`roles.pages:${actionName}`, rolesPagesActions[actionName]);
|
||||
});
|
||||
|
||||
const defaultScopes = [
|
||||
{
|
||||
title: '全部数据',
|
||||
filter: {},
|
||||
},
|
||||
{
|
||||
title: '用户自己的数据',
|
||||
filter: {
|
||||
"created_by_id.$currentUser": true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const Scope = database.getModel('actions_scopes');
|
||||
|
||||
database.getModel('collections').addHook('afterCreate', async (model, options) => {
|
||||
// TODO(bug): createScope 存不了 filter 参数
|
||||
// for (const scope of defaultScopes) {
|
||||
// const s = await model.createScope(scope, options);
|
||||
// console.log(s.toJSON());
|
||||
// }
|
||||
try {
|
||||
await Scope.bulkCreate(defaultScopes.map(scope => ({...scope, collection_name: model.get('name')})));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
// 针对“自己创建的” scope 添加特殊的操作符以生成查询条件
|
||||
if (!Operator.has('$currentUser')) {
|
||||
Operator.register('$currentUser', (value, { ctx }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user