Skip to content

Commit

Permalink
Support 10 whitelist urls
Browse files Browse the repository at this point in the history
* update conditional options on Service form
  • Loading branch information
ryanwoldatwork authored Jun 8, 2023
1 parent 9cbbebc commit 13bfb3b
Show file tree
Hide file tree
Showing 13 changed files with 412 additions and 243 deletions.
9 changes: 9 additions & 0 deletions app/controllers/admin/forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ def form_params
:display_header_logo,
:display_header_square_logo,
:whitelist_url,
:whitelist_url_1,
:whitelist_url_2,
:whitelist_url_3,
:whitelist_url_4,
:whitelist_url_5,
:whitelist_url_6,
:whitelist_url_7,
:whitelist_url_8,
:whitelist_url_9,
:whitelist_test_url,
:disclaimer_text,
:success_text,
Expand Down
13 changes: 11 additions & 2 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ def create
head :ok and return
end

# Prevent the Submission if this is a published Form and if:
# Prevent the Submission if this is a published Form and if the form:
if @form &&
request.referer &&
# is not from the Form's whitelist URL
# is not from the Form's whitelist URLs
(@form.whitelist_url.present? ? !request.referer.start_with?(@form.whitelist_url) : true) &&
(@form.whitelist_url_1.present? ? !request.referer.start_with?(@form.whitelist_url_1) : true) &&
(@form.whitelist_url_2.present? ? !request.referer.start_with?(@form.whitelist_url_2) : true) &&
(@form.whitelist_url_3.present? ? !request.referer.start_with?(@form.whitelist_url_3) : true) &&
(@form.whitelist_url_4.present? ? !request.referer.start_with?(@form.whitelist_url_4) : true) &&
(@form.whitelist_url_5.present? ? !request.referer.start_with?(@form.whitelist_url_5) : true) &&
(@form.whitelist_url_6.present? ? !request.referer.start_with?(@form.whitelist_url_6) : true) &&
(@form.whitelist_url_7.present? ? !request.referer.start_with?(@form.whitelist_url_7) : true) &&
(@form.whitelist_url_8.present? ? !request.referer.start_with?(@form.whitelist_url_8) : true) &&
(@form.whitelist_url_9.present? ? !request.referer.start_with?(@form.whitelist_url_9) : true) &&
# is not from the Form's test whitelist URL
(@form.whitelist_test_url.present? ? !request.referer.start_with?(@form.whitelist_test_url) : true) &&
# is not from the Touchpoints app
Expand Down
9 changes: 9 additions & 0 deletions app/serializers/form_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class FormSerializer < ActiveModel::Serializer
:created_at,
:updated_at,
:whitelist_url,
:whitelist_url_1,
:whitelist_url_2,
:whitelist_url_3,
:whitelist_url_4,
:whitelist_url_5,
:whitelist_url_6,
:whitelist_url_7,
:whitelist_url_8,
:whitelist_url_9,
:whitelist_test_url,
:display_header_logo,
:success_text_heading,
Expand Down
9 changes: 9 additions & 0 deletions app/serializers/full_form_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def links
:created_at,
:updated_at,
:whitelist_url,
:whitelist_url_1,
:whitelist_url_2,
:whitelist_url_3,
:whitelist_url_4,
:whitelist_url_5,
:whitelist_url_6,
:whitelist_url_7,
:whitelist_url_8,
:whitelist_url_9,
:whitelist_test_url,
:display_header_logo,
:success_text_heading,
Expand Down
14 changes: 11 additions & 3 deletions app/views/admin/services/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<div class="field">
<%= form.label :bureau_id, "Subcomponent/Bureau", class: "usa-label" %>
<%= form.select :bureau_id, options_for_select(organization_dropdown_options, service.bureau_id), { prompt: "Which Bureau?" }, { class: "usa-select" } %>
<%= form.select :bureau_id, options_for_select(organization_dropdown_options, service.bureau_id), { prompt: "Which Bureau?", include_blank: true }, { class: "usa-select" } %>
</div>

<div class="field">
Expand Down Expand Up @@ -379,13 +379,17 @@

$("#service_digital_service_yes").on('click', function() {
$("#service_designated_for_improvement_a11_280").attr('required', true);
$("#resources_needed_to_provide_digital_service_option").show();
$("#service_resources_needed_to_provide_digital_service").show();
})
$("#service_digital_service_no").on('click', function() {
$("#service_designated_for_improvement_a11_280").attr('required', false);
$("#resources_needed_to_provide_digital_service_option").hide();
$("#service_resources_needed_to_provide_digital_service").hide();
})

$("#service_multi_agency_service_yes").on('click', function() {
$("#service_multi_agency_explanation").attr('required', true);
$("#multi_agency_explanation_option").show();
})
$("#service_multi_agency_service_yes").on('click', function() {
$("#service_multi_agency_explanation").attr('required', true);
$("#multi_agency_explanation_option").show();
Expand Down Expand Up @@ -445,6 +449,10 @@
$("#service_multi_agency_explanation").attr('required', true);
$("#multi_agency_explanation_option").show();
}
if ($("#service_multi_agency_service_no:checked")) {
$("#service_multi_agency_explanation").attr('required', false);
$("#multi_agency_explanation_option").hide();
}

if ($("#service_fully_digital_service_yes:checked")) {
$("#barriers_to_fully_digital_service_option").show();
Expand Down
45 changes: 45 additions & 0 deletions app/views/components/_whitelist_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,51 @@
<%= f.url_field :whitelist_url, class: "usa-input", placeholder: "https://example.gov" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_1, class: "usa-input", placeholder: "URL 1" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_2, class: "usa-input", placeholder: "URL 2" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_3, class: "usa-input", placeholder: "URL 3" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_4, class: "usa-input", placeholder: "URL 4" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_5, class: "usa-input", placeholder: "URL 5" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_6, class: "usa-input", placeholder: "URL 6" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_7, class: "usa-input", placeholder: "URL 7" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_8, class: "usa-input", placeholder: "URL 8" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.url_field :whitelist_url_9, class: "usa-input", placeholder: "URL 9" %>
</div>
</div>
<div class="grid-col-12">
<div class="field">
<%= f.label :whitelist_test_url, "URL for staging or testing site where survey will display", class: "usa-label" %>
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20230608193911_add_form_whitelist_urls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AddFormWhitelistUrls < ActiveRecord::Migration[7.0]
def change
add_column :forms, :whitelist_url_1, :string
add_column :forms, :whitelist_url_2, :string
add_column :forms, :whitelist_url_3, :string
add_column :forms, :whitelist_url_4, :string
add_column :forms, :whitelist_url_5, :string
add_column :forms, :whitelist_url_6, :string
add_column :forms, :whitelist_url_7, :string
add_column :forms, :whitelist_url_8, :string
add_column :forms, :whitelist_url_9, :string
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_05_31_225454) do
ActiveRecord::Schema[7.0].define(version: 2023_06_08_193911) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -258,6 +258,15 @@
t.integer "questions_count", default: 0
t.boolean "verify_csrf", default: true
t.string "submissions_tags", array: true
t.string "whitelist_url_1"
t.string "whitelist_url_2"
t.string "whitelist_url_3"
t.string "whitelist_url_4"
t.string "whitelist_url_5"
t.string "whitelist_url_6"
t.string "whitelist_url_7"
t.string "whitelist_url_8"
t.string "whitelist_url_9"
t.index ["legacy_touchpoint_id"], name: "index_forms_on_legacy_touchpoint_id"
t.index ["legacy_touchpoint_uuid"], name: "index_forms_on_legacy_touchpoint_uuid"
t.index ["organization_id"], name: "index_forms_on_organization_id"
Expand Down
18 changes: 18 additions & 0 deletions public/api/v0/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ components:
type: string
whitelist_url:
type: string
whitelist_url_1:
type: string
whitelist_url_2:
type: string
whitelist_url_3:
type: string
whitelist_url_4:
type: string
whitelist_url_5:
type: string
whitelist_url_6:
type: string
whitelist_url_7:
type: string
whitelist_url_8:
type: string
whitelist_url_9:
type: string
whitelist_test_url:
type: string
display_header_logo:
Expand Down
Loading

0 comments on commit 13bfb3b

Please sign in to comment.