From f1c0503916e3715ec0c9a0334454662bb5696b25 Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 23 Jan 2021 11:17:36 +0800 Subject: [PATCH] fix: SequelizeForeignKeyConstraintError: insert or update on table "actions_scopes" violates foreign key constraint "actions_scopes_collection_name_fkey" --- .../src/hooks/collections-after-create.ts | 12 ++++++++++++ packages/plugin-permissions/src/server.ts | 12 ++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/plugin-collections/src/hooks/collections-after-create.ts b/packages/plugin-collections/src/hooks/collections-after-create.ts index ebc468b23..7b39471a0 100644 --- a/packages/plugin-collections/src/hooks/collections-after-create.ts +++ b/packages/plugin-collections/src/hooks/collections-after-create.ts @@ -73,6 +73,18 @@ const defaultValues = { default: true, }, ], + scopes: [ + { + title: '全部数据', + filter: {}, + }, + { + title: '用户自己的数据', + filter: { + "created_by_id.$currentUser": true, + }, + }, + ], }; export default async function (model: CollectionModel, options: any = {}) { diff --git a/packages/plugin-permissions/src/server.ts b/packages/plugin-permissions/src/server.ts index 84876d908..2cdfcc2ea 100644 --- a/packages/plugin-permissions/src/server.ts +++ b/packages/plugin-permissions/src/server.ts @@ -55,12 +55,12 @@ export class Permissions { // 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; - } + // 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) => {