Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/DSACMS/iv-cbv-payroll into …
Browse files Browse the repository at this point in the history
…wmg/2464-multi-modal
  • Loading branch information
jeffcatania-usds committed Feb 27, 2025
2 parents f0e59c2 + dac5ee7 commit 86a5564
Show file tree
Hide file tree
Showing 57 changed files with 287 additions and 404 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/owasp-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
with:
target: 'http://localhost:3000/'
fail_action: true
cmd_options: -c app/zap.conf -z "-configfile /zap/wrk/zap_options.conf"
cmd_options: -c app/zap.conf
2 changes: 2 additions & 0 deletions app/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ Layout/IndentationWidth:
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: normal
Layout/EndAlignment:
EnforcedStyleAlignWith: keyword
20 changes: 0 additions & 20 deletions app/app/assets/stylesheets/cbv.scss
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,6 @@ html {
/**
* Help Modal
*/
#help-iframe {
min-height: 600px;
line-height: 1;

// Small screens such as mobile
@media screen and (max-width: 375px) {
height: 73vh;
}

// Medium screens such as tablets
@media screen and (min-width: 810px) {
height: 630px;
}

// Larger screens such as desktop
@include at-media(desktop) {
height: 660px;
}
}

.main-bullets {
list-style-type: disc;
}
Expand Down
2 changes: 1 addition & 1 deletion app/app/channels/paystubs_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def subscribed
private

def check_pinwheel_account_synchrony
pinwheel_account = PinwheelAccount.find_by_pinwheel_account_id(params["account_id"])
pinwheel_account = PayrollAccount.find_by_pinwheel_account_id(params["account_id"])

if pinwheel_account.present?
broadcast_to(@cbv_flow, {
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/api/pinwheel_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def create_token
token_response = pinwheel.create_link_token(
response_type: token_params[:response_type],
id: token_params[:id],
end_user_id: @cbv_flow.pinwheel_end_user_id,
end_user_id: @cbv_flow.end_user_id,
language: token_params[:locale]
)
token = token_response["data"]["token"]
Expand Down
8 changes: 3 additions & 5 deletions app/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ def redirect_if_maintenance_mode
def check_help_param
if params[:help] == "true"
help_link = helpers.render(partial: "help/help_link", locals: { text: t("help.alert.help_options"), source: "banner" })
flash.merge!(
alert: "#{t('help.alert.text_before')} #{help_link}",
alert_heading: t("help.alert.heading"),
alert_type: "warning"
)
flash.now[:alert] = "#{t('help.alert.text_before')} #{help_link}"
flash.now[:alert_heading] = t("help.alert.heading")
flash.now[:alert_type] = "warning"
end
end
end
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/employer_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Cbv::EmployerSearchesController < Cbv::BaseController
def show
@query = search_params[:query]
@employers = @query.blank? ? [] : provider_search(@query)
@has_pinwheel_account = @cbv_flow.pinwheel_accounts.any?
@has_pinwheel_account = @cbv_flow.payroll_accounts.any?
@selected_tab = search_params[:type] || "payroll"

case search_params[:type]
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/missing_results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Cbv::MissingResultsController < Cbv::BaseController
before_action :track_missing_results_event, only: :show

def show
@has_pinwheel_account = @cbv_flow.pinwheel_accounts.any?
@has_pinwheel_account = @cbv_flow.payroll_accounts.any?
end

def track_missing_results_event
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/payment_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Cbv::PaymentDetailsController < Cbv::BaseController

def show
account_id = params[:user][:account_id]
@pinwheel_account = @cbv_flow.pinwheel_accounts.find_by(pinwheel_account_id: account_id)
@pinwheel_account = @cbv_flow.payroll_accounts.find_by(pinwheel_account_id: account_id)

# security check - make sure the account_id is associated with the current cbv_flow_id
if @pinwheel_account.nil?
Expand Down
8 changes: 4 additions & 4 deletions app/app/controllers/cbv/summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def transmit_to_caseworker
employments: @employments,
incomes: @incomes,
identities: @identities,
payments_grouped_by_employer: summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.pinwheel_accounts),
payments_grouped_by_employer: summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.payroll_accounts),
has_consent: has_consent
}
)
Expand Down Expand Up @@ -164,7 +164,7 @@ def transmit_to_caseworker
end

def generate_csv
pinwheel_account = PinwheelAccount.find_by(cbv_flow_id: @cbv_flow.id)
pinwheel_account = PayrollAccount.find_by(cbv_flow_id: @cbv_flow.id)

data = {
client_id: @cbv_flow.cbv_applicant.agency_id_number,
Expand Down Expand Up @@ -195,7 +195,7 @@ def track_transmitted_event(cbv_flow, payments)
cbv_applicant_id: cbv_flow.cbv_applicant_id,
cbv_flow_id: cbv_flow.id,
invitation_id: cbv_flow.cbv_flow_invitation_id,
account_count: cbv_flow.pinwheel_accounts.count,
account_count: cbv_flow.payroll_accounts.count,
paystub_count: payments.count,
account_count_with_additional_information:
cbv_flow.additional_information.values.count { |info| info["comment"].present? },
Expand All @@ -213,7 +213,7 @@ def track_accessed_income_summary_event(cbv_flow, payments)
cbv_flow_id: cbv_flow.id,
cbv_applicant_id: cbv_flow.cbv_applicant_id,
invitation_id: cbv_flow.cbv_flow_invitation_id,
account_count: cbv_flow.pinwheel_accounts.count,
account_count: cbv_flow.payroll_accounts.count,
paystub_count: payments.count,
account_count_with_additional_information:
cbv_flow.additional_information.values.count { |info| info["comment"].present? },
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/synchronizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def redirect_if_sync_finished
def set_pinwheel_account
account_id = params[:user][:account_id]

@pinwheel_account = @cbv_flow.pinwheel_accounts.find_by(pinwheel_account_id: account_id)
@pinwheel_account = @cbv_flow.payroll_accounts.find_by(pinwheel_account_id: account_id)
end
end
3 changes: 3 additions & 0 deletions app/app/controllers/help_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class HelpController < ApplicationController

def index
@title = t("help.index.title")
render layout: false
end

def show
Expand All @@ -25,6 +26,8 @@ def show
rescue => ex
Rails.logger.error "Unable to track event (ApplicantViewedHelpTopic): #{ex}"
end

render layout: false if turbo_frame_request?
end

private
Expand Down
19 changes: 19 additions & 0 deletions app/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
class PagesController < ApplicationController
def home
end

def error_404
# When in development environment, you'll need to set
# config.consider_all_requests_local = false
# in config/development.rb for these pages to actually show up.
@cbv_flow = if session[:cbv_flow_id]
CbvFlow.find(session[:cbv_flow_id])
end

render status: :not_found, formats: %i[html]
end

def error_500
# When in development environment, you'll need to set
# config.consider_all_requests_local = false
# in config/development.rb for these pages to actually show up.

render status: :internal_server_error, formats: %i[html]
end
end
12 changes: 6 additions & 6 deletions app/app/controllers/webhooks/pinwheel/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def create

if params["event"] == "account.added"
supported_jobs = get_supported_jobs(params["payload"]["platform_id"])
PinwheelAccount
PayrollAccount
.create_with(cbv_flow: @cbv_flow, supported_jobs: supported_jobs)
.find_or_create_by(pinwheel_account_id: params["payload"]["account_id"])
track_account_created_event(@cbv_flow, params["payload"]["platform_name"])
end

if PinwheelAccount::EVENTS_MAP.keys.include?(params["event"])
pinwheel_account = PinwheelAccount.find_by_pinwheel_account_id(params["payload"]["account_id"])
if PayrollAccount::EVENTS_MAP.keys.include?(params["event"])
pinwheel_account = PayrollAccount.find_by_pinwheel_account_id(params["payload"]["account_id"])

if pinwheel_account.present?
pinwheel_account.update!(PinwheelAccount::EVENTS_MAP[params["event"]] => Time.now)
pinwheel_account.update!(PayrollAccount::EVENTS_MAP[params["event"]] => Time.now)

if params.dig("payload", "outcome") == "error" || params.dig("payload", "outcome") == "pending"
pinwheel_account.update!(PinwheelAccount::EVENTS_ERRORS_MAP[params["event"]] => Time.now)
pinwheel_account.update!(PayrollAccount::EVENTS_ERRORS_MAP[params["event"]] => Time.now)
end

if pinwheel_account.has_fully_synced?
Expand Down Expand Up @@ -86,7 +86,7 @@ def track_account_created_event(cbv_flow, platform_name)
end

def set_cbv_flow
@cbv_flow = CbvFlow.find_by_pinwheel_end_user_id(params["payload"]["end_user_id"])
@cbv_flow = CbvFlow.find_by_end_user_id(params["payload"]["end_user_id"])
end

def set_pinwheel
Expand Down
12 changes: 6 additions & 6 deletions app/app/helpers/cbv/pinwheel_data_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ def set_payments(account_id = nil)
end

def set_employments
@employments = @cbv_flow.pinwheel_accounts.map do |pinwheel_account|
@employments = @cbv_flow.payroll_accounts.map do |pinwheel_account|
next unless pinwheel_account.job_succeeded?("employment")

pinwheel.fetch_employment(account_id: pinwheel_account.pinwheel_account_id)
end.compact
end

def set_incomes
@incomes = @cbv_flow.pinwheel_accounts.map do |pinwheel_account|
@incomes = @cbv_flow.payroll_accounts.map do |pinwheel_account|
next unless pinwheel_account.job_succeeded?("income")

pinwheel.fetch_income(account_id: pinwheel_account.pinwheel_account_id)
end.compact
end

def set_identities
@identities = @cbv_flow.pinwheel_accounts.map do |pinwheel_account|
@identities = @cbv_flow.payroll_accounts.map do |pinwheel_account|
next unless pinwheel_account.job_succeeded?("identity")

pinwheel.fetch_identity(account_id: pinwheel_account.pinwheel_account_id)
Expand All @@ -43,7 +43,7 @@ def hours_by_earning_category(earnings)
end

def payments_grouped_by_employer
summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.pinwheel_accounts)
summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.payroll_accounts)
end

def total_gross_income
Expand Down Expand Up @@ -74,7 +74,7 @@ def summarize_by_employer(payments, employments, incomes, identities, pinwheel_a
private

def fetch_paystubs(from_pay_date, to_pay_date)
@cbv_flow.pinwheel_accounts.flat_map do |pinwheel_account|
@cbv_flow.payroll_accounts.flat_map do |pinwheel_account|
next [] unless pinwheel_account.job_succeeded?("paystubs")

fetch_paystubs_for_account_id(pinwheel_account.pinwheel_account_id, from_pay_date, to_pay_date)
Expand All @@ -90,7 +90,7 @@ def fetch_paystubs_for_account_id(account_id, from_pay_date, to_pay_date)
end

def does_pinwheel_account_support_job?(account_id, job)
pinwheel_account = PinwheelAccount.find_by_pinwheel_account_id(account_id)
pinwheel_account = PayrollAccount.find_by_pinwheel_account_id(account_id)
return false unless pinwheel_account

pinwheel_account.job_succeeded?(job)
Expand Down
44 changes: 14 additions & 30 deletions app/app/javascript/controllers/help.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
import { Controller } from "@hotwired/stimulus"
import { trackUserAction } from "../utilities/api"
import { Controller } from "@hotwired/stimulus";
import { trackUserAction } from "../utilities/api";

export default class extends Controller {
static targets = ["iframe"]
static targets = ["content"];

connect() {
this.handleClick = (event) => {
if (event.target.href?.includes("#help-modal")) {
trackUserAction("ApplicantOpenedHelpModal", { source: event.target.dataset.source })
}
handleClick(event) {
if (event.target.href?.includes("#help-modal")) {
trackUserAction("ApplicantOpenedHelpModal", {
source: event.target.dataset.source,
});
// reset the help modal src on mousedown to ensure the help modal src is reset to "/help"
document.querySelector("#help_modal_content").src = "/help";
}

document.addEventListener("click", this.handleClick)
}

disconnect() {
document.removeEventListener("click", this.handleClick)
connect() {
document.addEventListener("click", this.handleClick);
}

/**
* This function is used to prepare the next URL for the iframe.
* It generates a new random parameter and updates the iframe src
* so that when the modal is opened, the iframe will load the
* default help topics rather than the last viewed topic.
*/
prepareNextUrl() {
const iframe = this.iframeTarget
const currentSrc = new URL(iframe.src)

// Generate a new random parameter
const randomHex = Array.from(crypto.getRandomValues(new Uint8Array(2)))
.map(b => b.toString(16).padStart(2, "0"))
.join("")

// Update the iframe src with new random parameter
currentSrc.searchParams.set("r", randomHex)
iframe.src = currentSrc.toString()
disconnect() {
document.removeEventListener("click", this.handleClick);
}
}
2 changes: 1 addition & 1 deletion app/app/javascript/utilities/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export const fetchArgyleToken = () => {
return fetchInternal(ARGYLE_TOKENS_GENERATE, {
method: 'post',
})
};
};
6 changes: 3 additions & 3 deletions app/app/models/cbv_flow.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CbvFlow < ApplicationRecord
has_many :pinwheel_accounts, dependent: :destroy
has_many :payroll_accounts, dependent: :destroy
belongs_to :cbv_flow_invitation, optional: true
belongs_to :cbv_applicant, optional: true
validates :client_agency_id, inclusion: Rails.application.config.client_agencies.client_agency_ids
Expand All @@ -11,7 +11,7 @@ class CbvFlow < ApplicationRecord
include Redactable
has_redactable_fields(
case_number: :string,
pinwheel_end_user_id: :uuid,
end_user_id: :uuid,
additional_information: :object
)

Expand All @@ -28,6 +28,6 @@ def self.create_from_invitation(cbv_flow_invitation)
end

def has_account_with_required_data?
pinwheel_accounts.any?(&:has_required_data?)
payroll_accounts.any?(&:has_required_data?)
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class PinwheelAccount < ApplicationRecord
class PayrollAccount < ApplicationRecord
belongs_to :cbv_flow

after_update_commit {
Expand Down
16 changes: 5 additions & 11 deletions app/app/views/help/_help_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
data-controller="help"
>
<div class="usa-modal__content">
<div class="usa-modal__main padding-0 margin-0 maxw-none-important">
<div class="usa-modal__body padding-0">
<iframe
id="help-iframe"
src="<%= help_path(site_id: params[:site_id]) %>"
class="width-full border-0"
title="Help Content"
data-help-target="iframe"
scrolling="no"
>
</iframe>
<div class="usa-modal__main">
<div class="usa-modal__body" data-help-target="content">
<%= turbo_frame_tag "help_content" do %>
<%= render template: "help/index" %>
<% end %>
</div>
</div>

Expand Down
3 changes: 2 additions & 1 deletion app/app/views/help/_help_topic_link.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= link_to help_topic_path(topic: topic, locale: I18n.locale),
class: "usa-button margin-bottom-1 height-5 text-left display-block" do %>
class: "usa-button margin-bottom-1 height-5 text-left display-block",
data: { turbo_frame: "help_modal_content" } do %>
<%= text %>
<% end %>
Loading

0 comments on commit 86a5564

Please sign in to comment.