These are chat archives for reactioncommerce/reaction

15th
Jul 2015
Aesop7
@Aesop7
Jul 15 2015 03:03
If a developer wants to add data to each user, is it currently possible to extend the "Accounts.onCreateUser ()" function? If not, are there any plans to add that sort of functionality?
Aaron Judd
@aaronjudd
Jul 15 2015 05:02
@Aesop7 what’s the use case? Accounts.onCreateUser() is a core meteor function, you should be able to re-use as needed. For most user stuff, except authentication, we’re transitioning to using the Accounts collection and you could just extend the schema, or use a hook for additional ways of inserting custom data
Bogi
@boboci9
Jul 15 2015 12:27
@aaronjudd I finished the defaultRoles PR but before I add the pull request I wanted to some additional changes regarding the product images, mainly Media publication, I wanted to add the same shops array as we have for the products
do you agree with that?
also could you give me a hint on where do I have to change the Media restrictions so that I can allow permissions to the shop owners to their own shop's media so that they can upload images to their own products?
Bogi
@boboci9
Jul 15 2015 12:47
I was looking for something like
    ReactionCore.Collections.Media.files.permit(['insert', 'update', 'remove']).ifHasRole('admin', shop).apply();
Aaron Judd
@aaronjudd
Jul 15 2015 16:02
@boboci9 is this what you are looking for? security.coffee
###
Security.permit(['insert', 'update', 'remove'])
  .collections([Media])
  .ifHasRole({ role: ['admin','owner','createProduct'], group: ReactionCore.getShopId()} )
  .ifFileBelongsToShop()
looks like it should already be working for you
I need to look into it some more, but I feel like shopId is being stored in the image metadata as well, so maybe some changes to the publication is needed?
Bogi
@boboci9
Jul 15 2015 16:08
but this will only give permission to the current shopId
not to the shop of the seller
that is what I'm looking for to change
do you have any suggestions?
Aaron Judd
@aaronjudd
Jul 15 2015 17:17
well I think the goal is to refactor ReactionCore.getShopId() so that it's reactive and can be changed.
Bogi
@boboci9
Jul 15 2015 17:45
but in case of a multi vendor setup the main shop Id has to remain the same and the seller would be in charge of his own shop products and upload the products there but the settings and all other global info should be coming from the main shop Id
Bogi
@boboci9
Jul 15 2015 18:00

for the productImageGallery.coffee I was thinking about a change like this to allow the image upload because I can add a product to a different shop using the productDetail page but I can't add the image

uploadHandler = (event, template) ->
  productId = selectedProductId()
  variantId = selectedVariantId()
  shopId = selectedProduct().shopId ||  ReactionCore.getShopId() 
  userId = Meteor.userId()
  count = Media.find({'metadata.variantId': variantId }).count()
  FS.Utility.eachFile event, (file) ->
    fileObj = new FS.File(file)
    fileObj.metadata =
      ownerId: userId
      productId: productId
      variantId: variantId
      shopId: shopId
      priority: count
    Media.insert fileObj
    count++

where I added

shopId = selectedProduct().shopId ||  ReactionCore.getShopId()

to calculate the shopId based on the product's shopId that is being inserted? What do you say?

Aaron Judd
@aaronjudd
Jul 15 2015 18:26
yes this makes sense - and I get the challenge with ReactionCore.getShopId(), @queso (Josh Owens) is taking a look at refactoring this for marketplace.. I’d like to get his thoughts, on this as well. I’m still thinking that we need this as a central method though so that we can enforce use of ‘shop’
you could also use the userId and use their roles to determine the shopId
Bogi
@boboci9
Jul 15 2015 18:31
that would work for me because I am having only one shop per seller, but you said you wanted to have multiple shops per seller
but the selectedProduct already has the shopId set to it at this point when the image is uploaded to it
Aaron Judd
@aaronjudd
Jul 15 2015 18:32
ok, yeah - I guess that makes the most sense
Bogi
@boboci9
Jul 15 2015 18:33
ok, I will add this change to the Account createUser/Shop.defaultRoles change because I already prepared that for a PR
Aaron Judd
@aaronjudd
Jul 15 2015 18:33
is using getShopId() even needed then for insert, wouldn’t a product always have the shopId?
(although the fallback is good)
ok, just add this to the PR, and we’ll get Josh’s feedback on the PR as well.
Goutham Veeramachaneni
@gouthamve
Jul 15 2015 18:35
Hi sorry to disturb the ongoing discussion, I am trying to develop an integration with one of the Indian Payment Gateways, and I am getting this error:
Refused to display 'https://api.razorpay.com/v1/checkout?key_id=YOUR_KEY_ID' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN’.
Bogi
@boboci9
Jul 15 2015 18:35
I have been testing this for the last couple of hours and I didn't get a use case when the fallback was needed in my scenarios but it could be possible if someone were to do things differently, I only added that as a safety catch
Aaron Judd
@aaronjudd
Jul 15 2015 18:36
@Gouthamve you probably need to add a policy to your package: https://atmospherejs.com/meteor/browser-policy
I think the paypal one has a policy in server/policy.coffee (or something like that) if you need a guide
Goutham Veeramachaneni
@gouthamve
Jul 15 2015 18:38
Thanks!
Bogi
@boboci9
Jul 15 2015 18:40
I just had one last question using your Security package is there a way to get a collection's permissions, or find out somehow why am I getting Access.denied for a collection that I added the current user's permission?
Aaron Judd
@aaronjudd
Jul 15 2015 18:45
I think this is what might be tripping you up
Security.defineMethod 'ifFileBelongsToShop',
  fetch: []
  deny: (type, arg, userId, doc) ->
    return doc.metadata.shopId isnt ReactionCore.getShopId()
(or are you saying that getShopId IS the same and you are still getting denied?)
Bogi
@boboci9
Jul 15 2015 18:48
you could be right, I will check it without the ifFileBelongsToShop at least I will know why I get the access denied
I have different shopIds, and I overwrote the permission rule for my seller
great thanks, that was the cause of my issue
Bogi
@boboci9
Jul 15 2015 18:57
I my RC version I also added a shops parameter to the Media publication as well as we have for the products, when we have products published from several shops we will need their photos as well, I will add it to the PR and we can discusss it there if it needs changes
Aaron Judd
@aaronjudd
Jul 15 2015 18:57
great :thumbsup:
Goutham Veeramachaneni
@gouthamve
Jul 15 2015 20:55
Quick question: Will #402 be open-source?
Spencer Norman
@spencern
Jul 15 2015 20:58

@aaronjudd When extending a schema in a package like so:

ReactionCore.Schemas.rentalProduct = new SimpleSchema([
  ReactionCore.Schemas.ProductVariant
  {
    unavailableDates:
      type: [Date]
      defaultValue: {}
      optional: true
    unitHistory:
      type: [ReactionCore.Schemas.ProductHistory]
      optional: true
  }
])

Does this extend the original ReactionCore.Schemas.Product and allow me to insert these fields directly into products variants or do I need to attach it to Collections.Products?

Spencer Norman
@spencern
Jul 15 2015 21:31

Actually, nevermind on the reattaching bit.
looks like it’s unsafe to attach a schema to a collection more than once.

https://github.com/aldeed/meteor-collection2/blob/master/collection2.js#L37-39

Are there any packages that demonstrate successfully modifying a reaction-core schema / collection?
Aaron Judd
@aaronjudd
Jul 15 2015 23:12
that should work as intended...
that’s how we do it in the paypal package for example
Spencer Norman
@spencern
Jul 15 2015 23:12
Ok, perfect. I found an example (I think) in the shipping package as well
Aaron Judd
@aaronjudd
Jul 15 2015 23:20
@Gouthamve re: #402 - I think so, at least the API tools.. we’re still scoping the architecture right now, but probably rancher.com based. the actual “launch site” (reactioncommerce.com) will likely stay closed for now.