From 0e4bd77b5193eaa194556f10e12b28ee02fc117a Mon Sep 17 00:00:00 2001 From: Sujith Date: Mon, 6 Feb 2023 13:07:09 +0530 Subject: [PATCH] fix: update the new permission and if condition Signed-off-by: Sujith --- .../src/util/defaultRoles.js | 8 ++------ packages/api-plugin-simple-schema/migrations/2.js | 11 +++-------- .../src/util/checkAndSeedDb.js | 4 ++-- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/api-plugin-authorization-simple/src/util/defaultRoles.js b/packages/api-plugin-authorization-simple/src/util/defaultRoles.js index fceb5a60790..cfe895bf47c 100644 --- a/packages/api-plugin-authorization-simple/src/util/defaultRoles.js +++ b/packages/api-plugin-authorization-simple/src/util/defaultRoles.js @@ -70,12 +70,7 @@ export const defaultShopManagerRoles = [ "reaction:legacy:shippingRestrictions/update", "reaction:legacy:shops/read", "reaction:legacy:shops/update", - "reaction:legacy:simpleSchema/introspect:*", - "reaction:legacy:simpleSchema/introspect:Cart", - "reaction:legacy:simpleSchema/introspect:Product", - "reaction:legacy:simpleSchema/introspect:Order", - "reaction:legacy:simpleSchema/introspect:Account", - "reaction:legacy:simpleSchema/introspect:Promotion", + "reaction:legacy:simpleSchema/introspect", "reaction:legacy:sitemaps/update:settings", "reaction:legacy:surcharges/create", "reaction:legacy:surcharges/delete", @@ -124,5 +119,6 @@ export const defaultSystemManagerRoles = [ "reaction:legacy:groups/update", "reaction:legacy:shops/create", "reaction:legacy:shops/read", + "reaction:legacy:simpleSchema/introspect", "reaction:legacy:invitations/read" ]; diff --git a/packages/api-plugin-simple-schema/migrations/2.js b/packages/api-plugin-simple-schema/migrations/2.js index bde173855a0..5559ce2a808 100644 --- a/packages/api-plugin-simple-schema/migrations/2.js +++ b/packages/api-plugin-simple-schema/migrations/2.js @@ -4,12 +4,7 @@ const COLLECTION_ROLES = "roles"; const COLLECTION_GROUPS = "Groups"; const newPermissions = [ - "reaction:legacy:simpleSchema/introspect:*", - "reaction:legacy:simpleSchema/introspect:Cart", - "reaction:legacy:simpleSchema/introspect:Product", - "reaction:legacy:simpleSchema/introspect:Order", - "reaction:legacy:simpleSchema/introspect:Account", - "reaction:legacy:simpleSchema/introspect:Promotion" + "reaction:legacy:simpleSchema/introspect" ]; /** @@ -25,7 +20,7 @@ async function down({ db, progress }) { const allGroups = await db.collection(COLLECTION_GROUPS).find({}).toArray(); const affectedGroups = []; allGroups.forEach((group) => { - if (group.slug === "shop manager" || group.slug === "owner") { // consider only these two groups for this migration + if (group.slug === "shop manager" || group.slug === "owner" || group.slug === "system-manager") { // only these three groups for this migration const perms = group.permissions; if (perms && Array.isArray(perms) && perms.length) { const found = newPermissions.some((elem) => perms.includes(elem)); @@ -74,7 +69,7 @@ async function up({ db, progress }) { for (let index = 0; index < allGroups.length; index += 1) { const currentGroup = allGroups[index]; - if (!(currentGroup.slug === "shop manager" || currentGroup.slug === "owner")) { // consider only these two groups for this migration + if (!(currentGroup.slug === "shop manager" || currentGroup.slug === "owner" || currentGroup.slug === "system-manager")) { // only these three groups for this migration progress(Math.floor(((index + 1) / (allGroups.length * 2)) * 100)); continue; } diff --git a/packages/api-plugin-simple-schema/src/util/checkAndSeedDb.js b/packages/api-plugin-simple-schema/src/util/checkAndSeedDb.js index efb67d67214..cd94d3ed07c 100644 --- a/packages/api-plugin-simple-schema/src/util/checkAndSeedDb.js +++ b/packages/api-plugin-simple-schema/src/util/checkAndSeedDb.js @@ -16,10 +16,10 @@ export default async function checkAndSeedDb(context) { const allGroups = await Groups.find({}).toArray(); for (const currentGroup of allGroups) { - if (!( + if ( currentGroup.slug === "shop manager" || currentGroup.slug === "system-manager" || - currentGroup.slug === "owner")) { // adding permission only for these three groups for this migration + currentGroup.slug === "owner") { // adding permission only for these three groups for this migration const currentPerms = currentGroup.permissions; let permsToAdd = [];