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
Adding support for b2b vpp #12420
Adding support for b2b vpp #12420
Conversation
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 looks good! Just a few small comments 🙃
# @return (Bool) b2b available for distribution | ||
attr_accessor :b2b_unavailable | ||
|
||
attr_accessor :b2b_users |
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.
Can you add a comment above this one?
# Sets the b2b flag. If you call Save on app_details without adding any b2b users | ||
# it will result in an error. | ||
def enable_b2b_app! | ||
print("b2b : " + b2b_unavailable.to_s) |
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.
Can you 💣 this print
?
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.
oops! :/
b2b_user_array.push(B2bUser.from_username(user)) | ||
end | ||
@b2b_users = b2b_user_array | ||
return self |
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 method looks like its "setting" users instead of "adding" users. Should this method be renamed? Also, this method could be cleaned up to look like the follow if it is actually just "setting"...
def add_b2b_users(user_list = [])
raise "Cannot add b2b users if b2b is not enabled" unless b2b_app_enabled
@b2b_users = map do |user|
B2bUser.from_username(user)
end
return self
end
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.
@joshdholtz its peculiar but when i examined the request body, only the ones that were being added or removed were included in the request body. so this is indeed "adding" instead of "setting". But your comment about "cleanup" stands. I will make the change.
@joshdholtz see if this looks good! I m doing some more testing. I ll leave you a comment when i m done. |
Oops I think I found a bug! Do not merge. I m working on a fix. |
Fixed. 😥 |
aa51579
to
6a9f644
Compare
@heartofagoof I will pull this down and test it later today / over this weekend! Would be able to provide me with some code examples I can play with for all the functionalities that you added? 😊 I can replace with all of my app ids and stuff but nice to have an example to base it off of 💪 |
@joshdholtz Something like this should work. I tried it out.
And then try to just add b2b users when the b2b is enabled. That should work too. What should fail is this :
|
Also @joshdholtz , that email id will have to have been enrolled in vpp program - as far as i know. |
how's it looking @joshdholtz ? |
) | ||
|
||
# Create a new object based on a set of territories. | ||
# @param territories (Array of String or Spaceship::Tunes::Territory objects): A list of the territories | ||
# @param params (Hash): Optional parameters (include_future_territories (Bool, default: true) Are future territories included?) | ||
# This method has serious implications on vpp + educational discount but i don't want to break | ||
# existing support. please be very careful when using this and provide appropriate params. | ||
# In future, we should create availability from territories as an instance method not as a class method. |
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.
Can we remove this comment block after the @param
and move it to a new line between the Create
and the first @param
saying something like...
Create a new object based on a set of territories.
This will override any values already set for cleared_for_preorder, app_available_date, b2b_unavailable, b2b_app_enabled, and educational_discount
# @param territories (Array of String or Spaceship::Tunes::Territory objects): A list of the territories
# @param params (Hash): Optional parameters (include_future_territories (Bool, default: true) Are future territories included?)
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.
Done!
end | ||
|
||
# just adds users to the availability, You will still have to call update_availabilty | ||
def add_b2b_users(user_list = []) |
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.
Does this actually "set" the users and not "add" users? 🤔
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.
If this does set/override the @b2b_users
, could we maybe combine enable_b2b_app!
with this one and just pass the user list into the enable_b2_app!
method?
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.
It does not set or override. It may look like this but the way the requests are ( if you observe the object ) only the email ids either being added or removed are sent over.
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.
@heartofagoof Interesting 🤔 Good to know! So this could also remove the user if the user was already set?
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.
No. For that you'd have to set removed = true. Which we are not setting right now. I didn't want to implement anything destructive. :)
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 can of course change the implementation to something like this if it helps :
update_b2b_users(users_to_add: [], users_to_remove: [])
and update the signature to:
from_username(email_id: [], add_or_remove:)
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 way we provide the ability to add and remove b2b teams.
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.
Just a few nitpicks on the comments and then I think we will be good 😊
def cleared_for_preorder | ||
super || false | ||
end | ||
|
||
# Sets the b2b flag. If you call Save on app_details without adding any b2b users |
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.
Can we change this comment to...
# Sets `b2b_app_enabled` to true and `educational_discount` to false
# Requires users to be added with `add_b2b_users` otherwise `update_availability` will error
self | ||
end | ||
|
||
# just adds users to the availability, You will still have to call update_availabilty |
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.
And...
# Adds users for b2b enabled apps
@snatchev Can you also take a look at this when you get a chance? 😊 I've reviewed and tested it and it looks 💯 but just another set of 👀 would be 💪 |
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.
Looks good! 👍 But waiting for one more set of 👀
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 think we can take advantage of the attr_mapping to get the data back out in the right format when we make the request. This is more of a nice-to-have if it works correctly (which I haven't tested).
Otherwise, it looks good to me. Nice specs :)
data["preOrder"]["clearedForPreOrder"] = { "value" => cleared_for_preorder, "isEditable" => true, "isRequired" => true, "errorKeys" => nil } | ||
data["preOrder"]["appAvailableDate"] = { "value" => app_available_date, "isEditable" => true, "isRequired" => true, "errorKeys" => nil } | ||
data["b2bUsers"] = availability.b2b_app_enabled ? availability.b2b_users.map { |user| { "value" => { "add" => user.add, "delete" => user.delete, "dsUsername" => user.ds_username } } } : [] |
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 believe you can convert the b2b_users
back into data by doing: b2b_users.raw_data.to_h
. Ideally, the model and the attr_mapping
should be the only place that has to know how to convert to and from the JSON data.
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.
@heartofagoof Do you mind trying this out? ^ 😊
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.
Okay digging into the metaprogramming ya'll have to make sense of it. I tried to use the mapping but it was not working quite as expected - it might be the limitation of the model.
I am more than happy to give it a proper go, however. If it is limited in scope, I can make the changes here but if it is extensive, hopefully I can make it in another PR.
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.
Hey @heartofagoof, if it doesn't work as expected out of the box, I wouldn't bother too much trying to hack it to work
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.
Yeah, no worries at all! We will merge what you got here 😊
Hey @heartofagoof 👋 Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉 Please let us know if this change requires an immediate release by adding a comment here 👍 |
Congratulations! 🎉 This was released as part of fastlane 2.96.0 🚀 |
Checklist
bundle exec rspec
from the root directory to see all new and existing tests passbundle exec rubocop -a
to ensure the code style is validMotivation and Context
I wished to provide the support to enable vpp and add the vpp email addresses. I have deliberately not provided a way to remove them or disable vpp because i do not want to introduce changes that may mess up the system.
I have tested adding b2b users when existing users present. also enabled b2b distribution when it was disabled. I have also ensured it by making sure existing spec tests are working - which is a good test in this case since the specs for availability were quite extensive.
Description
Created a class
b2b_user
for parsing the user detailsProvided parsing for
b2bAppEnabled
,b2bAppFlagDisabled
andb2bUsers
Updated
TunesClient
,AvailabilitySpec
,TunesStubbing
for this change and added a couple of fixtures for tests.