Skip to content
Merged
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
31 changes: 29 additions & 2 deletions app/components/button_component.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# frozen_string_literal: true

class ButtonComponent < BaseComponent
attr_reader :action, :icon, :big, :wide, :full_width, :outline, :unstyled, :danger, :tag_options
attr_reader :url,
:method,
:icon,
:big,
:wide,
:full_width,
:outline,
:unstyled,
:danger,
:tag_options

def initialize(
action: ->(**tag_options, &block) { button_tag(**tag_options, &block) },
action: nil,
url: nil,
method: nil,
icon: nil,
big: false,
wide: false,
Expand All @@ -15,6 +26,8 @@ def initialize(
**tag_options
)
@action = action
@url = url
@method = method
@icon = icon
@big = big
@wide = wide
Expand Down Expand Up @@ -53,4 +66,18 @@ def content
original_content
end
end

def action
@action ||= begin
if url
if method && method != :get
->(**tag_options, &block) { button_to(url, method:, **tag_options, &block) }
else
->(**tag_options, &block) { link_to(url, **tag_options, &block) }
end
else
->(**tag_options, &block) { button_tag(**tag_options, &block) }
end
end
end
end
4 changes: 1 addition & 3 deletions app/views/accounts/_pii.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<div class="usa-alert__text">
<%= t('account.re_verify.banner') %>
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(account_reauthentication_path, **tag_options, &block)
end,
Comment on lines -8 to -10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like on this branch, after these changes, there are 26 action: usages left, would we consider removing all of them in a follow-up PR?

identity-idp:aduth-backup-code-s-form-link> git grep -A 3 ButtonComponent.new -- app | grep action: | wc -l
      26

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can! I actually manually un-edited some additional files since they weren't strictly required to update, so as to keep review simpler. But definitely want to get everything migrated over.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up at #10468

url: account_reauthentication_path,
method: :post,
class: 'usa-button usa-button--unstyled',
).with_content(t('account.re_verify.footer')) %>
Expand Down
20 changes: 5 additions & 15 deletions app/views/idv/cancellations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
<p><%= t('idv.cancel.description.hybrid') %></p>

<% c.with_action_button(
action: ->(**tag_options, &block) do
button_to(idv_cancel_path(step: params[:step], location: 'cancel'), **tag_options, &block)
end,
url: idv_cancel_path(step: params[:step], location: 'cancel'),
method: :delete,
).with_content(t('forms.buttons.cancel')) %>
<% c.with_action_button(
action: ->(**tag_options, &block) do
button_to(idv_cancel_path(step: params[:step]), **tag_options, &block)
end,
url: idv_cancel_path(step: params[:step]),
method: :put,
outline: true,
).with_content(t('links.go_back')) %>
Expand All @@ -28,9 +24,7 @@

<div class="margin-top-4">
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(idv_session_path(step: params[:step]), **tag_options, &block)
end,
url: idv_session_path(step: params[:step]),
method: :delete,
big: true,
wide: true,
Expand All @@ -39,9 +33,7 @@
%>
<div class="margin-top-2">
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(idv_cancel_path(step: params[:step]), **tag_options, &block)
end,
url: idv_cancel_path(step: params[:step]),
method: :put,
big: true,
wide: true,
Expand All @@ -61,9 +53,7 @@

<div class="margin-top-4">
<%= render SpinnerButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(idv_cancel_path(step: params[:step], location: 'cancel'), **tag_options, &block)
end,
url: idv_cancel_path(step: params[:step], location: 'cancel'),
method: :delete,
big: true,
wide: true,
Expand Down
4 changes: 1 addition & 3 deletions app/views/idv/confirm_start_over/before_letter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

<div class="margin-y-5">
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(idv_session_path(step: :request_letter), **tag_options, &block)
end,
url: idv_session_path(step: :request_letter),
method: :delete,
big: true,
wide: true,
Expand Down
4 changes: 1 addition & 3 deletions app/views/idv/confirm_start_over/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

<div class="margin-y-5">
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(idv_session_path(step: :gpo_verify), **tag_options, &block)
end,
url: idv_session_path(step: :gpo_verify),
method: :delete,
big: true,
wide: true,
Expand Down
4 changes: 1 addition & 3 deletions app/views/idv/in_person/verify_info/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ locals:
</div>
<div class="margin-top-5">
<%= render SpinnerButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(idv_in_person_verify_info_path, **tag_options, &block)
end,
url: idv_in_person_verify_info_path,
big: true,
wide: true,
action_message: t('idv.messages.verifying'),
Expand Down
4 changes: 1 addition & 3 deletions app/views/idv/verify_info/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ locals:
</div>
<div class="margin-top-5">
<%= render SpinnerButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(idv_verify_info_path, **tag_options, &block)
end,
url: idv_verify_info_path,
big: true,
wide: true,
action_message: t('idv.messages.verifying'),
Expand Down
4 changes: 1 addition & 3 deletions app/views/session_timeout/_warning.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
t('continue', scope: modal_presenter.translation_scope),
) %>
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(logout_path, **tag_options, &block)
end,
url: logout_path,
method: :delete,
big: true,
full_width: true,
Expand Down
10 changes: 2 additions & 8 deletions app/views/users/auth_app/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
<% end %>

<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(
auth_app_path(id: @form.configuration.id),
form: { aria: { label: t('two_factor_authentication.auth_app.delete') } },
**tag_options,
&block
)
end,
url: auth_app_path(id: @form.configuration.id),
method: :delete,
form: { aria: { label: t('two_factor_authentication.auth_app.delete') } },
big: true,
wide: true,
danger: true,
Expand Down
10 changes: 4 additions & 6 deletions app/views/users/authorization_confirmation/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@

<div class="margin-top-4 text-center">
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(user_authorization_confirmation_path, method: :post, **tag_options, &block)
end,
url: user_authorization_confirmation_path,
method: :post,
big: true,
wide: true,
).with_content(t('user_authorization_confirmation.continue')) %>
<div class="margin-y-4">
<%= t('user_authorization_confirmation.or') %>
</div>
<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(reset_user_authorization_path, method: :delete, **tag_options, &block)
end,
url: reset_user_authorization_path,
method: :delete,
big: true,
wide: true,
).with_content(t('user_authorization_confirmation.sign_in')) %>
Expand Down
26 changes: 15 additions & 11 deletions app/views/users/backup_code_setup/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<% self.title = t('forms.backup_code_regenerate.confirm') %>

<%= render AlertIconComponent.new(icon_name: :warning, class: 'display-block margin-bottom-4') %>
<%= render StatusPageComponent.new(status: :warning) do |c| %>
<% c.with_header { t('forms.backup_code_regenerate.confirm') } %>

<%= render PageHeadingComponent.new.with_content(t('forms.backup_code_regenerate.confirm')) %>
<p><%= t('forms.backup_code_regenerate.caution') %></p>

<p>
<%= t('forms.backup_code_regenerate.caution') %>
</p>
<%= render ButtonComponent.new(
url: backup_code_setup_path,
big: true,
wide: true,
class: 'margin-top-3 margin-bottom-2',
).with_content(t('account.index.backup_code_confirm_regenerate')) %>

<%= form_tag(backup_code_setup_path, method: :get, class: 'margin-top-5') do %>
<%= button_tag t('account.index.backup_code_confirm_regenerate'), type: 'submit',
class: 'usa-button usa-button--big usa-button--wide margin-bottom-2' %>
<%= render ButtonComponent.new(
url: account_path,
big: true,
wide: true,
outline: true,
).with_content(t('links.cancel')) %>
<% end %>

<%= link_to t('links.cancel'), account_path,
class: 'usa-button usa-button--big usa-button--wide usa-button--outline' %>
12 changes: 3 additions & 9 deletions app/views/users/piv_cac/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
<% end %>

<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(
piv_cac_path(id: @form.configuration.id),
form: { aria: { label: @presenter.delete_button_label } },
**tag_options,
&block
)
end,
url: piv_cac_path(id: @form.configuration.id),
method: :delete,
form: { aria: { label: @presenter.delete_button_label } },
big: true,
wide: true,
danger: true,
class: 'display-block margin-top-2',
).with_content(@presenter.delete_button_label) %>

<%= render 'shared/cancel', link: account_path %>
<%= render 'shared/cancel', link: account_path %>
10 changes: 2 additions & 8 deletions app/views/users/webauthn/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@
<% end %>

<%= render ButtonComponent.new(
action: ->(**tag_options, &block) do
button_to(
webauthn_path(id: @form.configuration.id),
form: { aria: { label: @presenter.delete_button_label } },
**tag_options,
&block
)
end,
url: webauthn_path(id: @form.configuration.id),
method: :delete,
form: { aria: { label: @presenter.delete_button_label } },
big: true,
wide: true,
danger: true,
Expand Down
28 changes: 14 additions & 14 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
{
"warning_type": "Dynamic Render Path",
"warning_code": 15,
"fingerprint": "406a2c5ea3d852268958d2db11c146841491b6e87cee9c583dd35f5f41898fb7",
"fingerprint": "0550ef2573eae747e7e4bb6f31851ed77713409b74f7abe48c15a6a82801babb",
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/idv/cancellations/new.html.erb",
"line": 43,
"line": 31,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => ButtonComponent.new(:action => (lambda do\n button_to(idv_cancel_path(:step => params[:step]), { **tag_options }, &block)\n end), :method => :put, :big => true, :wide => true, :outline => true, :form => ({ :\"aria-label\" => t(\"idv.cancel.actions.keep_going\") })).with_content(t(\"idv.cancel.actions.keep_going\")), {})",
"code": "render(action => ButtonComponent.new(:url => idv_session_path(:step => params[:step]), :method => :delete, :big => true, :wide => true, :form => ({ :\"aria-label\" => t(\"idv.cancel.actions.start_over\") })).with_content(t(\"idv.cancel.actions.start_over\")), {})",
"render_path": [
{
"type": "controller",
"class": "Idv::CancellationsController",
"method": "new",
"line": 13,
"line": 16,
"file": "app/controllers/idv/cancellations_controller.rb",
"rendered": {
"name": "idv/cancellations/new",
Expand All @@ -37,19 +37,19 @@
{
"warning_type": "Dynamic Render Path",
"warning_code": 15,
"fingerprint": "8b51f403181f74421f5681ada1096371e1f55fb03d0127db01b5e5da7dda3c51",
"fingerprint": "278d16995e8a645908c9a043314cfeebd8cb094bce766ad5101c62ff08853de6",
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/idv/cancellations/new.html.erb",
"line": 32,
"line": 60,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => ButtonComponent.new(:action => (lambda do\n button_to(idv_session_path(:step => params[:step]), { **tag_options }, &block)\n end), :method => :delete, :big => true, :wide => true, :form => ({ :\"aria-label\" => t(\"idv.cancel.actions.start_over\") })).with_content(t(\"idv.cancel.actions.start_over\")), {})",
"code": "render(action => SpinnerButtonComponent.new(:url => idv_cancel_path(:step => params[:step], :location => \"cancel\"), :method => :delete, :big => true, :wide => true, :outline => true, :form => ({ :\"aria-label\" => CancellationsPresenter.new(:sp_name => decorated_sp_session.sp_name, :url_options => url_options).exit_action_text, :data => ({ :form_steps_wait => \"\" }) })).with_content(CancellationsPresenter.new(:sp_name => decorated_sp_session.sp_name, :url_options => url_options).exit_action_text), {})",
"render_path": [
{
"type": "controller",
"class": "Idv::CancellationsController",
"method": "new",
"line": 13,
"line": 16,
"file": "app/controllers/idv/cancellations_controller.rb",
"rendered": {
"name": "idv/cancellations/new",
Expand All @@ -71,19 +71,19 @@
{
"warning_type": "Dynamic Render Path",
"warning_code": 15,
"fingerprint": "f7d01c6318e6ce369f9fe9bf59b6a3a323034b4b826e2a52a9a87b581d468598",
"fingerprint": "341d99a0fdaf75dff50ea66c9da1b973cb36fc1aac2221480deff6e30d11540a",
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/idv/cancellations/new.html.erb",
"line": 65,
"line": 40,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => SpinnerButtonComponent.new(:action => (lambda do\n button_to(idv_cancel_path(:step => params[:step], :location => \"cancel\"), { **tag_options }, &block)\n end), :method => :delete, :big => true, :wide => true, :outline => true, :form => ({ :\"aria-label\" => CancellationsPresenter.new(:sp_name => decorated_sp_session.sp_name, :url_options => url_options).exit_action_text, :data => ({ :form_steps_wait => \"\" }) })).with_content(CancellationsPresenter.new(:sp_name => decorated_sp_session.sp_name, :url_options => url_options).exit_action_text), {})",
"code": "render(action => ButtonComponent.new(:url => idv_cancel_path(:step => params[:step]), :method => :put, :big => true, :wide => true, :outline => true, :form => ({ :\"aria-label\" => t(\"idv.cancel.actions.keep_going\") })).with_content(t(\"idv.cancel.actions.keep_going\")), {})",
"render_path": [
{
"type": "controller",
"class": "Idv::CancellationsController",
"method": "new",
"line": 13,
"line": 16,
"file": "app/controllers/idv/cancellations_controller.rb",
"rendered": {
"name": "idv/cancellations/new",
Expand All @@ -103,6 +103,6 @@
"note": ""
}
],
"updated": "2023-11-02 09:34:28 -0400",
"brakeman_version": "6.0.1"
"updated": "2024-04-19 08:20:16 -0400",
"brakeman_version": "6.1.0"
}
Loading