-
Couldn't load subscription status.
- Fork 2.2k
code injection, integration with reaction-filtration #743
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
Changes from all commits
2629db3
574e818
6de84a5
23bb42f
c664a76
c308238
f30efbc
1f4db39
f3ad751
d0cf3cd
0222a4b
9ca4bfc
c20160a
53d850f
10e66fd
943b97d
db8f687
571ed33
ad8aa1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,3 +75,5 @@ reactioncommerce:default-theme # default Reaction theme | |
| # Forced updates on packages | ||
| mdg:[email protected] | ||
| cosmos:[email protected] | ||
|
|
||
| ramusus:reaction-filtration | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,8 @@ mdg:[email protected] | |
| mdg:[email protected] | ||
| [email protected] | ||
| [email protected] | ||
| meteorhacks:[email protected] | ||
| meteorhacks:[email protected] | ||
| meteorhacks:[email protected] | ||
| meteorhacks:[email protected] | ||
| mikowals:[email protected] | ||
|
|
@@ -130,6 +132,7 @@ [email protected] | |
| [email protected] | ||
| raix:[email protected] | ||
| raix:[email protected] | ||
| ramusus:[email protected] | ||
| [email protected] | ||
| [email protected] | ||
| [email protected] | ||
|
|
@@ -182,6 +185,7 @@ [email protected] | |
| [email protected] | ||
| [email protected] | ||
| [email protected] | ||
| tmeasday:[email protected] | ||
| [email protected] | ||
| [email protected] | ||
| [email protected] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ Package.onUse(function (api) { | |
| api.use("ongoworks:[email protected]"); | ||
| api.use("alanning:[email protected]"); | ||
| api.use("meteorhacks:[email protected]"); | ||
| api.use("tmeasday:[email protected]"); | ||
|
|
||
| // ReactionCore declaration | ||
| api.addFiles("common/globals.js"); | ||
|
|
@@ -74,6 +75,7 @@ Package.onUse(function (api) { | |
| api.imply("vsivsi:job-collection"); | ||
| api.imply("ongoworks:security"); | ||
| api.imply("alanning:roles"); | ||
| api.imply("tmeasday:publish-counts"); | ||
| api.imply("alanning:roles"); | ||
| api.imply("meteorhacks:subs-manager"); | ||
| api.imply("reactioncommerce:reaction-schemas"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,32 @@ | |
| Meteor.publish("Products", function (productScrollLimit, productFilters) { | ||
| check(productScrollLimit, Match.OneOf(null, undefined, Number)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could simplify it like this: const filters = new SimpleSchema({
"shops": {type: [String], optional: true},
"tag": {type: String, optional: true},
"query": {type: String, optional: true},
"visibility": {type: Boolean, optional: true},
"details": {type: Object, optional: true},
"details.key": {type: String},
"details.value": {type: String},
"price": {type: Object, optional: true},
"price.min": {type: Number},
"price.max": {type: Number},
"weight": {type: Object, optional: true},
"weight.min": {type: Number},
"weight.max": {type: Number}
})
Meteor.publish("Products", function (productScrollLimit, productFilters) {
new SimpleSchema({
productScrollLimit: { type: Number, optional: true },
productFilters: { type: filters, optional: true }
}).validator()
...I think it should work not only in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already tried this and I learned, that we can not completely substitute check() with SS validator, because check package will throw error "not all arguments of publication are checked with check()". Try/catch we need, because validate() throws ValidationError and inside publication will fails silently without and log message (for me that is strange). We need throw Meteor error again to stop continue publication with wrong format of arguments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a feeling that we can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can in the way I did. |
||
| check(productFilters, Match.OneOf(null, undefined, Object)); | ||
| try { | ||
| new SimpleSchema({ | ||
| "shops": {type: [String], optional: true}, | ||
| "tag": {type: String, optional: true}, | ||
| "query": {type: String, optional: true}, | ||
| "visibility": {type: Boolean, optional: true}, | ||
| "details": {type: Object, optional: true}, | ||
| "details.key": {type: String}, | ||
| "details.value": {type: String}, | ||
| "price": {type: Object, optional: true}, | ||
| "price.min": {type: Number}, | ||
| "price.max": {type: Number}, | ||
| "weight": {type: Object, optional: true}, | ||
| "weight.min": {type: Number}, | ||
| "weight.max": {type: Number} | ||
| }).validate(productFilters); | ||
| } catch (e) { | ||
| ReactionCore.Log.error(e); | ||
| throw new Meteor.Error(e); | ||
| } | ||
|
|
||
| let shopAdmin; | ||
| const limit = productScrollLimit || 10; | ||
| const shop = ReactionCore.getCurrentShop(); | ||
| const Products = ReactionCore.Collections.Products; | ||
| let sort = {title: 1}; | ||
| const sort = {title: 1}; | ||
|
|
||
| if (typeof shop !== "object") { | ||
| return this.ready(); | ||
|
|
@@ -24,7 +44,6 @@ Meteor.publish("Products", function (productScrollLimit, productFilters) { | |
| if (productFilters) { | ||
| // handle multiple shops | ||
| if (productFilters.shops) { | ||
| check(productFilters.shops, Array); | ||
| _.extend(selector, {shopId: {$in: productFilters.shops}}); | ||
|
|
||
| // check if this user is a shopAdmin | ||
|
|
@@ -37,16 +56,48 @@ Meteor.publish("Products", function (productScrollLimit, productFilters) { | |
|
|
||
| // filter by tag | ||
| if (productFilters.tag) { | ||
| check(productFilters.tag, String); | ||
| _.extend(selector, {hashtags: {$in: [productFilters.tag]}}); | ||
| } | ||
|
|
||
| // filter by query | ||
| if (productFilters.query) { | ||
| let cond = {$regex: productFilters.query, $options: "i"}; | ||
| _.extend(selector, {$or: [{title: cond}, {pageTitle: cond}, {description: cond}]}); | ||
| } | ||
|
|
||
| // filter by details | ||
| if (productFilters.details) { | ||
| _.extend(selector, {metafields: {$elemMatch: {key: {$regex: productFilters.details.key, $options: "i"}, | ||
| value: {$regex: productFilters.details.value, $options: "i"}}}}); | ||
| } | ||
|
|
||
| // filter by visibility | ||
| if (productFilters.visibility !== undefined) { | ||
| _.extend(selector, {isVisible: productFilters.visibility}); | ||
| } | ||
|
|
||
| // filter by price | ||
| if (productFilters.price) { | ||
| _.extend(selector, {variants: {$elemMatch: {price: {$gte: productFilters.price.min, | ||
| $lte: productFilters.price.max}}}}); | ||
| } | ||
|
|
||
| // filter by weight | ||
| if (productFilters.weight) { | ||
| _.extend(selector, {variants: {$elemMatch: {weight: {$gte: productFilters.weight.min, | ||
| $lte: productFilters.weight.max}}}}); | ||
| } | ||
| } | ||
|
|
||
| // products are always visible to owners | ||
| if (!(Roles.userIsInRole(this.userId, ["owner"], shop._id) || shopAdmin)) { | ||
| selector.isVisible = true; | ||
| } | ||
|
|
||
| ReactionCore.Log.debug("Products publication limit", productScrollLimit); | ||
| ReactionCore.Log.debug("Products publication selector", EJSON.stringify(selector)); | ||
|
|
||
| Counts.publish(this, "Products", Products.find(selector), {noReady: true}); | ||
| return Products.find(selector, { | ||
| sort: sort, | ||
| limit: limit | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <template name="products"> | ||
| {{>productGrid tag}} | ||
| {{>productGrid}} | ||
| </template> | ||
|
|
||
| <template name="productListGrid"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ Package.onUse(function (api) { | |
| // community packages | ||
| api.use("reactioncommerce:[email protected]"); | ||
| api.use("reactioncommerce:[email protected]"); | ||
| api.use("ramusus:[email protected]"); | ||
|
|
||
| // register package | ||
| api.addFiles("server/register.js", "server"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ Package.onUse(function (api) { | |
| api.use("blaze-html-templates"); | ||
| api.use("accounts-base"); | ||
| api.use("reactioncommerce:[email protected]"); | ||
| api.use("ramusus:[email protected]"); | ||
|
|
||
| // flow-router packages | ||
| api.use("kadira:[email protected]"); | ||
| api.use("kadira:[email protected]"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package doesn't seem to be very well maintained,(source has deprecated Meteor code) and warns
This package is designed primarily for correctness, not performance. That's why it's aimed at counting smaller datasets and keeping the count instantly up to date.Is this the best choice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree completely, this notice also make me hesitate about using it. I will try to find another way of getting reactive count value.