spaceship/lib/spaceship/tunes/availability.rb in fastlane-2.98.0 vs spaceship/lib/spaceship/tunes/availability.rb in fastlane-2.99.0

- old
+ new

@@ -22,12 +22,11 @@ attr_accessor :educational_discount # @return (Bool) b2b available for distribution attr_accessor :b2b_unavailable - # @return (Array of Spaceship::Tunes::B2bUser objects) A list of users set by user - if not - # then the b2b user list that is currently set + # @return (Array of Spaceship::Tunes::B2bUser objects) A list of users attr_accessor :b2b_users attr_mapping( 'theWorld' => :include_future_territories, 'preOrder.clearedForPreOrder.value' => :cleared_for_preorder, @@ -76,11 +75,11 @@ def territories @territories ||= raw_data['countries'].map { |info| Territory.new(info) } end def b2b_users - @b2b_users ||= raw_data['b2bUsers'].map { |user| B2bUser.new(user) } + @b2b_users || raw_data['b2bUsers'].map { |user| B2bUser.new(user) } end def b2b_app_enabled @b2b_app_enabled.nil? ? raw_data['b2bAppEnabled'] : @b2b_app_enabled end @@ -98,19 +97,36 @@ def enable_b2b_app! raise "Not possible to enable b2b on this app" if b2b_unavailable @b2b_app_enabled = true # need to set the educational discount to false @educational_discount = false - self + return self end # Adds users for b2b enabled apps def add_b2b_users(user_list = []) raise "Cannot add b2b users if b2b is not enabled" unless b2b_app_enabled - @b2b_users = user_list.map do |user| - B2bUser.from_username(user) - end - self + @b2b_users = user_list.map { |user| B2bUser.from_username(user) } + return self + end + + # Updates users for b2b enabled apps + def update_b2b_users(user_list = []) + raise "Cannot add b2b users if b2b is not enabled" unless b2b_app_enabled + + added_users = b2b_users.map(&:ds_username) + + # Returns if list is unchanged + return self if (added_users - user_list) == (user_list - added_users) + + users_to_add = user_list.reject { |user| added_users.include?(user) } + users_to_remove = added_users.reject { |user| user_list.include?(user) } + + @b2b_users = b2b_users.reject { |user| users_to_remove.include?(user.ds_username) } + @b2b_users.concat(users_to_add.map { |user| B2bUser.from_username(user) }) + @b2b_users.concat(users_to_remove.map { |user| B2bUser.from_username(user, is_add_type: false) }) + + return self end end end end