Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Shop Manager" as a default group #2602

Merged
merged 16 commits into from
Jul 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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