Browse Source

Modify way organisation id is set and back links

pull/2629/head
Manny Dinssa 2 years ago
parent
commit
f2e15b9896
  1. 12
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 12
      app/controllers/bulk_upload_sales_logs_controller.rb
  3. 1
      app/models/bulk_upload.rb
  4. 4
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  5. 4
      app/models/forms/bulk_upload_sales/upload_your_file.rb
  6. 1
      app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb
  7. 2
      app/views/bulk_upload_lettings_results/show.html.erb
  8. 2
      app/views/bulk_upload_lettings_results/summary.html.erb
  9. 1
      app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb
  10. 2
      app/views/bulk_upload_sales_results/show.html.erb
  11. 2
      app/views/bulk_upload_sales_results/summary.html.erb
  12. 4
      app/views/logs/_create_for_org_actions.html.erb

12
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -3,6 +3,8 @@ class BulkUploadLettingsLogsController < ApplicationController
before_action :validate_data_protection_agrement_signed!
def start
support_user_redirection and return if current_user.support?
if have_choice_of_year?
redirect_to bulk_upload_lettings_log_path(id: "year")
else
@ -51,7 +53,7 @@ private
when "needstype"
Forms::BulkUploadLettings::Needstype.new(form_params)
when "upload-your-file"
Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:, organisation_id: params[:org]))
Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:, request:))
when "checking-file"
Forms::BulkUploadLettings::CheckingFile.new(form_params)
else
@ -60,6 +62,12 @@ private
end
def form_params
params.fetch(:form, {}).permit(:year, :needstype, :file)
params.fetch(:form, {}).permit(:year, :needstype, :file, :organisation_id)
end
def support_user_redirection
if params[:organisation_id].present?
redirect_to bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: current_year }, organisation_id: params[:organisation_id])
end
end
end

12
app/controllers/bulk_upload_sales_logs_controller.rb

@ -3,6 +3,8 @@ class BulkUploadSalesLogsController < ApplicationController
before_action :validate_data_protection_agrement_signed!
def start
support_user_redirection and return if current_user.support?
if have_choice_of_year?
redirect_to bulk_upload_sales_log_path(id: "year")
else
@ -49,7 +51,7 @@ private
when "guidance"
Forms::BulkUploadSales::Guidance.new(form_params.merge(referrer: params[:referrer]))
when "upload-your-file"
Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:, organisation_id: params[:org]))
Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:, request:))
when "checking-file"
Forms::BulkUploadSales::CheckingFile.new(form_params)
else
@ -58,6 +60,12 @@ private
end
def form_params
params.fetch(:form, {}).permit(:year, :file)
params.fetch(:form, {}).permit(:year, :file, :organisation_id)
end
def support_user_redirection
if params[:organisation_id].present?
redirect_to bulk_upload_sales_log_path(id: "upload-your-file", form: { year: current_year }, organisation_id: params[:organisation_id])
end
end
end

1
app/models/bulk_upload.rb

@ -3,7 +3,6 @@ class BulkUpload < ApplicationRecord
enum rent_type_fix_status: { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" }
belongs_to :user
belongs_to :organisation, optional: true
has_many :bulk_upload_errors, dependent: :destroy

4
app/models/forms/bulk_upload_lettings/upload_your_file.rb

@ -11,7 +11,8 @@ module Forms
attribute :needstype, :integer
attribute :file
attribute :current_user
attribute :organisation_id
attribute :organisation_id, :integer
attr_accessor :request
validates :file, presence: true
validate :validate_file_is_csv
@ -21,6 +22,7 @@ module Forms
end
def back_path
organisation_id = request.query_parameters[:organisation_id]
if organisation_id.present?
lettings_logs_organisation_path(organisation_id)
else

4
app/models/forms/bulk_upload_sales/upload_your_file.rb

@ -10,7 +10,8 @@ module Forms
attribute :year, :integer
attribute :file
attribute :current_user
attribute :organisation_id
attribute :organisation_id, :integer
attr_accessor :request
validates :file, presence: true
validate :validate_file_is_csv
@ -20,6 +21,7 @@ module Forms
end
def back_path
organisation_id = request.query_parameters[:organisation_id]
if organisation_id.present?
sales_logs_organisation_path(organisation_id)
else

1
app/views/bulk_upload_lettings_logs/forms/upload_your_file.html.erb

@ -7,6 +7,7 @@
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "upload-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<%= f.hidden_field :needstype %>
<%= f.hidden_field :organisation_id, value: params[:organisation_id]%>
<%= f.govuk_error_summary %>

2
app/views/bulk_upload_lettings_results/show.html.erb

@ -23,4 +23,4 @@
</div>
</div>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path %>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path(organisation_id: @bulk_upload.organisation_id) %>

2
app/views/bulk_upload_lettings_results/summary.html.erb

@ -27,4 +27,4 @@
<% end %>
</div>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path %>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path(organisation_id: @bulk_upload.organisation_id) %>

1
app/views/bulk_upload_sales_logs/forms/upload_your_file.html.erb

@ -6,6 +6,7 @@
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "upload-your-file"), method: :patch do |f| %>
<%= f.hidden_field :year %>
<%= f.hidden_field :organisation_id, value: params[:organisation_id]%>
<%= f.govuk_error_summary %>

2
app/views/bulk_upload_sales_results/show.html.erb

@ -23,4 +23,4 @@
</div>
</div>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path %>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path(organisation_id: @bulk_upload.organisation_id) %>

2
app/views/bulk_upload_sales_results/summary.html.erb

@ -27,4 +27,4 @@
<% end %>
</div>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path %>
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_sales_logs_path(organisation_id: @bulk_upload.organisation_id) %>

4
app/views/logs/_create_for_org_actions.html.erb

@ -2,11 +2,11 @@
<% if @organisation.data_protection_confirmed? %>
<% if current_page?(controller: 'organisations', action: 'lettings_logs') %>
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %>
<%= govuk_button_link_to "Upload lettings logs in bulk", bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, org: @organisation.id), secondary: true %>
<%= govuk_button_link_to "Upload lettings logs in bulk", bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, organisation_id: @organisation.id), secondary: true %>
<% end %>
<% if current_page?(controller: 'organisations', action: 'sales_logs') %>
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %>
<%= govuk_button_link_to "Upload sales logs in bulk", bulk_upload_sales_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, org: @organisation.id), secondary: true %>
<%= govuk_button_link_to "Upload sales logs in bulk", bulk_upload_sales_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, organisation_id: @organisation.id), secondary: true %>
<% end %>
<% end %>
</div>

Loading…
Cancel
Save