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

Rewrite addAccountToGroup to not call through to Meteor method #5431

Merged
merged 18 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from 12 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
190 changes: 0 additions & 190 deletions imports/meteor-app-tests/groups.app-test.js

This file was deleted.

1 change: 1 addition & 0 deletions imports/node-app/core/util/getErrorFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function getErrorFormatter() {
const eventObj = {
errorId: err.errorId,
path: err.path,
stack: originalError.stack,
...(originalError.eventData || {})
};

Expand Down
6 changes: 4 additions & 2 deletions imports/node-app/core/util/getErrorFormatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ test("if originalError is present, logs the error with some additional details",
expect(LoggerMock.error).toHaveBeenCalledWith(
{
errorId: jasmine.any(String),
path: "PATH"
path: "PATH",
stack: jasmine.any(String)
},
message
);
Expand All @@ -63,7 +64,8 @@ test("if originalError is validation-error, uses details[0].message", () => {
expect(LoggerMock.error).toHaveBeenCalledWith(
{
errorId: jasmine.any(String),
path: "PATH"
path: "PATH",
stack: jasmine.any(String)
},
message
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import { Components, registerComponent, withPermissions } from "@reactioncommerce/reaction-components";
import { Components, registerComponent } from "@reactioncommerce/reaction-components";

/**
* @summary React stateless component for "remove from group" button for groupTable
Expand All @@ -10,38 +10,26 @@ import { Components, registerComponent, withPermissions } from "@reactioncommerc
* @property {Object} account - User account object
* @property {Object} group - Group data
* @property {Function} handleRemoveUserFromGroup - function to call on button click
* @property {Boolean} hasPermissions - true or false depending on if user is granted access
* @return {Node} React node containing wrapped button
*/
const GroupsTableButton = ({ account, group, handleRemoveUserFromGroup, hasPermissions }) => {
if (group.slug === "owner") {
return null;
}

if (!hasPermissions) {
return null;
}

return (
<div className="group-table-button">
<Components.Button
status="danger"
onClick={handleRemoveUserFromGroup(account, group._id)}
bezelStyle="solid"
i18nKeyLabel="admin.groups.remove"
label="Remove"
/>
</div>
);
};
const GroupsTableButton = ({ account, group, handleRemoveUserFromGroup }) => (
<div className="group-table-button">
<Components.Button
bezelStyle="solid"
i18nKeyLabel="admin.groups.remove"
label="Remove"
onClick={handleRemoveUserFromGroup(account, group._id)}
status="danger"
/>
</div>
);

GroupsTableButton.propTypes = {
account: PropTypes.object,
group: PropTypes.object, // current group in interation
handleRemoveUserFromGroup: PropTypes.func,
hasPermissions: PropTypes.bool
group: PropTypes.object, // current group in interaction
handleRemoveUserFromGroup: PropTypes.func
};

registerComponent("GroupsTableButton", GroupsTableButton, withPermissions({ roles: ["accounts"] }));
registerComponent("GroupsTableButton", GroupsTableButton);

export default GroupsTableButton;
29 changes: 12 additions & 17 deletions imports/plugins/core/accounts/client/components/groupsTableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ const GroupsTableCell = (props) => {
}

if (columnName === "dropdown") {
const groupName = <span className="group-dropdown">{_.startCase(groups[0].name)}</span>;
const groupName = group.name && _.startCase(group.name);
const groupNameSpan = <span className="group-dropdown">{groupName}</span>;
const ownerGroup = groups.find((grp) => grp.slug === "owner") || {};
const hasOwnerAccess = Reaction.hasPermission("owner", Reaction.getUserId(), Reaction.getShopId());

if (groups.length === 1) {
return groupName;
}
// Permission check. Remove owner option, if user is not current owner.
// Also remove groups user does not have roles to manage. This is also checked on the server
const dropOptions = groups
.filter((grp) => !((grp.slug === "owner" && !hasOwnerAccess)))
.filter((grp) => Reaction.canInviteToGroup({ group: grp })) || [];

if (group.slug === "owner") {
return groupName;
if (dropOptions.length < 2) {
return groupNameSpan;
}

const { onMethodDone, onMethodLoad } = props;
const dropDownButton = (opt) => ( // eslint-disable-line
<div className="group-dropdown">
<Components.Button bezelStyle="solid" label={group.name && _.startCase(group.name)}>
Expand All @@ -75,21 +77,14 @@ const GroupsTableCell = (props) => {
</div>
);

// Permission check. Remove owner option, if user is not current owner.
// Also remove groups user does not have roles to manage. This is also checked on the server
const dropOptions = groups
.filter((grp) => !((grp.slug === "owner" && !hasOwnerAccess)))
.filter((grp) => Reaction.canInviteToGroup({ group: grp })) || [];

if (dropOptions.length < 2) { return dropDownButton(); } // do not use dropdown if only one option

const { onMethodDone, onMethodLoad } = props;
return (
<div className="group-dropdown">
<Components.DropDownMenu
buttonElement={dropDownButton(groups)}
attachment="bottom right"
targetAttachment="top right"
onChange={handleUserGroupChange({ account, ownerGrpId: ownerGroup._id, onMethodDone, onMethodLoad })}
onChange={handleUserGroupChange({ account, currentGroupId: group._id, ownerGrpId: ownerGroup._id, onMethodDone, onMethodLoad })}
>
{dropOptions
.filter((grp) => grp._id !== group._id)
Expand Down Expand Up @@ -117,7 +112,7 @@ GroupsTableCell.propTypes = {
account: PropTypes.object,
adminGroups: PropTypes.array, // all admin groups
columnName: PropTypes.string,
group: PropTypes.object, // current group in interation
group: PropTypes.object, // current group in interaction
handleRemoveUserFromGroup: PropTypes.func,
handleUserGroupChange: PropTypes.func,
moment: PropTypes.func,
Expand Down
Loading