Skip to content

Commit

Permalink
Rebase + run the rules again
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Liebowitz committed May 24, 2017
1 parent b821cfa commit e653c3d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 79 deletions.
4 changes: 2 additions & 2 deletions app/controllers/invite_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def submit
render :index
return
end

email = params[:email]
first_name = params[:first_name]
last_name = params[:last_name]
Expand All @@ -55,7 +55,7 @@ def submit
return
end
end

if email.length == 0
render :index
return
Expand Down
152 changes: 75 additions & 77 deletions app/services/boarding_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class AddTesterResponse
attr_accessor :message
attr_accessor :type
end
end

class BoardingService
include AbstractController::Translation
Expand All @@ -18,9 +18,9 @@ class BoardingService
attr_accessor :itc_closed_text

def initialize(app_id: ENV["ITC_APP_ID"],
user: ENV["ITC_USER"] || ENV["FASTLANE_USER"],
password: ENV["ITC_PASSWORD"] || ENV["FASTLANE_PASSWORD"],
tester_group_names: ENV["ITC_APP_TESTER_GROUPS"])
user: ENV["ITC_USER"] || ENV["FASTLANE_USER"],
password: ENV["ITC_PASSWORD"] || ENV["FASTLANE_PASSWORD"],
tester_group_names: ENV["ITC_APP_TESTER_GROUPS"])
@app_id = app_id
@user = user
@password = password
Expand Down Expand Up @@ -70,7 +70,6 @@ def add_tester(email, first_name, last_name)
Rails.logger.info "Successfully added tester to the default tester group in app: #{app.name}"
end
end

rescue => ex
Rails.logger.error "Could not add #{tester.email} to app: #{app.name}"
raise ex
Expand All @@ -81,87 +80,86 @@ def add_tester(email, first_name, last_name)

private

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)
Rails.logger.info "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)
Rails.logger.info "Successfully added tester: #{email} to app: #{app.name}"
else
raise "Current account doesn't have permission to create a tester"
end

return tester
rescue => ex
Rails.logger.error "Could not create tester #{email}"
raise ex
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)
Rails.logger.info "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)
Rails.logger.info "Successfully added tester: #{email} to app: #{app.name}"
else
raise "Current account doesn't have permission to create a tester"
end

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
raise "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
raise "Account #{current_user.email} doesn't have a role that is allowed to administer app testers, current roles: #{current_user.roles}"
tester = nil
end
return tester
rescue => ex
Rails.logger.error "Could not create tester #{email}"
raise ex
end

if tester
Rails.logger.info "Found existing tester #{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
raise "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
raise "Account #{current_user.email} doesn't have a role that is allowed to administer app testers, current roles: #{current_user.roles}"
end

return tester
if tester
Rails.logger.info "Found existing tester #{email}"
end
def ensure_values
error_message = []

error_message << "Environment variable `ITC_APP_ID` required" if @app_id.to_s.length == 0
error_message << "Environment variable `ITC_USER` or `FASTLANE_USER` required" if @user.to_s.length == 0
error_message << "Environment variable `ITC_PASSWORD` or `FASTLANE_PASSWORD`" if @password.to_s.length == 0
raise error_message.join("\n") if error_message.length > 0

spaceship = Spaceship::Tunes.login(@user, @password)
spaceship.select_team

@app ||= Spaceship::Tunes::Application.find(@app_id)
raise "Could not find app with ID #{app_id}" if @app.nil?

if tester_group_names
test_flight_groups = Spaceship::TestFlight::Group.filter_groups(app_id: @app.apple_id)
test_flight_group_names = test_flight_groups.map { |group| group.name }.to_set
tester_group_names.select do |group_name|
next if test_flight_group_names.include?(group_name)
error_message << "TestFlight missing group `#{group_name}`, You need to first create this group in iTunes Connect."
end
end

raise error_message.join("\n") if error_message.length > 0
return tester
end

def ensure_values
error_message = []

error_message << "Environment variable `ITC_APP_ID` required" if @app_id.to_s.length == 0
error_message << "Environment variable `ITC_USER` or `FASTLANE_USER` required" if @user.to_s.length == 0
error_message << "Environment variable `ITC_PASSWORD` or `FASTLANE_PASSWORD`" if @password.to_s.length == 0
raise error_message.join("\n") if error_message.length > 0

spaceship = Spaceship::Tunes.login(@user, @password)
spaceship.select_team

@app ||= Spaceship::Tunes::Application.find(@app_id)
raise "Could not find app with ID #{app_id}" if @app.nil?

if tester_group_names
test_flight_groups = Spaceship::TestFlight::Group.filter_groups(app_id: @app.apple_id)
test_flight_group_names = test_flight_groups.map(&:name).to_set
tester_group_names.select do |group_name|
next if test_flight_group_names.include?(group_name)
error_message << "TestFlight missing group `#{group_name}`, You need to first create this group in iTunes Connect."
end
end

def testing_is_live?
app.build_trains.each do |version, train|
if train.external_testing_enabled
train.builds.each do |build|
return true if build.external_testing_enabled
end
end
raise error_message.join("\n") if error_message.length > 0
end

def testing_is_live?
app.build_trains.each do |version, train|
next unless train.external_testing_enabled
train.builds.each do |build|
return true if build.external_testing_enabled
end
return false
end
return false
end
end

0 comments on commit e653c3d

Please sign in to comment.