-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ceased or revoked - start form (#624)
# Ceased or revoked - start form From: https://eaflood.atlassian.net/browse/RUBY-807 This adds all the code that will deal with the start of the journey for the ceased and revoked form.
- Loading branch information
Showing
14 changed files
with
402 additions
and
6 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/controllers/waste_carriers_engine/cease_or_revoke_forms_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module WasteCarriersEngine | ||
class CeaseOrRevokeFormsController < FormsController | ||
def new | ||
super(CeaseOrRevokeForm, "cease_or_revoke_form") | ||
end | ||
|
||
def create | ||
super(CeaseOrRevokeForm, "cease_or_revoke_form") | ||
end | ||
|
||
private | ||
|
||
def transient_registration_attributes | ||
params.fetch(:cease_or_revoke_form).permit(metaData: %i[status revoked_reason]) | ||
end | ||
|
||
# rubocop:disable Naming/MemoizedInstanceVariableName | ||
def find_or_initialize_transient_registration(token) | ||
@transient_registration ||= CeasedOrRevokedRegistration.where(reg_identifier: token).first || | ||
CeasedOrRevokedRegistration.where(token: token).first || | ||
CeasedOrRevokedRegistration.new(reg_identifier: token) | ||
end | ||
# rubocop:enable Naming/MemoizedInstanceVariableName | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module WasteCarriersEngine | ||
class CeaseOrRevokeForm < BaseForm | ||
def self.can_navigate_flexibly? | ||
false | ||
end | ||
|
||
delegate :metaData, to: :transient_registration | ||
delegate :status, :revoked_reason, to: :metaData, allow_nil: true | ||
delegate :contact_address, :company_name, :registration_type, :tier, to: :transient_registration | ||
|
||
validate :validate_status | ||
validate :validate_revoked_reason | ||
|
||
private | ||
|
||
def validate_status | ||
return true if %w[INACTIVE REVOKED].include?(status) | ||
|
||
errors.add(:status, :presence) | ||
|
||
false | ||
end | ||
|
||
def validate_revoked_reason | ||
if revoked_reason.blank? | ||
errors.add(:revoked_reason, :presence) | ||
|
||
false | ||
elsif revoked_reason.size > 500 | ||
errors.add(:revoked_reason, :length) | ||
|
||
false | ||
end | ||
|
||
true | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
app/forms/waste_carriers_engine/ceased_or_revoked_confirm_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module WasteCarriersEngine | ||
class CeasedOrRevokedConfirmForm < BaseForm | ||
# TODO | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ervices/waste_carriers_engine/ceased_or_revoked_registration_permission_checks_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module WasteCarriersEngine | ||
class CeasedOrRevokedRegistrationPermissionChecksService < BaseRegistrationPermissionChecksService | ||
|
||
private | ||
|
||
def all_checks_pass? | ||
transient_registration_is_valid? && user_has_permission? && registation_is_active? | ||
end | ||
|
||
def user_has_permission? | ||
return true if can?(:revoke, registration) && can?(:cease, registration) | ||
|
||
permission_check_result.needs_permissions! | ||
|
||
false | ||
end | ||
|
||
def registation_is_active? | ||
return true if registration.active? | ||
|
||
permission_check_result.invalid! | ||
|
||
false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/views/waste_carriers_engine/cease_or_revoke_forms/new.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<%= render("waste_carriers_engine/shared/back", back_path: Rails.application.routes.url_helpers.registration_path(@transient_registration.reg_identifier)) %> | ||
|
||
<div class="text"> | ||
<%= form_for(@cease_or_revoke_form) do |f| %> | ||
<%= f.fields_for :metaData do |f| %> | ||
<%= render("waste_carriers_engine/shared/errors", object: @cease_or_revoke_form) %> | ||
|
||
<h1 class="heading-large"><%= t(".heading", reg_identifier: @transient_registration.reg_identifier) %></h1> | ||
|
||
<div class="panel wcr-panel wcr-panel-border-all"> | ||
<h2 class="heading-medium"><%= @cease_or_revoke_form.company_name %></h2> | ||
|
||
<p class="lede"> | ||
<%= t(".tier.#{@cease_or_revoke_form.tier.downcase}") %> - | ||
<%= t(".registration_type.#{@cease_or_revoke_form.registration_type}") %> | ||
</p> | ||
<p> | ||
<%= displayable_address(@cease_or_revoke_form.contact_address).join(", ") %> | ||
</p> | ||
</div> | ||
|
||
<div class="form-group <%= "form-group-error" if @cease_or_revoke_form.errors[:status].any? %>"> | ||
<fieldset> | ||
<legend> | ||
<p> | ||
<%= t(".cease_or_revoke.legend") %> | ||
</p> | ||
</legend> | ||
|
||
<% if @cease_or_revoke_form.errors[:status].any? %> | ||
<span class="error-message"><%= @cease_or_revoke_form.errors[:status].join(", ") %></span> | ||
<% end %> | ||
|
||
<div class="multiple-choice"> | ||
<%= f.radio_button :status, "REVOKED", checked: @transient_registration.metaData&.status == "REVOKED" %> | ||
<%= f.label :status, t(".cease_or_revoke.options.revoke"), value: "REVOKED" %> | ||
</div> | ||
|
||
<div class="multiple-choice"> | ||
<%= f.radio_button :status, "INACTIVE", checked: @transient_registration.metaData&.status == "INACTIVE" %> | ||
<%= f.label :status, t(".cease_or_revoke.options.cease"), value: "INACTIVE" %> | ||
</div> | ||
</fieldset> | ||
</div> | ||
|
||
<div class="form-group <%= "form-group-error" if @cease_or_revoke_form.errors[:revoked_reason].any? %>"> | ||
<fieldset> | ||
<% if @cease_or_revoke_form.errors[:revoked_reason].any? %> | ||
<span class="error-message"><%= @cease_or_revoke_form.errors[:revoked_reason].join(", ") %></span> | ||
<% end %> | ||
<%= f.label :revoked_reason, t(".cease_or_revoke.reason"), class: "form-label" %> | ||
<%= f.text_area :revoked_reason, class: "form-control form-control-3-4", rows: 5, value: @transient_registration.metaData&.revoked_reason %> | ||
</fieldset> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.submit t(".next_button"), class: "button" %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
en: | ||
waste_carriers_engine: | ||
cease_or_revoke_forms: | ||
new: | ||
heading: "Revoke or cease registration %{reg_identifier}" | ||
tier: | ||
upper: "Upper tier" | ||
lower: "Lower tier" | ||
registration_type: | ||
carrier_dealer: "Carrier and dealer" | ||
broker_dealer: "Broker and dealer" | ||
carrier_broker_dealer: "Carrier, broker and dealer" | ||
reason: | ||
label: "Reason" | ||
help_text: "Maximum 500 characters" | ||
cease_or_revoke: | ||
legend: "What do you want to do?" | ||
options: | ||
revoke: "Revoke" | ||
cease: "Cease" | ||
reason: "Reason" | ||
contact_address: | ||
heading: "Contact address:" | ||
next_button: "Confirm" | ||
activemodel: | ||
errors: | ||
models: | ||
waste_carriers_engine/cease_or_revoke_form: | ||
attributes: | ||
status: | ||
presence: "Select revoke or cease" | ||
revoked_reason: | ||
presence: "Enter a reason" | ||
length: "Reason must be 500 characters or fewer" |
10 changes: 10 additions & 0 deletions
10
config/locales/models/ceased_or_revoked_registrations/en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
en: | ||
activemodel: | ||
errors: | ||
models: | ||
waste_carriers_engine/ceased_or_revoked_registration: | ||
attributes: | ||
reg_identifier: | ||
invalid_format: "The registration ID is not in a valid format" | ||
no_registration: "There is no registration matching this ID" | ||
renewal_in_progress: "This renewal is already in progress" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.