fix: scopes
This commit is contained in:
parent
e36415330f
commit
82355e1422
@ -73,23 +73,11 @@ const defaultValues = {
|
|||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
scopes: [
|
|
||||||
{
|
|
||||||
title: '全部数据',
|
|
||||||
filter: {},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '用户自己的数据',
|
|
||||||
filter: {
|
|
||||||
"created_by_id.$currentUser": true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function (model: CollectionModel, options: any = {}) {
|
export default async function (model: CollectionModel, options: any = {}) {
|
||||||
const { migrate = true } = options;
|
const { migrate = true } = options;
|
||||||
console.log({migrate})
|
console.log('plugin-collections hook', {migrate})
|
||||||
if (migrate) {
|
if (migrate) {
|
||||||
await model.migrate({...options, isNewRecord: true});
|
await model.migrate({...options, isNewRecord: true});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Model, ModelCtor, BELONGSTOMANY } from '@nocobase/database';
|
import { Model, ModelCtor, BELONGSTOMANY } from '@nocobase/database';
|
||||||
import { get, set } from 'lodash';
|
import { get, set, isString } from 'lodash';
|
||||||
import { Op } from 'sequelize';
|
|
||||||
|
|
||||||
const transforms = {
|
const transforms = {
|
||||||
table: async (fields: Model[], context?: any) => {
|
table: async (fields: Model[], context?: any) => {
|
||||||
@ -50,7 +49,7 @@ const transforms = {
|
|||||||
field.set('dataSource', dataSource);
|
field.set('dataSource', dataSource);
|
||||||
}
|
}
|
||||||
const { values } = ctx.action.params;
|
const { values } = ctx.action.params;
|
||||||
if (field.get('component.type') === 'filter' && get(values, 'associatedKey')) {
|
if (field.get('component.type') === 'filter' && get(values, 'associatedKey') && isString(get(values, 'associatedKey'))) {
|
||||||
const options = Field.parseApiJson(ctx.state.developerMode ? {
|
const options = Field.parseApiJson(ctx.state.developerMode ? {
|
||||||
filter: {
|
filter: {
|
||||||
collection_name: get(values, 'associatedKey'),
|
collection_name: get(values, 'associatedKey'),
|
||||||
|
@ -34,33 +34,22 @@ export class Permissions {
|
|||||||
resourcer.registerActionHandler(`roles.collections:${actionName}`, rolesCollectionsActions[actionName]);
|
resourcer.registerActionHandler(`roles.collections:${actionName}`, rolesCollectionsActions[actionName]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const defaultScopes = [
|
database.getModel('collections').addHook('afterCreate', async (model: any, options) => {
|
||||||
{
|
console.log('plugin-permissions hook');
|
||||||
title: '全部数据',
|
await model.updateAssociations({
|
||||||
filter: {},
|
scopes: [
|
||||||
},
|
{
|
||||||
{
|
title: '全部数据',
|
||||||
title: '用户自己的数据',
|
filter: {},
|
||||||
filter: {
|
},
|
||||||
"created_by_id.$currentUser": true,
|
{
|
||||||
},
|
title: '用户自己的数据',
|
||||||
},
|
filter: {
|
||||||
];
|
"created_by_id.$currentUser": true,
|
||||||
|
},
|
||||||
const Scope = database.getModel('actions_scopes');
|
},
|
||||||
|
]
|
||||||
database.getModel('collections').addHook('afterCreate', async (model, options) => {
|
}, 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;
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
database.getModel('users').addHook('afterCreate', async(model, options) => {
|
database.getModel('users').addHook('afterCreate', async(model, options) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user