Skip to content

Commit

Permalink
Export responses per fiscal year
Browse files Browse the repository at this point in the history
* update delivery options to radio tile
* remove forms permissions invite form in favor of /admin/invite
  • Loading branch information
ryanwoldatwork authored Apr 19, 2023
1 parent 4645022 commit 7576376
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 62 deletions.
17 changes: 0 additions & 17 deletions app/controllers/admin/forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,6 @@ def export
render json: { form: @form, questions: }
end

def invite
invitee = invite_params[:refer_user]

if invitee.present? && invitee =~ URI::MailTo::EMAIL_REGEXP && (ENV['GITHUB_CLIENT_ID'].present? ? true : APPROVED_DOMAINS.any? { |word| invitee.end_with?(word) })
if User.exists?(email: invitee)
redirect_to permissions_admin_form_path(@form), alert: "User with email #{invitee} already exists"
else
UserMailer.invite(current_user, invitee).deliver_later
redirect_to permissions_admin_form_path(@form), notice: "Invite sent to #{invitee}"
end
elsif ENV['GITHUB_CLIENT_ID'].present?
redirect_to permissions_admin_form_path(@form), alert: 'Please enter a valid email address'
else
redirect_to permissions_admin_form_path(@form), alert: 'Please enter a valid .gov or .mil email address'
end
end

def publish
Event.log_event(Event.names[:form_published], 'Form', @form.uuid, "Form #{@form.name} published at #{DateTime.now}", current_user.id)

Expand Down
8 changes: 4 additions & 4 deletions app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def ensure_no_responses
end

DELIVERY_METHODS = [
['touchpoints-hosted-only', 'Hosted only on the Touchpoints site'],
['modal', 'Tab button & modal'],
['custom-button-modal', 'Custom button & modal'],
['inline', 'Embedded inline on your site'],
['touchpoints-hosted-only', 'Hosted on Touchpoints'],
['modal', 'Blue button & modal on your website'],
['custom-button-modal', 'Custom button & modal on your website'],
['inline', 'Embedded inline on your website'],
].freeze

def suppress_submit_button
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/forms/delivery.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<br>
<legend class="usa-sr-only">Delivery methods</legend>
<% Form::DELIVERY_METHODS.each_with_index do |delivery_method, index| %>
<div class="usa-checkbox">
<%= f.radio_button :delivery_method, delivery_method[0], class: "usa-radio__input" %>
<div class="usa-radio">
<%= f.radio_button :delivery_method, delivery_method[0], class: "usa-radio__input usa-radio__input--tile" %>
<%= f.label delivery_method[1], class: "usa-radio__label", for: "form_delivery_method_#{delivery_method[0]}" %>
</div>
<% end %>
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin/submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
</div>
<br>
<%= link_to "Export All Responses to CSV", export_submissions_admin_form_url(form, start_date: "2019-10-01", format: "json"), class: "usa-button export-btn" %>
<br>
<p>
<%= link_to "Export FY2020", export_submissions_admin_form_url(form, start_date: "2019-10-01", end_date: "2020-09-30", format: "json"), class: "usa-button usa-button--outline export-btn" %>
<%= link_to "Export FY2021", export_submissions_admin_form_url(form, start_date: "2020-10-01", end_date: "2021-09-30", format: "json"), class: "usa-button usa-button--outline export-btn" %>
<%= link_to "Export FY2022", export_submissions_admin_form_url(form, start_date: "2021-10-01", end_date: "2022-09-30", format: "json"), class: "usa-button usa-button--outline export-btn" %>
<%= link_to "Export FY2023", export_submissions_admin_form_url(form, start_date: "2022-10-01", end_date: "2023-09-30", format: "json"), class: "usa-button usa-button--outline export-btn" %>
</p>
<% else %>
<div class="usa-alert usa-alert--info">
<div class="usa-alert__body">
Expand Down
43 changes: 13 additions & 30 deletions app/views/components/_roles_and_permissions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -129,37 +129,20 @@
</div>

<div class="well">
<%= form_with(model: current_user, url: "invite", local: true) do |f| %>
<div class="grid-row grid-gap-md">
<div class="tablet:grid-col-12">
<p>
Don't see a user in the dropdown?
</p>
<div class="grid-row grid-gap-md">
<div class="tablet:grid-col-12 usa-prose">
<p class="text-bold">
Don't see a user in the User dropdown?
</p>

<div class="field">
<%= label_tag :refer_user, "Invite a colleague to Touchpoints", class: "usa-label" %>
<%= f.email_field :refer_user, class: "usa-input", placeholder: "[email protected]" %>
</div>
</div>
</div>
<div class="field">
<br>
<%= f.submit "Invite User", class: "usa-button", id: "invite-button", disabled: true %>
<br>
<%= link_to "Invite a User to Touchpoints", admin_invite_path, class: "usa-button usa-button--outline full-width" %>

<p>
After the user signs into Touchpoints, they will be available to select in the user dropdown.
</p>
</div>
<% end %>
</div>
</div>
</div>
</div>

<script>
$(function(){
$("#user_refer_user").on("keyup", function(event) {
if(event.target.value != '' && event.target.value.length > 5) {
$("#invite-button").attr('disabled', false);
} else {
$("#invite-button").attr('disabled', true);
}
});
});
</script>
</div>
</div>
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@
get 'export_submissions', to: 'forms#export_submissions', as: :export_submissions
get 'export_a11_header', to: 'forms#export_a11_header', as: :export_a11_header
get 'export_a11_submissions', to: 'forms#export_a11_submissions', as: :export_a11_submissions
patch 'invite', to: 'forms#invite', as: :invite
get 'js', to: 'forms#js', as: :js
get 'permissions', to: 'forms#permissions', as: :permissions
get 'compliance', to: 'forms#compliance', as: :compliance
Expand Down
16 changes: 8 additions & 8 deletions spec/features/admin/forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
find('label', text: 'Display square (80px wide by 80px tall) logo?').click
click_on 'Update logo'
click_on 'Delivery'
find('label', text: 'Hosted only on the touchpoints site').click
find('label', text: 'Hosted on touchpoints').click
click_on 'Update Form'
expect(page).to have_content('Form was successfully updated.')
visit example_admin_form_path(Form.last)
Expand All @@ -166,7 +166,7 @@
find('label', text: 'Display square (80px wide by 80px tall) logo?').click
click_on 'Update logo'
click_on 'Delivery'
find('label', text: 'Embedded inline on your site').click
find('label', text: 'Embedded inline on your website').click
fill_in('form_element_selector', with: 'test_selector')
click_on 'Update Form'
expect(page).to have_content('Form was successfully updated.')
Expand Down Expand Up @@ -1551,20 +1551,20 @@

context 'with a valid email' do
before do
visit permissions_admin_form_path(form)
visit admin_invite_path(form)
end

it 'sends an invite to the designated user' do
fill_in('user[refer_user]', with: '[email protected]')
click_on 'Invite User'
expect(page).to have_content('Invite sent to [email protected]')
expect(page.current_path).to eq(permissions_admin_form_path(form))
expect(page.current_path).to eq(admin_invite_path)
end
end

context 'with an invalid email' do
before do
visit permissions_admin_form_path(form)
visit admin_invite_path
end

it 'initially disabled button shows an alert when at least 6 characters of an invalid email address is provided' do
Expand All @@ -1577,14 +1577,14 @@
expect(find("#invite-button").disabled?).to be(false)
click_on 'Invite User'
expect(page).to have_content('Please enter a valid .gov or .mil email address')
expect(page.current_path).to eq(permissions_admin_form_path(form))
expect(page.current_path).to eq(admin_invite_path)
end

it 'shows a gov-specific user alert when the email address is not a valid email' do
fill_in('user[refer_user]', with: '[email protected]')
click_on 'Invite User'
expect(page).to have_content('Please enter a valid .gov or .mil email address')
expect(page.current_path).to eq(permissions_admin_form_path(form))
expect(page.current_path).to eq(admin_invite_path)
end

context 'when using GitHub for oAuth' do
Expand All @@ -1609,7 +1609,7 @@
fill_in('user[refer_user]', with: user.email)
click_on 'Invite User'
expect(page).to have_content("User with email #{user.email} already exists")
expect(page.current_path).to eq(permissions_admin_form_path(form))
expect(page.current_path).to eq(admin_invite_path)
end
end
end
Expand Down

0 comments on commit 7576376

Please sign in to comment.