pilot/lib/pilot/tester_manager.rb in fastlane-2.29.0 vs pilot/lib/pilot/tester_manager.rb in fastlane-2.29.1
- old
+ new
@@ -4,23 +4,32 @@
module Pilot
class TesterManager < Manager
def add_tester(options)
start(options)
-
app = find_app(app_filter: config[:apple_id] || config[:app_identifier])
UI.user_error!("You must provide either a Apple ID for the app (with the `:apple_id` option) or app identifier (with the `:app_identifier` option)") unless app
- tester = find_or_create_tester(email: config[:email], first_name: config[:first_name], last_name: config[:last_name])
-
+ tester = find_app_tester(email: config[:email], app: app)
+ tester ||= create_tester(
+ email: config[:email],
+ first_name: config[:first_name],
+ last_name: config[:last_name],
+ app: app
+ )
begin
groups = Spaceship::TestFlight::Group.add_tester_to_groups!(tester: tester, app: app, groups: config[:groups])
if tester.kind_of?(Spaceship::Tunes::Tester::Internal)
UI.success("Successfully added tester to app #{app.name}")
else
- group_names = groups.map(&:name).join(", ")
- UI.success("Successfully added tester to app #{app.name} in group(s) #{group_names}")
+ # tester was added to the group(s) in the above add_tester_to_groups() call, now we need to let the user know which group(s)
+ if config[:groups]
+ group_names = groups.map(&:name).join(", ")
+ UI.success("Successfully added tester to group(s): #{group_names} in app: #{app.name}")
+ else
+ UI.success("Successfully added tester to the default tester group in app: #{app.name}")
+ end
end
rescue => ex
UI.error("Could not add #{tester.email} to app: #{app.name}")
raise ex
end
@@ -89,24 +98,54 @@
return app
end
nil
end
- def find_or_create_tester(email: nil, first_name: nil, last_name: nil)
- tester = Spaceship::Tunes::Tester::Internal.find(config[:email])
- tester ||= Spaceship::Tunes::Tester::External.find(config[:email])
+ def find_app_tester(email: nil, app: nil)
+ current_user = Spaceship::Members.find(Spaceship::Tunes.client.user)
+ if current_user.admin?
+ tester = Spaceship::Tunes::Tester::Internal.find(email)
+ tester ||= Spaceship::Tunes::Tester::External.find(email)
+ elsif current_user.app_manager?
+ unless app
+ UI.user_error!("Account #{current_user.email_address} is only an 'App Manager' and therefore you must also define what app this tester (#{email}) should be added to")
+ end
+ tester = Spaceship::Tunes::Tester::Internal.find_by_app(app.apple_id, email)
+ tester ||= Spaceship::Tunes::Tester::External.find_by_app(app.apple_id, email)
+ else
+ UI.user_error!("Account #{current_user.email} doesn't have a role that is allowed to administer app testers, current roles: #{current_user.roles}")
+ tester = nil
+ end
if tester
- UI.success("Existing tester #{tester.email}")
+ UI.success("Found existing tester #{email}")
+ end
+
+ return tester
+ end
+
+ def create_tester(email: nil, first_name: nil, last_name: nil, app: nil)
+ current_user = Spaceship::Members.find(Spaceship::Tunes.client.user)
+ if current_user.admin?
+ tester = Spaceship::Tunes::Tester::External.create!(email: email,
+ first_name: first_name,
+ last_name: last_name)
+ UI.success("Successfully added tester: #{email} to your account")
+ elsif current_user.app_manager?
+
+ Spaceship::TestFlight::Tester.create_app_level_tester(app_id: app.apple_id,
+ first_name: first_name,
+ last_name: last_name,
+ email: email)
+ tester = Spaceship::Tunes::Tester::External.find_by_app(app.apple_id, email)
+ UI.success("Successfully added tester: #{email} to app: #{app.name}")
else
- tester = Spaceship::Tunes::Tester::External.create!(email: config[:email],
- first_name: config[:first_name],
- last_name: config[:last_name])
- UI.success("Successfully added tester: #{tester.email} to your account")
+ UI.user_error!("Current account doesn't have permission to create a tester")
end
+
return tester
rescue => ex
- UI.error("Could not create tester #{config[:email]}")
+ UI.error("Could not create tester #{email}")
raise ex
end
def list_testers_by_app(app_filter)
app = Spaceship::Application.find(app_filter)