diff --git a/packages/plugin-pages/src/actions/getView.ts b/packages/plugin-pages/src/actions/getView.ts index 44b8ddb1e..51d9576fe 100644 --- a/packages/plugin-pages/src/actions/getView.ts +++ b/packages/plugin-pages/src/actions/getView.ts @@ -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: { diff --git a/packages/plugin-permissions/src/collections/collections.ts b/packages/plugin-permissions/src/collections/collections.ts index 9955a8228..7c62563df 100644 --- a/packages/plugin-permissions/src/collections/collections.ts +++ b/packages/plugin-permissions/src/collections/collections.ts @@ -10,11 +10,11 @@ export default extend({ target: 'actions_scopes', title: '数据范围', sourceKey: 'name', - // actions: { - // list: { - // sort: 'sort', - // }, - // }, + actions: { + list: { + sort: 'id', + }, + }, component: { type: 'drawerSelect', }, diff --git a/packages/plugin-permissions/src/server.ts b/packages/plugin-permissions/src/server.ts index 68e8651c4..711143d98 100644 --- a/packages/plugin-permissions/src/server.ts +++ b/packages/plugin-permissions/src/server.ts @@ -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 }) => {