From 9fac63cf8f2b49f543e28397e6b36db3b261657e Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Wed, 26 Jul 2017 17:17:48 +0100 Subject: [PATCH 01/12] Setup up version for migrating from old permissions style to groups --- .../5_update_defaultRoles_to_groups.js | 49 +++++++++++++++++++ .../core/versions/server/migrations/index.js | 1 + 2 files changed, 50 insertions(+) create mode 100644 imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js new file mode 100644 index 00000000000..69045cab9d8 --- /dev/null +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -0,0 +1,49 @@ +import { Meteor } from "meteor/meteor"; +import { Roles } from "meteor/alanning:roles"; +import { Migrations } from "/imports/plugins/core/versions"; +import { Logger } from "/server/api"; +import { Accounts, Groups, Shops } from "/lib/collections"; + +Migrations.add({ + version: 5, + up() { + const allGroups = Groups.find({}).fetch(); + const shops = Shops.find({}).fetch(); + + if (shops && shops.length) { + shops.forEach((shop) => createGroupsForShop(shop)); + } + function createGroupsForShop(shop) { + const { defaultRoles, defaultVisitorRole } = shop; + const roles = { + customer: defaultRoles || [ "guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"], + guest: defaultVisitorRole || ["anonymous", "guest", "product", "tag", "index", "cart/checkout", "cart/completed"], + owner: Roles.getAllRoles().fetch().map((role) => role.name) + }; + + Object.keys(roles).forEach((groupKeys) => { + const groupExists = allGroups.find((grp) => grp.slug === groupKeys && grp.shopId === shop._id); + if (!groupExists) { + Logger.debug(`creating group ${groupKeys} for shop ${shop.name}`); + const groupId = Groups.insert({ + name: groupKeys, + slug: groupKeys, + permissions: roles[groupKeys], + shopId: shop._id + }); + console.log({ newgroup: groupId }); + updateAccountsBelongingToGroup({ shopId: shop._id, permissions: roles[groupKeys], groupId }); + } + }); + } + + function updateAccountsBelongingToGroup({ shopId, permissions, groupId }) { + const query = { [`roles.${shopId}`]: permissions }; + const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); + Accounts.update({ _id: { $in: matchingUserIds } }, { $set: { groups: [groupId] } }); + } + }, + down() { + + } +}); diff --git a/imports/plugins/core/versions/server/migrations/index.js b/imports/plugins/core/versions/server/migrations/index.js index 1b214dca99f..ae181bd052a 100644 --- a/imports/plugins/core/versions/server/migrations/index.js +++ b/imports/plugins/core/versions/server/migrations/index.js @@ -2,3 +2,4 @@ import "./1_rebuild_account_and_order_search_collections"; import "./2_add_key_to_search_ui"; import "./3_reset_package_registry"; import "./4_update_templates_priority"; +import "./5_update_defaultRoles_to_groups"; From a3e3d11f658490aa2d4cdafdf0e7ea5933ea9aa8 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Wed, 26 Jul 2017 18:23:31 +0100 Subject: [PATCH 02/12] Update accounts that match on migrate and add down method --- .../5_update_defaultRoles_to_groups.js | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index 69045cab9d8..6d519d87d26 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -7,12 +7,13 @@ import { Accounts, Groups, Shops } from "/lib/collections"; Migrations.add({ version: 5, up() { - const allGroups = Groups.find({}).fetch(); const shops = Shops.find({}).fetch(); + Groups.remove({}); if (shops && shops.length) { shops.forEach((shop) => createGroupsForShop(shop)); } + function createGroupsForShop(shop) { const { defaultRoles, defaultVisitorRole } = shop; const roles = { @@ -22,28 +23,46 @@ Migrations.add({ }; Object.keys(roles).forEach((groupKeys) => { - const groupExists = allGroups.find((grp) => grp.slug === groupKeys && grp.shopId === shop._id); - if (!groupExists) { - Logger.debug(`creating group ${groupKeys} for shop ${shop.name}`); - const groupId = Groups.insert({ - name: groupKeys, - slug: groupKeys, - permissions: roles[groupKeys], - shopId: shop._id - }); - console.log({ newgroup: groupId }); - updateAccountsBelongingToGroup({ shopId: shop._id, permissions: roles[groupKeys], groupId }); - } + Logger.info(`creating group ${groupKeys} for shop ${shop.name}`); + const groupId = Groups.insert({ + name: groupKeys, + slug: groupKeys, + permissions: roles[groupKeys], + shopId: shop._id + }); + Logger.info(`new group "${groupKeys}" created with id ${groupId}"`); + return updateAccountsBelongingToGroup({ shopId: shop._id, permissions: roles[groupKeys], groupId }); }); } function updateAccountsBelongingToGroup({ shopId, permissions, groupId }) { - const query = { [`roles.${shopId}`]: permissions }; + const query = { [`roles.${shopId}`]: { $all: permissions } }; const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); - Accounts.update({ _id: { $in: matchingUserIds } }, { $set: { groups: [groupId] } }); + if (matchingUserIds.length) { + Logger.info(`updating following matching Accounts to new group: ${matchingUserIds}`); + } + Accounts.update({ _id: { $in: matchingUserIds }, shopId }, { $addToSet: { groups: groupId } }); } }, down() { + const shops = Shops.find({}).fetch(); + + if (shops && shops.length) { + shops.forEach((shop) => removeGroupsForShop(shop)); + } + function removeGroupsForShop(shop) { + const shopGroups = Groups.find({ shopId: shop._id }).fetch(); + const keys = { + customer: "defaultRoles", + guest: "defaultVisitorRole" + }; + + shopGroups.forEach((group) => { + const shopkey = keys[group.slug]; + Shops.update({ _id: shop._id }, { $set: { [shopkey]: group.permissions } }); + Accounts.update({ shopId: shop._id }, { $unset: { groups: "" } }); + }); + } } }); From aa656a5e932507693c2a4d535e1dfb1d038ca851 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Thu, 27 Jul 2017 14:26:05 +0100 Subject: [PATCH 03/12] Add shop manager as part of default groups on start and add to migration file --- .../migrations/5_update_defaultRoles_to_groups.js | 15 +++++++++------ server/api/core/core.js | 9 ++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index 6d519d87d26..12a1238061e 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -16,21 +16,24 @@ Migrations.add({ function createGroupsForShop(shop) { const { defaultRoles, defaultVisitorRole } = shop; + const ownerRoles = Roles.getAllRoles().fetch().map(role => role.name); + const shopManagerRoles = ownerRoles.filter(role => role !== "owner"); const roles = { - customer: defaultRoles || [ "guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"], - guest: defaultVisitorRole || ["anonymous", "guest", "product", "tag", "index", "cart/checkout", "cart/completed"], - owner: Roles.getAllRoles().fetch().map((role) => role.name) + "shop manager": shopManagerRoles, + "customer": defaultRoles || [ "guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"], + "guest": defaultVisitorRole || ["anonymous", "guest", "product", "tag", "index", "cart/checkout", "cart/completed"], + "owner": ownerRoles }; Object.keys(roles).forEach((groupKeys) => { - Logger.info(`creating group ${groupKeys} for shop ${shop.name}`); + Logger.debug(`creating group ${groupKeys} for shop ${shop.name}`); const groupId = Groups.insert({ name: groupKeys, slug: groupKeys, permissions: roles[groupKeys], shopId: shop._id }); - Logger.info(`new group "${groupKeys}" created with id ${groupId}"`); + Logger.debug(`new group "${groupKeys}" created with id ${groupId}"`); return updateAccountsBelongingToGroup({ shopId: shop._id, permissions: roles[groupKeys], groupId }); }); } @@ -39,7 +42,7 @@ Migrations.add({ const query = { [`roles.${shopId}`]: { $all: permissions } }; const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); if (matchingUserIds.length) { - Logger.info(`updating following matching Accounts to new group: ${matchingUserIds}`); + Logger.debug(`updating following matching Accounts to new group: ${matchingUserIds}`); } Accounts.update({ _id: { $in: matchingUserIds }, shopId }, { $addToSet: { groups: groupId } }); } diff --git a/server/api/core/core.js b/server/api/core/core.js index 79220ca611b..540d44f2a8f 100644 --- a/server/api/core/core.js +++ b/server/api/core/core.js @@ -63,10 +63,13 @@ export default { createDefaultGroups() { const allGroups = Groups.find({}).fetch(); const shops = Shops.find({}).fetch(); + const ownerRoles = Roles.getAllRoles().fetch().map(role => role.name); + const shopManagerRoles = ownerRoles.filter(role => role !== "owner"); const roles = { - customer: [ "guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"], - guest: ["anonymous", "guest", "product", "tag", "index", "cart/checkout", "cart/completed"], - owner: Roles.getAllRoles().fetch().map(role => role.name) + "shop manager": shopManagerRoles, + "customer": [ "guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"], + "guest": ["anonymous", "guest", "product", "tag", "index", "cart/checkout", "cart/completed"], + "owner": ownerRoles }; if (shops && shops.length) { From 9b6abdd678d2f398a863fb77a10b33b21d33c275 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Thu, 27 Jul 2017 14:43:04 +0100 Subject: [PATCH 04/12] Show no dropdown if shop has only one group --- .../core/accounts/client/components/groupsTableCell.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/imports/plugins/core/accounts/client/components/groupsTableCell.js b/imports/plugins/core/accounts/client/components/groupsTableCell.js index bfddc155a12..885135590c2 100644 --- a/imports/plugins/core/accounts/client/components/groupsTableCell.js +++ b/imports/plugins/core/accounts/client/components/groupsTableCell.js @@ -33,6 +33,11 @@ const GroupsTableCell = ({ account, columnName, group, groups, handleRemoveUserF } if (columnName === "dropdown") { + if (groups.length === 1) { + return ( +

{_.startCase(groups[0].name)}

+ ); + } const dropDownButton = (
From aceb0e5431def33fdf2faed4f19200838726998f Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Thu, 27 Jul 2017 15:01:57 +0100 Subject: [PATCH 05/12] If account with no name, use first part of email as name --- .../core/accounts/client/components/groupsTableCell.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/imports/plugins/core/accounts/client/components/groupsTableCell.js b/imports/plugins/core/accounts/client/components/groupsTableCell.js index 885135590c2..5f20c2a2835 100644 --- a/imports/plugins/core/accounts/client/components/groupsTableCell.js +++ b/imports/plugins/core/accounts/client/components/groupsTableCell.js @@ -5,11 +5,14 @@ import { Components, registerComponent } from "@reactioncommerce/reaction-compon import { getGravatar } from "../helpers/accountsHelper"; const GroupsTableCell = ({ account, columnName, group, groups, handleRemoveUserFromGroup, handleUserGroupChange }) => { + const email = _.get(account, "emails[0].address"); + if (columnName === "name") { + const name = account.name || email.split("@")[0]; return (
- {account.name} + {name}
); } @@ -17,7 +20,7 @@ const GroupsTableCell = ({ account, columnName, group, groups, handleRemoveUserF if (columnName === "email") { return (
- {_.get(account, "emails[0].address")} + {email}
); } From 9687910ff860f6858226ba3cfc5085dc90093f06 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Fri, 28 Jul 2017 15:13:36 +0100 Subject: [PATCH 06/12] Switch logger to debug --- .../server/migrations/5_update_defaultRoles_to_groups.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index 6d519d87d26..998008386aa 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -23,14 +23,14 @@ Migrations.add({ }; Object.keys(roles).forEach((groupKeys) => { - Logger.info(`creating group ${groupKeys} for shop ${shop.name}`); + Logger.debug(`creating group ${groupKeys} for shop ${shop.name}`); const groupId = Groups.insert({ name: groupKeys, slug: groupKeys, permissions: roles[groupKeys], shopId: shop._id }); - Logger.info(`new group "${groupKeys}" created with id ${groupId}"`); + Logger.debug(`new group "${groupKeys}" created with id ${groupId}"`); return updateAccountsBelongingToGroup({ shopId: shop._id, permissions: roles[groupKeys], groupId }); }); } @@ -39,7 +39,7 @@ Migrations.add({ const query = { [`roles.${shopId}`]: { $all: permissions } }; const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); if (matchingUserIds.length) { - Logger.info(`updating following matching Accounts to new group: ${matchingUserIds}`); + Logger.debug(`updating following matching Accounts to new group: ${matchingUserIds}`); } Accounts.update({ _id: { $in: matchingUserIds }, shopId }, { $addToSet: { groups: groupId } }); } From 725774d57cc803bff86e87d20e4b545ea9495186 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Fri, 28 Jul 2017 15:27:02 +0100 Subject: [PATCH 07/12] add sort to display higher permission groups at the top --- .../plugins/core/accounts/client/helpers/accountsHelper.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imports/plugins/core/accounts/client/helpers/accountsHelper.js b/imports/plugins/core/accounts/client/helpers/accountsHelper.js index ea62f65bcce..7883bdaf7ca 100644 --- a/imports/plugins/core/accounts/client/helpers/accountsHelper.js +++ b/imports/plugins/core/accounts/client/helpers/accountsHelper.js @@ -11,7 +11,9 @@ import * as Collections from "/lib/collections"; * @return {Array} - array of groups, each having a `users` field */ export default function sortUsersIntoGroups({ accounts, groups }) { - const newGroups = groups.map((group) => { + // sort to display higher permission groups at the top + const sortedGroups = groups.sort((prev, next) => next.permissions.length - prev.permissions.length); + const newGroups = sortedGroups.map((group) => { const matchingAccounts = accounts.map((acc) => { if (acc.groups && acc.groups.indexOf(group._id) > -1) { return acc; From 74dd3e95b4e4a8156b406b2c1aa714ee05261aa9 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Fri, 28 Jul 2017 21:18:30 +0100 Subject: [PATCH 08/12] Setup searching for and creating custom group and setting users to custom --- .../5_update_defaultRoles_to_groups.js | 71 ++++++++++++++++--- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index 998008386aa..48f4147586c 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -11,10 +11,35 @@ Migrations.add({ Groups.remove({}); if (shops && shops.length) { - shops.forEach((shop) => createGroupsForShop(shop)); + shops.forEach((shop) => { + const defaultGroupAccounts = createDefaultGroupsForShop(shop); + + const customPermissions = Meteor.users + .find({ _id: { $nin: defaultGroupAccounts } }) + .fetch() + .map(user => user.roles[shop._id]); + + const permissionsArray = sortUniqueArray(customPermissions); + + permissionsArray.forEach((permissions, index) => { + Logger.info(`creating custom group for shop ${shop.name}`); + const groupId = Groups.insert({ + name: `custom ${index + 1}`, + slug: `custom${index + 1}`, + permissions, + shopId: shop._id + }); + updateAccountsInGroup({ + shopId: shop._id, + permissions, + groupId + }); + }); + }); } - function createGroupsForShop(shop) { + function createDefaultGroupsForShop(shop) { + let defaultGroupAccounts = []; const { defaultRoles, defaultVisitorRole } = shop; const roles = { customer: defaultRoles || [ "guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"], @@ -23,25 +48,37 @@ Migrations.add({ }; Object.keys(roles).forEach((groupKeys) => { - Logger.debug(`creating group ${groupKeys} for shop ${shop.name}`); + Logger.info(`creating group ${groupKeys} for shop ${shop.name}`); const groupId = Groups.insert({ name: groupKeys, slug: groupKeys, permissions: roles[groupKeys], shopId: shop._id }); - Logger.debug(`new group "${groupKeys}" created with id ${groupId}"`); - return updateAccountsBelongingToGroup({ shopId: shop._id, permissions: roles[groupKeys], groupId }); + Logger.info(`new group "${groupKeys}" created with id "${groupId}"`); + const updatedAccounts = updateAccountsInGroup({ + shopId: shop._id, + permissions: roles[groupKeys], + groupId + }); + defaultGroupAccounts = defaultGroupAccounts.concat(updatedAccounts); }); + return defaultGroupAccounts; } - function updateAccountsBelongingToGroup({ shopId, permissions, groupId }) { - const query = { [`roles.${shopId}`]: { $all: permissions } }; + function updateAccountsInGroup({ shopId, permissions, groupId }) { + const query = { [`roles.${shopId}`]: { $size: permissions.length, $all: permissions } }; const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); + if (matchingUserIds.length) { - Logger.debug(`updating following matching Accounts to new group: ${matchingUserIds}`); + Logger.info(`updating following matching Accounts to new group: ${matchingUserIds}`); } - Accounts.update({ _id: { $in: matchingUserIds }, shopId }, { $addToSet: { groups: groupId } }); + Accounts.update( + { _id: { $in: matchingUserIds }, shopId }, + { $addToSet: { groups: groupId } }, + { multi: true } + ); + return matchingUserIds; } }, down() { @@ -66,3 +103,19 @@ Migrations.add({ } } }); + +function sortUniqueArray(multiArray) { + const sorted = multiArray.map(x => { + if (!x) { return []; } + return x.sort(); + }).sort(); + const uniqueArray = []; + uniqueArray.push(sorted[0]); + + for (let i = 1; i < sorted.length; i++) { + if (JSON.stringify(sorted[i]) !== JSON.stringify(sorted[i - 1])) { + uniqueArray.push(sorted[i]); + } + } + return uniqueArray; +} From 2393ab7343fe5e9eb26d51e6c26c99317692bb09 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Sat, 29 Jul 2017 17:02:56 +0100 Subject: [PATCH 09/12] Add comments to document flow of migration --- .../5_update_defaultRoles_to_groups.js | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index 48f4147586c..c7a16daad0b 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -4,23 +4,28 @@ import { Migrations } from "/imports/plugins/core/versions"; import { Logger } from "/server/api"; import { Accounts, Groups, Shops } from "/lib/collections"; +/** + * Migration file created for moving from previous admin permission management to permission groups + * On up, it creates the default groups for all shops in the app, then update accounts belonging to the + * default groups. It also creates custom groups for every unique set of permission and assigns accounts + * with such permissions to the custom group they belong. + */ Migrations.add({ version: 5, up() { const shops = Shops.find({}).fetch(); - Groups.remove({}); + Groups.remove({}); // needed to ensure restart in case of a migration that failed before finishing if (shops && shops.length) { shops.forEach((shop) => { const defaultGroupAccounts = createDefaultGroupsForShop(shop); - + // retrieves remaining permission sets that doesn't fit the default sets const customPermissions = Meteor.users .find({ _id: { $nin: defaultGroupAccounts } }) .fetch() .map(user => user.roles[shop._id]); - + // sorts the array of permission sets to contain only unique sets to avoid creating groups with same permissions const permissionsArray = sortUniqueArray(customPermissions); - permissionsArray.forEach((permissions, index) => { Logger.info(`creating custom group for shop ${shop.name}`); const groupId = Groups.insert({ @@ -66,6 +71,7 @@ Migrations.add({ return defaultGroupAccounts; } + // finds all accounts with a permission set and assigns them to matching group function updateAccountsInGroup({ shopId, permissions, groupId }) { const query = { [`roles.${shopId}`]: { $size: permissions.length, $all: permissions } }; const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); @@ -98,12 +104,24 @@ Migrations.add({ shopGroups.forEach((group) => { const shopkey = keys[group.slug]; Shops.update({ _id: shop._id }, { $set: { [shopkey]: group.permissions } }); - Accounts.update({ shopId: shop._id }, { $unset: { groups: "" } }); + Accounts.update({ shopId: shop._id }, { $unset: { groups: "" } }, { multi: true }); }); } } }); +/* + * helper func created to limit the permission sets available to unique values without duplicates. + * It takes a two dimentional array like this: + * [ + * ["tag", "product"], + * ["product", "tag"], + * ["tag", "product", "shop"], + * ["tag", "shop"], + * ["shop", "tag"] + * ] + * and returns this: [["product", "tag"], ["product", "shop", "tag"], ["shop", "tag"]] + */ function sortUniqueArray(multiArray) { const sorted = multiArray.map(x => { if (!x) { return []; } From 1477059a72dadd73312e9801b0664033d3b2877c Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Sat, 29 Jul 2017 17:47:23 +0100 Subject: [PATCH 10/12] Prevent error on user without roles field in tests --- .../server/migrations/5_update_defaultRoles_to_groups.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index c7a16daad0b..07a59bde490 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -23,10 +23,11 @@ Migrations.add({ const customPermissions = Meteor.users .find({ _id: { $nin: defaultGroupAccounts } }) .fetch() - .map(user => user.roles[shop._id]); + .map(user => user.roles && user.roles[shop._id]); // sorts the array of permission sets to contain only unique sets to avoid creating groups with same permissions const permissionsArray = sortUniqueArray(customPermissions); permissionsArray.forEach((permissions, index) => { + if (!permissions) { return null; } Logger.info(`creating custom group for shop ${shop.name}`); const groupId = Groups.insert({ name: `custom ${index + 1}`, @@ -72,7 +73,7 @@ Migrations.add({ } // finds all accounts with a permission set and assigns them to matching group - function updateAccountsInGroup({ shopId, permissions, groupId }) { + function updateAccountsInGroup({ shopId, permissions = [], groupId }) { const query = { [`roles.${shopId}`]: { $size: permissions.length, $all: permissions } }; const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); From d9c5276efdc6b0ed0ddf15a08ad53c42135387e5 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Sat, 29 Jul 2017 19:04:12 +0100 Subject: [PATCH 11/12] Change info logs to debug --- .../server/migrations/5_update_defaultRoles_to_groups.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index 07a59bde490..fcdbbfbbe8d 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -28,7 +28,7 @@ Migrations.add({ const permissionsArray = sortUniqueArray(customPermissions); permissionsArray.forEach((permissions, index) => { if (!permissions) { return null; } - Logger.info(`creating custom group for shop ${shop.name}`); + Logger.debug(`creating custom group for shop ${shop.name}`); const groupId = Groups.insert({ name: `custom ${index + 1}`, slug: `custom${index + 1}`, @@ -54,14 +54,14 @@ Migrations.add({ }; Object.keys(roles).forEach((groupKeys) => { - Logger.info(`creating group ${groupKeys} for shop ${shop.name}`); + Logger.debug(`creating group ${groupKeys} for shop ${shop.name}`); const groupId = Groups.insert({ name: groupKeys, slug: groupKeys, permissions: roles[groupKeys], shopId: shop._id }); - Logger.info(`new group "${groupKeys}" created with id "${groupId}"`); + Logger.debug(`new group "${groupKeys}" created with id "${groupId}"`); const updatedAccounts = updateAccountsInGroup({ shopId: shop._id, permissions: roles[groupKeys], @@ -78,7 +78,7 @@ Migrations.add({ const matchingUserIds = Meteor.users.find(query).fetch().map((user) => user._id); if (matchingUserIds.length) { - Logger.info(`updating following matching Accounts to new group: ${matchingUserIds}`); + Logger.debug(`updating following matching Accounts to new group: ${matchingUserIds}`); } Accounts.update( { _id: { $in: matchingUserIds }, shopId }, From d99f6abfb1792782a6bead986a29d5fc9da2eb16 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Sat, 29 Jul 2017 19:36:54 +0100 Subject: [PATCH 12/12] Add comment --- .../plugins/core/accounts/client/components/groupsTableCell.js | 1 + .../server/migrations/5_update_defaultRoles_to_groups.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/imports/plugins/core/accounts/client/components/groupsTableCell.js b/imports/plugins/core/accounts/client/components/groupsTableCell.js index 5f20c2a2835..415e60904bc 100644 --- a/imports/plugins/core/accounts/client/components/groupsTableCell.js +++ b/imports/plugins/core/accounts/client/components/groupsTableCell.js @@ -8,6 +8,7 @@ const GroupsTableCell = ({ account, columnName, group, groups, handleRemoveUserF const email = _.get(account, "emails[0].address"); if (columnName === "name") { + // use first part of email, if account has no name const name = account.name || email.split("@")[0]; return (
diff --git a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js index 5825bfe7036..d21541fb6a8 100644 --- a/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js +++ b/imports/plugins/core/versions/server/migrations/5_update_defaultRoles_to_groups.js @@ -64,7 +64,6 @@ Migrations.add({ permissions: roles[groupKeys], shopId: shop._id }); - Logger.debug(`new group "${groupKeys}" created with id "${groupId}"`); const updatedAccounts = updateAccountsInGroup({ shopId: shop._id,