From 8523fbea5d9024e10d94fc08e7378ebfad863472 Mon Sep 17 00:00:00 2001 From: rasikasri <44141067+rasikasri@users.noreply.github.com> Date: Tue, 14 May 2024 10:12:34 +0100 Subject: [PATCH] GL-367: Add Admin UI screen to list the overrides (#705) GL-457: Add admin UI to create new overrides GL-367: Add Admin UI screen to list the overrides GL-458: Add admin UI to remove overrides (#706) --- ...mpting_certificate_overrides_controller.rb | 45 ++++++++++++ .../exempting_certificate_override.rb | 14 ++++ .../index.html.erb | 40 +++++++++++ .../new.html.erb | 16 +++++ app/views/layouts/application.html.erb | 5 +- config/routes.rb | 1 + .../exempting_certificate_override_factory.rb | 9 +++ .../exempting_certificate_override_spec.rb | 41 +++++++++++ ...g_certificate_overrides_controller_spec.rb | 70 +++++++++++++++++++ 9 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 app/controllers/green_lanes/exempting_certificate_overrides_controller.rb create mode 100644 app/models/green_lanes/exempting_certificate_override.rb create mode 100644 app/views/green_lanes/exempting_certificate_overrides/index.html.erb create mode 100644 app/views/green_lanes/exempting_certificate_overrides/new.html.erb create mode 100644 spec/factories/green_lanes/exempting_certificate_override_factory.rb create mode 100644 spec/models/green_lanes/exempting_certificate_override_spec.rb create mode 100644 spec/requests/green_lanes/exempting_certificate_overrides_controller_spec.rb diff --git a/app/controllers/green_lanes/exempting_certificate_overrides_controller.rb b/app/controllers/green_lanes/exempting_certificate_overrides_controller.rb new file mode 100644 index 00000000..65c134e7 --- /dev/null +++ b/app/controllers/green_lanes/exempting_certificate_overrides_controller.rb @@ -0,0 +1,45 @@ +module GreenLanes + class ExemptingCertificateOverridesController < AuthenticatedController + before_action :disable_service_switching! + before_action :check_service + def index + @exempting_certificate_overrides = GreenLanes::ExemptingCertificateOverride.all(page: current_page).fetch + end + + def new + @exempting_certificate_override = GreenLanes::ExemptingCertificateOverride.new + end + + def create + @exempting_certificate_override = GreenLanes::ExemptingCertificateOverride.new(eco_params) + + if @exempting_certificate_override.valid? && @exempting_certificate_override.save + redirect_to green_lanes_exempting_certificate_overrides_path, notice: 'Exempting Certificate Override created' + else + render :new + end + end + + def destroy + @exempting_certificate_override = GreenLanes::ExemptingCertificateOverride.find(params[:id]) + @exempting_certificate_override.destroy + + redirect_to green_lanes_exempting_certificate_overrides_path, notice: 'Exempting Certificate Override removed' + end + + private + + def eco_params + params.require(:exempting_certificate_override).permit( + :certificate_type_code, + :certificate_code, + ) + end + + def check_service + if TradeTariffAdmin::ServiceChooser.uk? + raise ActionController::RoutingError, 'Invalid service' + end + end + end +end diff --git a/app/models/green_lanes/exempting_certificate_override.rb b/app/models/green_lanes/exempting_certificate_override.rb new file mode 100644 index 00000000..a565ced0 --- /dev/null +++ b/app/models/green_lanes/exempting_certificate_override.rb @@ -0,0 +1,14 @@ +module GreenLanes + class ExemptingCertificateOverride + include Her::JsonApi::Model + use_api Her::XI_API + extend HerPaginatable + + attributes :certificate_type_code, + :certificate_code, + :created_at, + :updated_at + + collection_path '/admin/green_lanes/exempting_certificate_overrides' + end +end diff --git a/app/views/green_lanes/exempting_certificate_overrides/index.html.erb b/app/views/green_lanes/exempting_certificate_overrides/index.html.erb new file mode 100644 index 00000000..2e980684 --- /dev/null +++ b/app/views/green_lanes/exempting_certificate_overrides/index.html.erb @@ -0,0 +1,40 @@ +
ID | +Certificate Type Code | +Certificate Code | +Action | +
---|---|---|---|
<%= eco.id %> | +<%= eco.certificate_type_code %> | +<%= eco.certificate_code %> | ++ <%= link_to 'Remove', + green_lanes_exempting_certificate_override_path(eco), + method: :delete, + class: 'govuk-button govuk-button--warning', + data: { confirm: "Are you sure?", disable: 'Working ...' } %> + | +
No Exempting Certificate Override
+