Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/controllers/invite_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class InviteController < ApplicationController
before_action :set_app_details
before_action :check_disabled_text
before_action :check_imprint_url
before_action :group_drop_down

skip_before_filter :verify_authenticity_token

Expand Down Expand Up @@ -89,7 +90,15 @@ def submit

private
def create_and_add_tester(email, first_name, last_name)
add_tester_response = boarding_service.add_tester(email, first_name, last_name)
custom_group = params["groups"]["selected"]
unless @groups_for_dropdown.include?(custom_group)
# this is important, as it would otherwise allow users to add themselves
# to groups that are not white-listed by the developer using the
# `ITC_GROUPS_DROPDOWN_LIST` env variable
Rails.logger.info("Tried to access group #{custom_group}, but not in the list of available groups #{@groups_for_dropdown}")
custom_group = nil
end
add_tester_response = boarding_service.add_tester(email, first_name, last_name, custom_group)
@message = add_tester_response.message
@type = add_tester_response.type
end
Expand Down Expand Up @@ -124,4 +133,8 @@ def check_imprint_url
@imprint_url = boarding_service.imprint_url
end
end

def group_drop_down
@groups_for_dropdown = ENV["ITC_GROUPS_DROPDOWN_LIST"].to_s.length > 0 ? ENV["ITC_GROUPS_DROPDOWN_LIST"].split(";") : []
end
end
7 changes: 4 additions & 3 deletions app/services/boarding_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def initialize(app_id: ENV["ITC_APP_ID"],
ensure_values
end

def add_tester(email, first_name, last_name)
def add_tester(email, first_name, last_name, custom_group = nil)
add_tester_response = AddTesterResponse.new
add_tester_response.type = "danger"
custom_group ||= tester_group_names

tester = find_app_tester(email: email, app: app)
if tester
Expand All @@ -60,12 +61,12 @@ def add_tester(email, first_name, last_name)
end

begin
groups = Spaceship::TestFlight::Group.add_tester_to_groups!(tester: tester, app: app, groups: tester_group_names)
groups = Spaceship::TestFlight::Group.add_tester_to_groups!(tester: tester, app: app, groups: custom_group)
if tester.kind_of?(Spaceship::Tunes::Tester::Internal)
Rails.logger.info "Successfully added tester to app #{app.name}"
else
# 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 tester_group_names
if custom_group
group_names = groups.map(&:name).join(", ")
Rails.logger.info "Successfully added tester to group(s): #{group_names} in app: #{app.name}"
else
Expand Down
10 changes: 10 additions & 0 deletions app/views/invite/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<% end %>
<% end %>

<% if @groups_for_dropdown && @groups_for_dropdown.count > 1 %>
<%= label_tag(:group, t(:group)) %>
<%= select("groups", "selected", @groups_for_dropdown) %>
<% end %>

<br />
<%= submit_tag t(:get_beta_access), class: 'btn btn-lg btn-primary btn-block', id: "submit" %>
<% end %>
Expand Down Expand Up @@ -87,4 +92,9 @@
right: 25px;
}
}
select {
width: 100%;
margin-bottom: 20px;
height: 35px;
}
</style>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ en:
message_error: "Something went wrong, please contact the application owner"
loading: "Loading"
imprint: "Imprint"
group: "Group"