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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
01c94a3
Give all users access to shop selector.
spencern Jun 6, 2017
ac4494a
Set ShopId on shop selector change
spencern Jun 6, 2017
8b3df17
Merge branch 'spencer-code-cleanup' into marketplace-shop-switcher
spencern Jun 6, 2017
44ed9bc
Regular Shop Selector should just adjust only the route.
spencern Jun 8, 2017
150514f
Remove empty line at top of navbar
spencern Jun 8, 2017
8947d2c
Change Reaction.shopId to be a ReactiveVar
spencern Jun 8, 2017
9cc050d
Add closeOnClick option to DropDownMenu
spencern Jun 8, 2017
6af82e8
Add shop selector to admin toolbar.
spencern Jun 8, 2017
deae717
WIP - tons of code not committed - Init switching away from getSeller…
spencern Jun 9, 2017
6db6fe1
Switches dashboard context as well as published packages based on act…
spencern Jun 12, 2017
71f7073
Init group file
impactmass Jun 12, 2017
0ef424b
create group
impactmass Jun 12, 2017
f82956b
Test update
impactmass Jun 12, 2017
e82fb99
Considering side effects after group change
impactmass Jun 13, 2017
b6b93ef
multi update on groupname
impactmass Jun 13, 2017
ee999a9
Updating user after group change
impactmass Jun 13, 2017
1f55590
Simpleschema fix
impactmass Jun 14, 2017
13430c8
Resolve update when group name changes
impactmass Jun 14, 2017
9011584
add combinedroles
impactmass Jun 14, 2017
8d24925
Fix error
impactmass Jun 14, 2017
f0cb22c
Init group/addUser
impactmass Jun 15, 2017
951fb0e
Updating user group array and roles
impactmass Jun 15, 2017
d997f2a
more error handling on functions
impactmass Jun 15, 2017
448df6f
debug group/adduser
impactmass Jun 15, 2017
005d659
set field to optional
impactmass Jun 15, 2017
c547026
Update to remove user
impactmass Jun 16, 2017
71ecdf4
Update to remove user
impactmass Jun 16, 2017
63188cb
Refactoring updates on groups user belongs to
impactmass Jun 19, 2017
f688503
Refactoring updates on group name
impactmass Jun 19, 2017
6698d8c
Quick template scaffold to test adding perms to group
impactmass Jun 19, 2017
d706316
Connect update method to event
impactmass Jun 19, 2017
c263417
Update comments
impactmass Jun 20, 2017
0a54f26
Quickly scaffold component
impactmass Jun 20, 2017
0d8b8fe
Updates from first review
impactmass Jun 21, 2017
2714be1
Adding new values to groups
impactmass Jun 21, 2017
54660d0
Add more fields and uniqueness
impactmass Jun 21, 2017
028faa2
Hopefully final fixes
impactmass Jun 22, 2017
ff20eea
Track with id
impactmass Jun 22, 2017
0cbd6da
Switch use of Roles to R.haspermission
impactmass Jun 23, 2017
06936e5
Add tests for createGroup and addUser
impactmass Jun 23, 2017
bcfdffd
Update tests and change _id to groupId
impactmass Jun 28, 2017
14276f8
Change to object-type schema
impactmass Jun 28, 2017
ae56444
Update tests to match schema
impactmass Jun 28, 2017
407c428
Modify and add test for updateGroup
impactmass Jun 28, 2017
0b10d3c
Merge branch 'marketplace' into seun-create-groups-2184
impactmass Jun 28, 2017
fde269b
Remove un-needed ui stuffs
impactmass Jun 28, 2017
a81ddb3
Cleanup
impactmass Jun 28, 2017
3931e62
Remove done in before and add method to mock
impactmass Jun 29, 2017
4b62ab6
Fixing tests
impactmass Jun 29, 2017
09340b7
Update to test
impactmass Jun 29, 2017
63c653c
Refactor
impactmass Jun 29, 2017
f9f141d
Test changes after refactor
impactmass Jun 29, 2017
4d71287
Fix lint issue
impactmass Jun 29, 2017
8dee184
Initial switching roles to groups
impactmass Jun 30, 2017
8091822
Remove comment in json
impactmass Jun 30, 2017
c691632
Fixes on default customer group
impactmass Jul 3, 2017
5d4bb0b
Default guest grp
impactmass Jul 3, 2017
c13c9e4
Fixing tests and changes to groups init
impactmass Jul 5, 2017
8e330ee
one group type per shop
impactmass Jul 5, 2017
14e42a2
one group type per shop during init
impactmass Jul 5, 2017
f93c76d
Set default group on user when signup
impactmass Jul 5, 2017
26ea9c6
Fixing addDefaultRoles.app-test.js
impactmass Jul 5, 2017
fc07e12
Comments and hook function
impactmass Jul 5, 2017
b5820e1
Add test fo new group placement
impactmass Jul 6, 2017
4c6c5b1
Remove console log
impactmass Jul 6, 2017
b94a22c
Add test for group uniqueness per shop
impactmass Jul 6, 2017
975f8c4
Change addDefaultRoles method to use groups.
spencern Jul 6, 2017
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
3 changes: 2 additions & 1 deletion client/modules/core/helpers/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

const reactionTemplates = [];
// fetch collection from shop.layout configuration
let layout = _.find(Shop.layout, {
Expand Down Expand Up @@ -72,7 +73,7 @@ Template.registerHelper("reactionTemplate", function (options) {
for (layout of layoutWorkflows) {
// audience is layout permissions
if (layout.audience === undefined) {
layout.audience = Shop.defaultRoles || "owner";
layout.audience = defaultRoles || "owner";
}

// check permissions so you don't have to on template.
Expand Down
2 changes: 2 additions & 0 deletions client/modules/core/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Subscriptions.SellerShops = Subscriptions.Manager.subscribe("SellerShops");

Subscriptions.Tags = Subscriptions.Manager.subscribe("Tags");

Subscriptions.Groups = Subscriptions.Manager.subscribe("Groups");

Subscriptions.Media = Subscriptions.Manager.subscribe("Media");

/**
Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/accounts/server/init.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Reaction, Hooks } from "/server/api";

Hooks.Events.add("afterCoreInit", () => {
Reaction.addRolesToDefaultRoleSet({
Reaction.addRolesToGroups({
allShops: true,
roleSets: ["defaultRoles", "defaultVisitorRole"],
groups: ["guest", "customer"],
roles: ["account/verify"]
});
});
12 changes: 5 additions & 7 deletions imports/plugins/core/checkout/server/methods/workflow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from "lodash";
import { Meteor } from "meteor/meteor";
import { check, Match } from "meteor/check";
import { Cart, Orders, Packages, Shops } from "/lib/collections";
import { Cart, Orders, Packages, Groups } from "/lib/collections";
import { Logger, Reaction } from "/server/api";

/* eslint no-shadow: 0 */
Expand Down Expand Up @@ -64,12 +64,10 @@ Meteor.methods({
_.each(layouts, function (layout) {
// audience is the layout permissions
if (typeof layout.audience !== "object") {
const defaultRoles = Shops.findOne(
Reaction.getShopId(), {
sort: {
priority: 1
}
}).defaultRoles;
const defaultRoles = Groups.findOne({
slug: "customer",
shopId: Reaction.getShopId()
}).permissions;
layout.audience = defaultRoles;
}
// check permissions so you don't have to on template. For a case, when
Expand Down
18 changes: 6 additions & 12 deletions imports/plugins/included/notifications/server/init.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { Reaction, Hooks, Logger } from "/server/api";
import { Shops } from "/lib/collections";

function addRolesToVisitors() {
// Add the about permission to all default roles since it's available to all
Logger.debug("Adding notification route permissions to default roles");
const shop = Shops.findOne(Reaction.getShopId());
Shops.update(shop._id, {
$addToSet: { defaultRoles: "notifications" }
});
}
import { Reaction, Hooks } from "/server/api";

Hooks.Events.add("afterCoreInit", () => {
addRolesToVisitors();
Reaction.addRolesToGroups({
allShops: true,
groups: ["guest", "customer"],
roles: ["notifications"]
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Reaction, Hooks } from "/server/api";

Hooks.Events.add("afterCoreInit", () => {
Reaction.addRolesToDefaultRoleSet({
Reaction.addRolesToGroups({
allShops: true,
roleSets: ["defaultRoles", "defaultVisitorRole"],
groups: ["customer", "guest"],
roles: ["reaction-paypal/paypalDone", "reaction-paypal/paypalCancel"]
});
});
7 changes: 7 additions & 0 deletions lib/collections/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ export const Shops = new Mongo.Collection("Shops");

Shops.attachSchema(Schemas.Shop);

/**
* Groups Collection
*/
export const Groups = new Mongo.Collection("Groups");

Groups.attachSchema(Schemas.Groups);

/**
* SellerShops Collection (client-only)
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/collections/schemas/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export const Accounts = new SimpleSchema({
type: Profile,
optional: true
},
groups: {
type: [String], // groupIds that user belongs to
optional: true,
defaultValue: []
},
metafields: {
type: [Metafield],
optional: true
Expand Down
49 changes: 49 additions & 0 deletions lib/collections/schemas/groups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { SimpleSchema } from "meteor/aldeed:simple-schema";

export const Groups = new SimpleSchema({
name: {
type: String
},
description: {
type: String,
optional: true
},
slug: {
type: String
},
permissions: {
type: [String]
},
shopId: {
type: String,
regEx: SimpleSchema.RegEx.Id
},
createdBy: {
type: String,
optional: true,
regEx: SimpleSchema.RegEx.Id,
autoValue: function () {
return this.userId || this.value;
}
},
createdAt: {
type: Date,
autoValue: function () {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {
$setOnInsert: new Date
};
}
}
},
updatedAt: {
type: Date,
autoValue: function () {
return new Date;
}
}
});


1 change: 1 addition & 0 deletions lib/collections/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from "./registry";
export * from "./revisions";
export * from "./shipping";
export * from "./shops";
export * from "./groups";
export * from "./sms";
export * from "./social";
export * from "./tags";
Expand Down
8 changes: 0 additions & 8 deletions lib/collections/schemas/shops.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,6 @@ export const Shop = new SimpleSchema({
type: [Metafield],
optional: true
},
"defaultVisitorRole": {
type: [String],
defaultValue: ["anonymous", "guest", "product", "tag", "index", "cart/checkout", "cart/completed"]
},
"defaultRoles": {
type: [String],
defaultValue: ["guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"]
},
"defaultSellerRoles": {
type: [String],
defaultValue: [
Expand Down
42 changes: 2 additions & 40 deletions private/data/Shops.json
Original file line number Diff line number Diff line change
Expand Up @@ -3189,25 +3189,7 @@
"isCommercial": true,
"isShippingDefault": true,
"isBillingDefault": true
}],
"defaultVisitorRole": [
"anonymous",
"guest",
"product",
"tag",
"index",
"cart/checkout",
"cart/completed"
],
"defaultRoles": [
"account/profile",
"guest",
"product",
"tag",
"index",
"cart/checkout",
"cart/completed"
]
}]
}, {
"_id": "ddzuN2YPvgvx7rJS5",
"currencies": {
Expand Down Expand Up @@ -6395,25 +6377,5 @@
"isCommercial": true,
"isShippingDefault": true,
"isBillingDefault": true
}],
"defaultVisitorRole": [
"anonymous",
"guest",
"account/verify",
"product",
"tag",
"index",
"cart/checkout",
"cart/completed"
],
"defaultRoles": [
"account/profile",
"guest",
"product",
"account/verify",
"tag",
"index",
"cart/checkout",
"cart/completed"
]
}]
}]
Loading