Skip to content

Commit

Permalink
feat(rfh): add new triage questions
Browse files Browse the repository at this point in the history
Jira: PWNN-1554
  • Loading branch information
EdwinKruglov committed Sep 19, 2023
1 parent 609e340 commit a75b98f
Show file tree
Hide file tree
Showing 115 changed files with 1,716 additions and 574 deletions.
31 changes: 19 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
# using RuboCop version 1.44.1.
# using RuboCop version 1.55.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedMethods, AllowedPatterns.
Lint/AmbiguousBlockAssociation:
Exclude:
- 'spec/models/exit_survey_response_spec.rb'
- 'spec/services/support/messages/outlook/resync_email_ids_spec.rb'

# Offense count: 8
# Configuration parameters: AllowedPatterns, IgnoredPatterns.
# Configuration parameters: AllowedPatterns.
# SupportedStyles: snake_case, camelCase
Naming/MethodName:
EnforcedStyle: snake_case
Expand All @@ -36,29 +37,37 @@ RSpec/AnyInstance:
- 'spec/support/shared/notify_email_templates.rb'
- 'spec/support/sign_in_helpers.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/controllers/support_agents_spec.rb'

# Offense count: 3
# Offense count: 11
RSpec/LetSetup:
Enabled: false
Exclude:
- 'spec/jobs/support/send_exit_survey_job_spec.rb'
- 'spec/services/support/messages/outlook/synchronisation/message_case_detection_spec.rb'
- 'spec/support/shared/duplicate_email_attachments.rb'
- 'spec/support/shared/support_agent.rb'

# Offense count: 4
RSpec/SubjectStub:
Exclude:
- 'spec/forms/framework_requests/special_requirements_form_spec.rb'
- 'spec/services/support/messages/outlook/synchronisation/message_case_detection_spec.rb'

# Offense count: 115
# Offense count: 125
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Enabled: false

# Offense count: 13
# Configuration parameters: Database, Include.
# SupportedDatabases: mysql, postgresql
# Include: db/migrate/*.rb
# Include: db/**/*.rb
Rails/BulkChangeTable:
Exclude:
- 'db/migrate/20210118110545_change_options_to_jsonb.rb'
Expand All @@ -72,16 +81,17 @@ Rails/BulkChangeTable:
- 'db/migrate/20221014140003_add_more_trust_fields_to_support_organisations.rb'
- 'db/migrate/20230210133230_refactor_notifications_into_one_table.rb'

# Offense count: 2
# Offense count: 3
# Configuration parameters: Include.
# Include: app/controllers/**/*.rb, app/mailers/**/*.rb
Rails/LexicallyScopedActionFilter:
Exclude:
- 'app/controllers/all_cases_survey/satisfaction_reason_controller.rb'
- 'app/controllers/framework_requests/document_uploads_controller.rb'

# Offense count: 1
# Configuration parameters: Include.
# Include: db/migrate/*.rb
# Include: db/**/*.rb
Rails/NotNullColumn:
Exclude:
- 'db/migrate/20210107122307_add_liquid_template_to_journey.rb'
Expand Down Expand Up @@ -119,6 +129,3 @@ Style/DateTime:
- 'lib/microsoft_graph/transformer/attachment.rb'
- 'lib/microsoft_graph/transformer/message.rb'
- 'lib/microsoft_graph/transformer/update_message.rb'

Rails/UniqueValidationWithoutIndex:
Enabled: false
10 changes: 5 additions & 5 deletions app/controllers/framework_requests/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def sign_in_path
confirm_sign_in_framework_requests_path
end

def last_energy_path
return energy_alternative_framework_requests_path(framework_support_form: form.common) if framework_request.energy_alternative.present?
return energy_bill_framework_requests_path(framework_support_form: form.common) if framework_request.have_energy_bill.present?
return energy_request_about_framework_requests_path(framework_support_form: form.common) if framework_request.energy_request_about.present?
def set_flow(flow)
session[:framework_request_flow] = flow
end

energy_request_framework_requests_path(framework_support_form: form.common)
def flow
(session[:framework_request_flow] || "").inquiry
end

def create_redirect_path; end
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/framework_requests/bill_uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ def back_url
end

def determine_back_path
@current_user = UserPresenter.new(current_user)
return email_framework_requests_path(framework_support_form: form.common) if @current_user.guest?
return last_energy_path if @current_user.single_org?
return energy_alternative_framework_requests_path(framework_support_form: form.common) if framework_request.energy_alternative.present?

select_organisation_framework_requests_path(framework_support_form: form.common)
energy_bill_framework_requests_path(framework_support_form: form.common)
end
end
end
33 changes: 27 additions & 6 deletions app/controllers/framework_requests/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create

@form.save! if @form.new_path?

set_flow(framework_request.flow)
redirect_to create_redirect_path
end

Expand All @@ -42,8 +43,8 @@ def back_url = @back_url = determine_back_path

def create_redirect_path
if @form.final_category?
if @form.allow_bill_upload?
special_requirements_framework_requests_path(framework_support_form: @form.common)
if flow.energy? || flow.services?
contract_length_framework_requests_path(framework_support_form: @form.common)
else
procurement_amount_framework_requests_path(framework_support_form: @form.common)
end
Expand All @@ -60,10 +61,30 @@ def edit_back_url
end

def determine_back_path
return categories_framework_requests_path(framework_support_form: @form.common.merge(category_slug: "multiple")) if category_path == "multiple"
return message_framework_requests_path(framework_support_form: @form.common) if category_path.nil?

categories_framework_requests_path(category_path: @form.parent_category_path, framework_support_form: @form.common)
@current_user = UserPresenter.new(current_user)
# return categories_framework_requests_path(framework_support_form: @form.common.merge(category_slug: "multiple")) if category_path == "multiple"
# return email_framework_requests_path(framework_support_form: @form.common) if category_path.nil? && @current_user.guest?
# return confirm_schools_framework_requests_path(framework_support_form: @form.common) if category_path.nil? && form.eligible_for_school_picker?
# return confirm_sign_in_framework_requests_path(framework_support_form: @form.common) if category_path.nil? && @current_user.single_org?
# return select_organisation_framework_requests_path(framework_support_form: @form.common) if category_path.nil?

# categories_framework_requests_path(category_path: @form.parent_category_path, framework_support_form: @form.common)

if category_path == "multiple"
categories_framework_requests_path(framework_support_form: @form.common.merge(category_slug: "multiple"))
elsif category_path.nil?
if @current_user.guest?
email_framework_requests_path(framework_support_form: @form.common)
elsif form.eligible_for_school_picker?
confirm_schools_framework_requests_path(framework_support_form: @form.common)
elsif @current_user.single_org?
confirm_sign_in_framework_requests_path(framework_support_form: @form.common)
else
select_organisation_framework_requests_path(framework_support_form: @form.common)
end
else
categories_framework_requests_path(category_path: @form.parent_category_path, framework_support_form: @form.common)
end
end

def form_params = %i[category_slug category_other]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ def form_params
end

def create_redirect_path
if @form.allow_bill_upload?
bill_uploads_framework_requests_path(framework_support_form: @form.common)
elsif current_user.guest?
if current_user.guest?
name_framework_requests_path(framework_support_form: @form.common)
else
message_framework_requests_path(framework_support_form: @form.common)
categories_framework_requests_path(framework_support_form: @form.common)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def create_redirect_path
@current_user = UserPresenter.new(current_user)
return select_organisation_framework_requests_path(framework_support_form: form.common) unless @current_user.single_org?
return school_picker_framework_requests_path(framework_support_form: form.common) if @current_user.belongs_to_trust_or_federation? && @current_user.org.organisations.present?
return bill_uploads_framework_requests_path(framework_support_form: form.common) if @form.allow_bill_upload?

message_framework_requests_path(framework_support_form: form.common)
categories_framework_requests_path(framework_support_form: form.common)
end

def set_inferred_attrbutes
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/framework_requests/contract_lengths_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module FrameworkRequests
class ContractLengthsController < BaseController
skip_before_action :authenticate_user!

private

def form
@form ||= FrameworkRequests::ContractLengthForm.new(all_form_params)
end

def form_params
[:contract_length]
end

def create_redirect_path
contract_start_date_framework_requests_path(framework_support_form: form.common)
end

def back_url
@back_url = categories_framework_requests_path(category_path: framework_request.category&.ancestors_slug, framework_support_form: @form.common)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module FrameworkRequests
class ContractStartDatesController < BaseController
include Support::Concerns::HasDateParams

skip_before_action :authenticate_user!

private

def form
@form ||= FrameworkRequests::ContractStartDateForm.new(all_form_params)
end

def form_params
%i[contract_start_date_known contract_start_date]
end

def all_form_params
super
.except("contract_start_date(3i)", "contract_start_date(2i)", "contract_start_date(1i)")
.merge(contract_start_date: date_param(:framework_support_form, :contract_start_date).compact_blank)
end

def create_redirect_path
if framework_request.multischool?
same_supplier_framework_requests_path(framework_support_form: form.common)
else
procurement_amount_framework_requests_path(framework_support_form: form.common)
end
end

def back_url
@back_url = contract_length_framework_requests_path(ramework_support_form: @form.common)
end
end
end
71 changes: 71 additions & 0 deletions app/controllers/framework_requests/document_uploads_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module FrameworkRequests
class DocumentUploadsController < BaseController
skip_before_action :authenticate_user!

before_action :set_document_types, only: %i[index edit]

def list
files = framework_request.documents.map do |bill|
{
file_id: bill.id,
name: bill.filename,
size: bill.file.attachment.byte_size,
type: bill.file.attachment.content_type,
}
end
render status: :ok, json: files.to_json
end

def upload
if file_is_safe?
document = Document.pending.create!(
file: params[:file],
framework_request_id: framework_request.id,
filename: params[:file].original_filename,
)

render status: :created, json: { file_id: document.id }
else
track_event("Rfh/DocumentUploads/Upload/VirusDetected", framework_request_id: framework_request.id)

params[:file].tempfile.delete

render status: :unprocessable_entity, json: { error: "virus detected" }
end
end

def remove
document = Document.find(params[:file_id])
document.destroy!
head :ok
end

private

def file_is_safe?
# Rails.configuration.clamav_scanner.file_is_safe?(params[:file])
true
end

def form
@form ||= FrameworkRequests::DocumentUploadsForm.new(all_form_params)
end

def update_data
{}
end

def create_redirect_path
special_requirements_framework_requests_path(framework_support_form: form.common)
end

def back_url
@back_url = documents_framework_requests_path(framework_support_form: form.common)
end

def set_document_types
@document_types = framework_request.document_types
@other = framework_request.document_type_other
end
end
end
25 changes: 25 additions & 0 deletions app/controllers/framework_requests/documents_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module FrameworkRequests
class DocumentsController < BaseController
skip_before_action :authenticate_user!

private

def form
@form ||= FrameworkRequests::DocumentsForm.new(all_form_params)
end

def form_params
[:document_type_other, { document_types: [] }]
end

def create_redirect_path
return special_requirements_framework_requests_path(framework_support_form: @form.common) if framework_request.document_types.include?("none")

document_uploads_framework_requests_path(framework_support_form: @form.common)
end

def back_url
@back_url = message_framework_requests_path(framework_support_form: @form.common)
end
end
end
4 changes: 1 addition & 3 deletions app/controllers/framework_requests/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def form_params
end

def create_redirect_path
return bill_uploads_framework_requests_path(framework_support_form: form.common) if form.allow_bill_upload?

message_framework_requests_path(framework_support_form: form.common)
categories_framework_requests_path(framework_support_form: form.common)
end

def back_url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def form_params
[:energy_alternative]
end

def create_redirect_path = sign_in_path
def create_redirect_path
return bill_uploads_framework_requests_path(framework_support_form: @form.common) if framework_request.different_format_energy_alternative?

special_requirements_framework_requests_path(framework_support_form: @form.common)
end

def back_url
@back_url = energy_bill_framework_requests_path(framework_support_form: @form.common)
Expand Down
Loading

0 comments on commit a75b98f

Please sign in to comment.