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

refactor: remove removeAccountFromGroup meteor method and rewrite with GraphQL #5493

Merged
merged 16 commits into from
Sep 5, 2019

Conversation

kieckhafer
Copy link
Member

Resolves #5339
Impact: minor
Type: feature|refactor

Issue

removeAccountFromGroup still uses a meteor method to perform its actions.

Solution

Rewrite removeAccountFromGroup mutation to use GraphQL instead of meteor method.

  • Remove removeAccountFromGroup meteor method from app

Breaking changes

Nothing in core code. Any custom code calling the group/removeUser Meteor method will break.

Testing

  1. In Reaction Admin, invite a new user to a group
  2. Remove that user from group (no need to set up email / confirm the user, you can remove them without them setting up their account)

@kieckhafer kieckhafer requested a review from aldeed August 28, 2019 21:23
Signed-off-by: Erik Kieckhafer <[email protected]>
@aldeed aldeed mentioned this pull request Aug 28, 2019
45 tasks
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
@kieckhafer kieckhafer changed the title refactor: remove removeAccountFromGroup meteor method and rewrite with GraphQL [WIP] refactor: remove removeAccountFromGroup meteor method and rewrite with GraphQL Aug 28, 2019
@kieckhafer kieckhafer changed the title [WIP] refactor: remove removeAccountFromGroup meteor method and rewrite with GraphQL refactor: remove removeAccountFromGroup meteor method and rewrite with GraphQL Sep 3, 2019
@kieckhafer
Copy link
Member Author

@aldeed updated this PR, removed [WIP].


// we are limiting group method actions to only users with admin roles
// this also include shop owners, since they have the `admin` role in their Roles.GLOBAL_GROUP
if (!userHasPermission(["admin"], shopId)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldeed I didn't add an internalCall check here, based on the comment that only admins should be able to make this change (the comment persists from the previous meteor code)

groupId
} = input;

const { shopId } = await Groups.findOne({ _id: groupId }) || {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no group is found, then shopId would be undefined which I think would cause either an error or unexpected results from the userHasPermission call below. It would be better to do an explicit check before the permission check.

if (!group) throw new ReactionError("not-found", "Group not found");


// get default roles for a customer, which is the group
// this user will belong to after being removed from previous group
const defaultCustomerGroupForShop = await Groups.findOne({ slug: "customer", shopId }) || {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the || {} and throw error if (!defaultCustomerGroupForShop). Otherwise it will just throw less clear errors when accessing defaultCustomerGroupForShop.permissions below.

updatedFields: ["groups"]
});

return defaultCustomerGroupForShop;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit strange that we decided to return the group at all, and the docs are not clear about which group is returned, but to me it seems more logical to expect the removed group back rather than the new group. So I would return group instead of defaultCustomerGroupForShop.

It's actually a poorly named mutation in general, because it's actually changing the account group (to "customer") rather than just removing them from a group. I guess that's because we wanted everybody to always be in exactly one group per shop. So I'd argue we don't really need this mutation. You can call addAccountToGroup with the "customer" group, and it will do mostly the same thing. (Even that one would be better named setAccountGroupForShop.)

There is also a slight difference between those two mutations, which is a bit worrying. When switching back to the "customer" group here, we simply overwrite the full roles list for the shop, setting it to match the customer group permissions. But in addAccountToGroup, we delete all roles from the previous group and then add all roles from the new group. The difference is that addAccountToGroup way would keep one-off roles that have been added directly to a user outside the group paradigm. I don't know if this is really what we want or if users should have only the permissions from the group they are in and no others.

All of that being said, it doesn't seem like any core code actually calls removeAccountFromGroup, so how about you address these comments here but then mark it deprecated in the gql schema so that we can remove it in the next major release? The roles logic in addAccountToGroup is fine for now but we may want to raise the question of whether extra roles should be allowed on users (fits in with the work of the identity+auth pod that is starting).

@kieckhafer
Copy link
Member Author

@aldeed comments addressed

@kieckhafer kieckhafer requested a review from aldeed September 4, 2019 17:19
@aldeed aldeed merged commit 8d57ec6 into develop Sep 5, 2019
@aldeed aldeed deleted the ref-kieckhafer-removeAccountFromGroupGQL branch September 5, 2019 00:15
@kieckhafer kieckhafer mentioned this pull request Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants