Skip to content

Commit

Permalink
fix: update the new permission and if condition
Browse files Browse the repository at this point in the history
Signed-off-by: Sujith <[email protected]>
  • Loading branch information
sujithvn committed Feb 6, 2023
1 parent 06c601e commit 0e4bd77
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
];
11 changes: 3 additions & 8 deletions packages/api-plugin-simple-schema/migrations/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];

/**
Expand All @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api-plugin-simple-schema/src/util/checkAndSeedDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down

0 comments on commit 0e4bd77

Please sign in to comment.