Skip to content

Commit

Permalink
Add "Shop Manager" as a default group (#2602)
Browse files Browse the repository at this point in the history
* Setup up version for migrating from old permissions style to groups

* Update accounts that match on migrate and add down method

* Add shop manager as part of default groups on start and add to migration file

* Show no dropdown if shop has only one group

* If account with no name, use first part of email as name

* Switch logger to debug

* add sort to display higher permission groups at the top

* Setup searching for and creating custom group and setting users to custom

* Add comments to document flow of migration

* Prevent error on user without roles field in tests

* Change info logs to debug

* Add comment
  • Loading branch information
impactmass authored and spencern committed Jul 29, 2017
1 parent d8bbe37 commit d2b0f3e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
13 changes: 11 additions & 2 deletions imports/plugins/core/accounts/client/components/groupsTableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ 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") {
// use first part of email, if account has no name
const name = account.name || email.split("@")[0];
return (
<div className="table-cell body-first">
<img className="accounts-img-tag" src={getGravatar(account)} />
<span><b>{account.name}</b></span>
<span><b>{name}</b></span>
</div>
);
}

if (columnName === "email") {
return (
<div className="table-cell body">
<span>{_.get(account, "emails[0].address")}</span>
<span>{email}</span>
</div>
);
}
Expand All @@ -33,6 +37,11 @@ const GroupsTableCell = ({ account, columnName, group, groups, handleRemoveUserF
}

if (columnName === "dropdown") {
if (groups.length === 1) {
return (
<p>{_.startCase(groups[0].name)}</p>
);
}
const dropDownButton = (
<div className="group-dropdown">
<Components.Button label={group.name && _.startCase(group.name)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ Migrations.add({
function createDefaultGroupsForShop(shop) {
let defaultGroupAccounts = [];
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) => {
Expand Down
9 changes: 6 additions & 3 deletions server/api/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d2b0f3e

Please sign in to comment.