Skip to content

Commit

Permalink
I have updated the RM3830 admin section so that when the framework ha…
Browse files Browse the repository at this point in the history
…s expired, admins will be unable to edit/update any of the service/supplier data in the system.

I’ve also added specs to validate these changes.
  • Loading branch information
tim-s-ccs committed Mar 14, 2023
1 parent e4877fe commit f336d8a
Show file tree
Hide file tree
Showing 28 changed files with 865 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def set_lot
def service_scope
:facilities_management
end

def set_framework_has_expired
@framework_has_expired = Framework.find_by(framework: params[:framework]).status == :expired
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module FacilitiesManagement
module Admin
class SupplierDetailsController < FacilitiesManagement::Admin::FrameworkController
before_action :set_framework_has_expired
before_action :redirect_if_framework_has_expired, only: %i[edit update]
before_action :set_data_for_framework
before_action :set_supplier
before_action :set_page, only: %i[edit update]
Expand Down Expand Up @@ -53,6 +55,10 @@ def supplier_params
params.require(@suppliers_admin_param_key).permit(PERMITED_PARAMS[@page])
end

def redirect_if_framework_has_expired
redirect_to facilities_management_admin_supplier_detail_path if @framework_has_expired
end

PERMITED_PARAMS = {
supplier_name: %i[supplier_name],
supplier_contact_information: %i[contact_name contact_email contact_phone],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module FacilitiesManagement
module RM3830
module Admin
class ServiceRatesController < FacilitiesManagement::Admin::FrameworkController
before_action :set_framework_has_expired
before_action :redirect_if_framework_has_expired, only: :update
before_action :set_slug, :set_rate_type, :full_services, :set_variances, :initialise_errors

def edit; end
Expand Down Expand Up @@ -74,6 +76,10 @@ def save_updated_rates

@variances.each { |_label, rate| rate.save if rate.changed? }
end

def redirect_if_framework_has_expired
redirect_to edit_facilities_management_rm3830_admin_service_rate_path if @framework_has_expired
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module FacilitiesManagement
module RM3830
module Admin
class SublotRegionsController < FacilitiesManagement::Admin::FrameworkController
before_action :set_framework_has_expired
before_action :redirect_if_framework_has_expired, only: :update
before_action :set_supplier, :set_lot, :redirect_if_lot_out_of_range
before_action :set_region_data, only: :edit

Expand All @@ -22,6 +24,10 @@ def set_region_data
@selected_supplier_regions = Supplier::SupplierRegionsHelper.supllier_selected_regions(supplier_lot_data)
@subregions = FacilitiesManagement::Region.all.to_h { |region| [region.code, region.name] }
end

def redirect_if_framework_has_expired
redirect_to edit_facilities_management_rm3830_admin_supplier_framework_datum_sublot_region_path if @framework_has_expired
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module FacilitiesManagement
module RM3830
module Admin
class SublotServicesController < FacilitiesManagement::Admin::FrameworkController
before_action :set_framework_has_expired
before_action :redirect_if_framework_has_expired, only: :update
before_action :set_supplier, :set_lot, :redirect_if_lot_out_of_range
before_action :full_services
before_action :set_service_data, only: :edit
Expand Down Expand Up @@ -86,6 +88,10 @@ def update_checkboxes
@supplier.replace_services_for_lot(params[:checked_services], @lot)
@supplier.save
end

def redirect_if_framework_has_expired
redirect_to edit_facilities_management_rm3830_admin_supplier_framework_datum_sublot_service_path if @framework_has_expired
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/facilities_management/admin/framework_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ def admin_breadcrumbs(*breadcrumbs)

govuk_breadcrumbs(*breadcrumbs)
end

def framework_expired_warning(text)
warning_text(text) if @framework_has_expired
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
) %>
<%= govuk_page_header(FacilitiesManagement::PageDetail::Heading.new(t('.supplier_details'), @supplier.supplier_name, nil, nil, nil)) %>
<%= framework_expired_warning(t("facilities_management.#{params[:framework].downcase}.admin.you_cannot_update.details")) %>

<p class="govuk-body govuk-!-font-weight-regular govuk-hint">
<%= t('.edit_supplier_details') %>
</p>
Expand All @@ -24,9 +26,11 @@
<dd class="govuk-summary-list__value">
<%= supplier_user_email %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_user), class: 'govuk-link--no-visited-state') %>
</dd>
<% unless @framework_has_expired %>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_user), class: 'govuk-link--no-visited-state') %>
</dd>
<% end %>
</div>
</dl>
</div>
Expand All @@ -48,9 +52,11 @@
<dd class="govuk-summary-list__value">
<%= govuk_tag_with_text(*@supplier.current_status) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_status), class: 'govuk-link--no-visited-state') %>
</dd>
<% unless @framework_has_expired %>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_status), class: 'govuk-link--no-visited-state') %>
</dd>
<% end %>
</div>
</dl>
</div>
Expand All @@ -71,9 +77,11 @@
<dd class="govuk-summary-list__value">
<%= contact_detail(:supplier_name) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_name), class: 'govuk-link--no-visited-state') %>
</dd>
<% unless @framework_has_expired %>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_name), class: 'govuk-link--no-visited-state') %>
</dd>
<% end %>
</div>
<% if params[:framework] == 'RM3830' %>
<% %i[contact_name contact_email contact_phone].each do |attribute| %>
Expand All @@ -84,9 +92,11 @@
<dd class="govuk-summary-list__value">
<%= contact_detail(attribute) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_contact_information), class: 'govuk-link--no-visited-state') %>
</dd>
<% unless @framework_has_expired %>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_contact_information), class: 'govuk-link--no-visited-state') %>
</dd>
<% end %>
</div>
<% end %>
<% end %>
Expand All @@ -109,9 +119,11 @@
<dd class="govuk-summary-list__value">
<%= contact_detail(attribute) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :additional_supplier_information), class: 'govuk-link--no-visited-state') %>
</dd>
<% unless @framework_has_expired %>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :additional_supplier_information), class: 'govuk-link--no-visited-state') %>
</dd>
<% end %>
</div>
<% end %>
<div id="supplier-details--full_address"class="govuk-summary-list__row">
Expand All @@ -121,9 +133,11 @@
<dd class="govuk-summary-list__value">
<%= full_address %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_address), class: 'govuk-link--no-visited-state') %>
</dd>
<% unless @framework_has_expired %>
<dd class="govuk-summary-list__actions">
<%= link_to(t('.change'), edit_facilities_management_admin_supplier_detail_path(@framework, @supplier, page: :supplier_address), class: 'govuk-link--no-visited-state') %>
</dd>
<% end %>
</div>
</dl>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<h1 class="govuk-heading-xl">
<%= t('.heading') %>
</h1>

<%= framework_expired_warning(t('facilities_management.rm3830.admin.you_cannot_update.rates')) %>

<p class="govuk-body govuk-!-font-weight-regular govuk-hint">
<%= t('.leading_text') %><br/>
<%= t('.percentage_note') %>
Expand Down Expand Up @@ -36,7 +39,7 @@
</td>

<td class="govuk-table__cell supplier-rates-td">
<%= text_field_tag "rates[#{rate.id}]", rate.read_attribute_before_type_cast(:framework), class: "govuk-input govuk-input--width-3 #{'govuk-input--error' if rate_invalid }" %>
<%= text_field_tag "rates[#{rate.id}]", rate.read_attribute_before_type_cast(:framework), class: "govuk-input govuk-input--width-3 #{'govuk-input--error' if rate_invalid }", disabled: @framework_has_expired %>
</td>
</tr>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<h1 class="govuk-heading-xl"><%= t('.heading') %></h1>

<%= framework_expired_warning(t('facilities_management.rm3830.admin.you_cannot_update.rates')) %>

<p class="govuk-body govuk-!-font-weight-regular govuk-hint">
<%= t('.leading_text') %><br/>
<%= t('.percentage_note') %>
Expand Down Expand Up @@ -49,7 +52,7 @@
<td class="govuk-table__cell supplier-rates-td">
<% rate = work_pckg['rates'].find(&selector) %>
<% if rate %>
<%= text_field_tag "rates[#{rate.id}]", rate.read_attribute_before_type_cast(:benchmark), class: "govuk-input govuk-input--width-3 #{'govuk-input--error' if rate.errors.any?}", 'aria-label': "#{work_pckg['name']} #{rate.standard.blank? ? 'normal price' : "standard #{rate.standard}"}" %>
<%= text_field_tag "rates[#{rate.id}]", rate.read_attribute_before_type_cast(:benchmark), class: "govuk-input govuk-input--width-3 #{'govuk-input--error' if rate.errors.any?}", 'aria-label': "#{work_pckg['name']} #{rate.standard.blank? ? 'normal price' : "standard #{rate.standard}"}", disabled: @framework_has_expired %>
<% end %>
</td>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
</td>
<td class="govuk-table__cell supplier-rates-td">
<%= text_field_tag "rates[#{rate.id}]", rate.read_attribute_before_type_cast(attribue), class: "govuk-input govuk-input--width-3 #{'govuk-input--error' if rate_invalid }" %>
<%= text_field_tag "rates[#{rate.id}]", rate.read_attribute_before_type_cast(attribue), class: "govuk-input govuk-input--width-3 #{'govuk-input--error' if rate_invalid }", disabled: @framework_has_expired %>
</td>
</tr>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<%= form_with url: facilities_management_rm3830_admin_service_rate_path(slug: @slug), method: :put, html: { specialvalidation: true, novalidate: true }, local: 'false' do |f| %>
<%= render partial: @slug, locals: { f: f } %>
<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_benchmark_rates', aria: { label: t('.update_button') } %>
<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_benchmark_rates', aria: { label: t('.update_button') }, disabled: @framework_has_expired %>
<%= link_to t('.return_link'), facilities_management_rm3830_admin_path, class: 'govuk-link govuk-caption-m'%>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<h2 class="govuk-caption-l govuk-!-margin-bottom-2 govuk-!-font-weight-regular"><%= @supplier.supplier_name %></h1>
<h1 class="govuk-heading-xl govuk-!-margin-bottom-2"><%= @sublot_region_name %></h2>
<%= framework_expired_warning(t('facilities_management.rm3830.admin.you_cannot_update.regions')) %>
<p class="govuk-body govuk-!-font-weight-regular govuk-hint"><%= t('.leading_text') %></p>

<%= form_with url: facilities_management_rm3830_admin_supplier_framework_datum_sublot_region_path, method: 'put', local: 'false', html: { specialvalidation: true } do |f| %>
Expand All @@ -25,7 +26,8 @@
key2,
@selected_supplier_regions[key2],
class: "govuk-checkboxes__input",
id: "#{key2}"
id: "#{key2}",
disabled: @framework_has_expired
) %>
<label id="<%= key2 %>_label" class="govuk-label govuk-checkboxes__label" for="<%= key2 %>">
<%= value2 %>
Expand All @@ -39,6 +41,6 @@
</fieldset>
<% end %>
<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_supplier_regions', aria: { label: t('.update_button') }%>
<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_supplier_regions', aria: { label: t('.update_button') }, disabled: @framework_has_expired%>
<% end %>
<%= link_to t('.return_link'), facilities_management_rm3830_admin_supplier_framework_data_path, class: 'govuk-link govuk-caption-m' %>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<span class="govuk-caption-l"><%= @supplier.supplier_name %></span>
</div>
<h1 class="govuk-heading-xl"><%= @lot_name %></h1>
<%= framework_expired_warning(t('facilities_management.rm3830.admin.you_cannot_update.services')) %>
<p class="govuk-body govuk-!-font-weight-regular govuk-hint">
<%= t('.note') %>
</p>
Expand Down Expand Up @@ -35,7 +36,8 @@
work_pckg['code'],
@supplier_rate_data_checkboxes[work_pckg['code']],
class: "govuk-checkboxes__input",
id: "rates_#{work_pckg['code']}"
id: "rates_#{work_pckg['code']}",
disabled: @framework_has_expired
) %>
<label class="govuk-label govuk-checkboxes__label" for="rates_<%=work_pckg['code'] %>">

Expand All @@ -49,6 +51,6 @@
</table>
</fieldset>
<% end %>
<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_benchmark_rates', aria: { label: t('.update_button') }%>
<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_benchmark_rates', aria: { label: t('.update_button') }, disabled: @framework_has_expired %>
<%= link_to t('.return_button'), facilities_management_rm3830_admin_supplier_framework_data_path, class: 'govuk-link govuk-caption-m' %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
</div>
</div>
<h1 class="govuk-heading-xl"><%= t('.heading') %></h1>
<h2 class="govuk-heading-l govuk-!-font-weight-bold "><%= t('.services_and_prices') %></h1>
<h2 class="govuk-heading-l govuk-!-font-weight-bold "><%= t('.services_and_prices') %></h2>
<%= framework_expired_warning(t('facilities_management.rm3830.admin.you_cannot_update.services')) %>

<p class="govuk-body govuk-!-font-weight-regular govuk-hint">
<%= t('.note') %><br/>
Expand Down Expand Up @@ -61,7 +62,8 @@
@supplier_rate_data_checkboxes[work_pckg['code']],
class: "govuk-checkboxes__input",
id: "rates_#{work_pckg['code']}",
'aria-label': "#{work_pckg['name']} checkbox"
'aria-label': "#{work_pckg['name']} checkbox",
disabled: @framework_has_expired
) %>
<%= label_tag "rates_#{work_pckg['code']}", "#{work_pckg['code']} #{work_pckg['name']}", id: "#{work_pckg['code']}_label", class: 'govuk-label govuk-checkboxes__label' %>
Expand All @@ -78,7 +80,7 @@
<% input_value = determine_rate_card_service_price_text(service_type, work_pckg['code'], @supplier_data_ratecard_prices, @supplier_data_ratecard_discounts) %>
<% class_list = 'govuk-input govuk-input--width-3' %>
<% end %>
<%= text_field_tag "data[#{work_pckg['code']}][#{service_type}]", input_value, class: class_list, aria: { label: work_pckg['name'] } %>
<%= text_field_tag "data[#{work_pckg['code']}][#{service_type}]", input_value, class: class_list, aria: { label: work_pckg['name'] }, disabled: @framework_has_expired %>
</td>
<% end %>
</tr>
Expand Down Expand Up @@ -117,14 +119,14 @@
<% input_value = @variance_supplier_data[variance_values[i].to_sym] %>
<% class_list = 'govuk-input govuk-input--width-3' %>
<% end %>
<%= text_field_tag "rate[#{variance}]", input_value, class: class_list %>
<%= text_field_tag "rate[#{variance}]", input_value, class: class_list, disabled: @framework_has_expired %>
</td>
</tr>
<% end %>
</tbody>
</table>

<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_sublot_data_services_prices', aria: { label: 'update_sublot_data_services_prices' } %><br/>
<%= f.submit t('.update_button'), class: 'govuk-button', name: 'update_sublot_data_services_prices', aria: { label: 'update_sublot_data_services_prices' }, disabled: @framework_has_expired %><br/>
<%= link_to t('.return_link'), facilities_management_rm3830_admin_supplier_framework_data_path, class: 'govuk-link govuk-!-font-size-19' %>
<% end %>
</div>
5 changes: 5 additions & 0 deletions config/locales/views/facilities_management.rm3830.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ en:
supplier_framework_data: Supplier framework data
upload:
upload_name: 'Upload session #%{number}'
you_cannot_update:
details: The RM3830 has expired, you cannot update the supplier's details.
rates: The RM3830 has expired, you cannot update these rates.
regions: The RM3830 has expired, you cannot update the supplier's regions.
services: The RM3830 has expired, you cannot update the supplier's services.
buyer_account:
index:
buyer_account_dashboard: Buyer account dashboard
Expand Down
2 changes: 2 additions & 0 deletions config/locales/views/facilities_management.rm6232.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ en:
uploaded_by: 'Uploaded by:'
upload:
upload_name: 'Upload session #%{number}'
you_cannot_update:
details: The RM6232 has expired, you cannot update the supplier's details.
buyer_account:
index:
buyer_account_dashboard: Buyer account dashboard
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Service rates - Framework expired

Scenario Outline: The framework rates page inputs are disabled
Given the 'RM3830' framework has expired
And I sign in as an admin and navigate to the 'RM3830' dashboard
And I click on '<rates_page>'
Then I am on the '<rates_page>' page
And I should see the following warning text:
| The RM3830 has expired, you cannot update these rates. |
And all the text inputs are disabled
And the submit button is disabled

Examples:
| rates_page |
| Average framework rates |
| Call-off benchmark rates |
Loading

0 comments on commit f336d8a

Please sign in to comment.