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

[Marketplace] Feature - Permissions should be settable by placing a user into a predefined group #2448

Merged
merged 67 commits into from
Jul 6, 2017

Conversation

impactmass
Copy link
Contributor

@impactmass impactmass commented Jun 15, 2017

Permission groups. Implements #2184
This PR has the Meteor methods to manage permission groups. It specifically adds group/createGroup, group/updateGroup, group/addUser, group/removeUser.
The UI for this is being handled separately (as that involved changing a lot of the current Accounts section of admin dashboard).

To test:
_ Take a look at the tests, to have a sense of how the methods work
_ The methods can be tested from the browser console of a running Reaction (via Meteor.call and passing the needed values). See the jsdocs added for the descriptions of the arguments.

  • Start Reaction
  • Create a shop (i.e register as a user (not the owner). Go to "Profile", click "Become a Seller"
  • Create a group, by calling group/createGroup from console, passing in the required options.
  • Confirm in db that a new doc is created in Groups collection
  • Add a user to the group by calling group/addUser as described
  • Confirm that the user's permissions gets updated (i.e Meteor.user.roles) and that the user's Account doc now has the groupId.
  • The other methods follow similar pattern as shown in the tests

Other notes:
_ Groups exits as a schema
_ Group Ids are referenced on Accounts to track which users belong to a group

spencern and others added 25 commits June 6, 2017 12:20
* Modifies Shops publication to return all shops with matching domain by removing limit
* Rewrite of shop selector dropdown
* Use Shops publication instead of SellerShops publication in dropdown
* Remove requirement for marketplace ownership to see shop selector
* Change Reaction.ShopId when shop selector is changed
* TODO: Convert shop selector to React
@impactmass impactmass changed the title [WIP] Permission Groups [Marketplace] Permissions should be settable by placing a user into a predefined group Jun 29, 2017
@impactmass impactmass changed the title [Marketplace] Permissions should be settable by placing a user into a predefined group [Marketplace] Feature - Permissions should be settable by placing a user into a predefined group Jun 29, 2017
@impactmass impactmass requested a review from spencern June 29, 2017 19:04
Copy link
Contributor

@spencern spencern left a comment

Choose a reason for hiding this comment

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

Have a few questions, mostly around how the group _id gets ingested into the system. I think this is almost ready.

We should probably also add a few additional test cases to cover shops with several groups

@@ -107,6 +107,11 @@ export const Accounts = new SimpleSchema({
type: Profile,
optional: true
},
groups: {
type: [String],
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an array of group ids, correct? Would be nice to have comments here explaining what goes here and what the default means.

groups: {
type: [String],
optional: true,
defaultValue: []
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this default to a user having no permissions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. It's just means at the schema level, they don't belong to a group yet. Although, on account creation, the array then receives either "guest" or "customer".

spyOnMethod("createGroup", shop._id);

Meteor.call("group/createGroup", sampleGroup, shop._id);
const group = Groups.findOne({ shopId: shop._id });
Copy link
Contributor

Choose a reason for hiding this comment

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

How would we find this group if there were more than one for this particular shop? By _id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finding groups belonging to a shop can be done with the slug property. More can be seen in addDefaultRoles.app-test.js. This is just doing a findOne because just one group was added in the beforeEach.

const newGroupData = Object.assign({}, sampleGroup, { permissions: ["new-permissions"] });
Meteor.call("group/updateGroup", group._id, newGroupData, shop._id);
updatedUser = Meteor.users.findOne({ _id: user._id });
expect(updatedUser.roles[shop._id]).to.include.members(newGroupData.permissions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a test to make sure the permissions that the old group had, but the new group does not have are no longer included.

throw new Meteor.Error(400, "Bad request");
}

return { status: 200 };
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably return the _id of the created group here as well?

* Reaction Permission Group Methods
*/
Meteor.methods({
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Great job with jsdoc here.

@impactmass
Copy link
Contributor Author

Brought the other work of default groups into here (since they're closely linked, and better reviewed from together after discussing with Spencer). So, server implementation for #2184 along with #2194 is here.

@@ -19,6 +19,7 @@ Template.registerHelper("reactionTemplate", function (options) {
const shopId = options.hash.shopId || Reaction.getShopId();
// get shop info, defaults to current
const Shop = Collections.Shops.findOne(shopId);
const defaultRoles = Collections.Groups.findOne({ slug: "customer", shopId }).permissions;
Copy link
Contributor

@spencern spencern Jul 6, 2017

Choose a reason for hiding this comment

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

Do we need to ensure that defaultRoles are loaded at this point? (e.g. subscription.ready())? Maybe this is done already in another place

Copy link
Contributor

Choose a reason for hiding this comment

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

This helper is only used in the checkout right now it seems, and even if we load the checkout directly default roles are ready, so I think we're good to go here.

Copy link
Contributor

@spencern spencern left a comment

Choose a reason for hiding this comment

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

Excited to have this merged into marketplace

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.

3 participants