-
Notifications
You must be signed in to change notification settings - Fork 2
[271] Merge new emails into existing case #853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
066cbc9
add case autocomplete search
d-a-v-e 2c6db39
adds preview page and merge emails service
d-a-v-e 26da96c
adds preview page and merge emails service
d-a-v-e b9e6146
success view
d-a-v-e 14f72ae
specs
d-a-v-e 7e2f5d6
specs - fixes
d-a-v-e dd42932
revert capybara settings
d-a-v-e 529784f
rubocop
d-a-v-e 329a484
tweaks
d-a-v-e 941b472
merge develop => feature/271
d-a-v-e 3b501b0
spec fixes
d-a-v-e 1a29e1d
more specs
d-a-v-e 5c22cf2
fix session bug
d-a-v-e 7f7e64a
codeclimate
d-a-v-e 56672eb
revert changes to app/controllers/support/cases_controller.rb
d-a-v-e f7d9d5a
update changelog
d-a-v-e 4cb0730
correct error expectation message in spec
d-a-v-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| module Support | ||
| class Cases::MergeEmailsController < Cases::ApplicationController | ||
| before_action :from_case | ||
| before_action :to_case, except: %i[new] | ||
| before_action :stage, only: %i[create] | ||
|
|
||
| def new | ||
| clear_session | ||
| @back_url = support_cases_url | ||
| @stage = :search | ||
| @merge_emails_form = CaseMergeEmailsForm.new | ||
| end | ||
|
|
||
| def create | ||
| @merge_emails_form = CaseMergeEmailsForm.from_validation(validation) | ||
|
|
||
| case stage | ||
|
|
||
| when :search | ||
| @back_url = support_cases_url | ||
|
|
||
| when :preview | ||
| @back_url = new_support_case_merge_emails_path | ||
|
|
||
| when :merge | ||
| MergeCaseEmails.new( | ||
| from_case: from_case.__getobj__, | ||
| to_case: to_case.__getobj__, | ||
| ).call | ||
| return redirect_to support_case_merge_emails_path(from_case) | ||
| end | ||
|
|
||
| render :new | ||
| rescue MergeCaseEmails::CaseNotNewError | ||
| clear_session | ||
| redirect_to support_case_path(@current_case), notice: I18n.t("support.case_merge_emails.flash.case_not_new") | ||
| end | ||
|
|
||
| def show; end | ||
|
|
||
| private | ||
|
|
||
| def stage | ||
| @stage ||= if validation&.success? && merge_emails_params[:confirmation] | ||
| :merge | ||
| elsif validation&.success? | ||
| :preview | ||
| else | ||
| :search | ||
| end | ||
| end | ||
|
|
||
| def from_case | ||
| @from_case ||= CasePresenter.new(current_case) | ||
| end | ||
|
|
||
| def to_case | ||
| @to_case ||= CasePresenter.new( | ||
| Case.find_by(ref: to_case_ref), | ||
| ) | ||
| end | ||
|
|
||
| def to_case_ref | ||
| if params[:merge_emails_form] && merge_emails_params[:merge_into_case_ref].present? | ||
| session[:merge_into_case_ref] = merge_emails_params[:merge_into_case_ref] | ||
| else | ||
| session[:merge_into_case_ref] | ||
| end | ||
| end | ||
|
|
||
| def clear_session | ||
| session.delete(:merge_into_case_ref) | ||
| end | ||
|
|
||
| def validation | ||
| @validation ||= CaseMergeEmailsFormSchema.new.call(**merge_emails_params, merge_from_case_ref: from_case.ref) | ||
| end | ||
|
|
||
| def merge_emails_params | ||
| params.require(:merge_emails_form).permit(:merge_into_case_ref, :confirmation) | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,13 @@ | ||
| module Support | ||
| class CaseMergeEmailsForm | ||
| extend Dry::Initializer | ||
| include Concerns::ValidatableForm | ||
|
|
||
| # @!attribute [r] merge_into_case_ref | ||
| # @return [String, nil] | ||
| option :merge_into_case_ref, Types::Params::String, optional: true | ||
| # @!attribute [r] merge_from_case_ref | ||
| # @return [String, nil] | ||
| option :merge_from_case_ref, Types::Params::String, optional: true | ||
| end | ||
| end |
This file contains hidden or 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,20 @@ | ||
| module Support | ||
| class CaseMergeEmailsFormSchema < Dry::Validation::Contract | ||
| include Concerns::TranslatableFormSchema | ||
|
|
||
| params do | ||
| required(:merge_into_case_ref).value(:string) | ||
| required(:merge_from_case_ref).value(:string) | ||
| end | ||
|
|
||
| rule(:merge_into_case_ref) do | ||
| key.failure(:missing) unless Case.find_by(ref: value) | ||
| end | ||
|
|
||
| rule do | ||
| if values[:merge_into_case_ref] == values[:merge_from_case_ref] | ||
| base.failure("You cannot merge into the same case") | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,39 @@ | ||
| require "dry-initializer" | ||
|
|
||
| module Support | ||
| # | ||
| # Merge a new support cases emails into an existing support case | ||
| # | ||
| # TODO: | ||
| # 1. If adding any further merging functionality to this class, consider adding a merged_into_case_id | ||
| # to t.support_cases to keep a record of the case a case was merged into. | ||
| # | ||
| # 2. The inverse should also be applied to t.support_emails and t.support_interactions to keep a record of their | ||
| # original case (e.g. original_case_id). | ||
| # | ||
| class MergeCaseEmails | ||
| class CaseNotNewError < StandardError; end | ||
|
|
||
| extend Dry::Initializer | ||
|
|
||
| # @!attribute from_case | ||
| # @return [Support::Case] | ||
| option :from_case, Types.Instance(Support::Case), optional: false | ||
|
|
||
| # @!attribute to_case | ||
| # @return [Support::Case] | ||
| option :to_case, Types.Instance(Support::Case), optional: false | ||
|
|
||
| # @return [TrueClass] | ||
| def call | ||
| from_case.transaction do | ||
| raise CaseNotNewError unless from_case.initial? | ||
|
|
||
| from_case.interactions&.update_all(case_id: to_case.id) | ||
| from_case.emails&.update_all(case_id: to_case.id) | ||
| from_case.closed! | ||
| end | ||
| to_case.pending! | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,13 @@ | ||
| json.array! @cases do |kase| | ||
| # case | ||
| json.id kase.id | ||
| json.ref kase.ref | ||
|
|
||
| # agent | ||
| json.agent_name "#{kase.agent&.first_name} #{kase.agent&.last_name}" | ||
|
|
||
| # organisation | ||
| json.organisation_name kase.organisation&.name | ||
| json.organisation_urn kase.organisation&.urn | ||
| json.organisation_ukprn kase.organisation&.ukprn | ||
| end |
This file contains hidden or 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,56 @@ | ||
| <%= form.hidden_field :confirmation, value: true %> | ||
| <%= form.hidden_field :merge_into_case_ref, value: @to_case.ref %> | ||
|
|
||
| <h1 class="govuk-heading-l"> | ||
| <%= I18n.t("support.case_merge_emails.preview.header") %> | ||
| </h1> | ||
|
|
||
| <!-- FROM CASE --> | ||
|
|
||
| <table class="govuk-table"> | ||
| <caption class="govuk-table__caption govuk-table__caption--m"><%= I18n.t("support.case_merge_emails.preview.from") %></caption> | ||
| <thead class="govuk-table__head"> | ||
| <tr class="govuk-table__row"> | ||
| <% I18n.t("support.case_merge_emails.preview.table").each do |header| %> | ||
| <th scope="col" class="govuk-table__header"> <%= header %> </th> | ||
| <% end %> | ||
| </tr> | ||
| </thead> | ||
| <tbody class="govuk-table__body"> | ||
| <tr class="govuk-table__row" id="merge_emails_from"> | ||
| <td class="govuk-table__cell"> <%= @from_case.ref %> </td> | ||
| <td class="govuk-table__cell"> <%= @from_case.org_name %> </td> | ||
| <td class="govuk-table__cell"> <%= @from_case.category&.title %> </td> | ||
| <td class="govuk-table__cell"> <%= @from_case.state %> </td> | ||
| <td class="govuk-table__cell"> <%= @from_case.agent&.full_name %> </td> | ||
| <td class="govuk-table__cell"> <%= @from_case.created_at %> </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| <!-- TO CASE --> | ||
|
|
||
| <table class="govuk-table"> | ||
| <caption class="govuk-table__caption govuk-table__caption--m"><%= I18n.t("support.case_merge_emails.preview.to") %></caption> | ||
| <thead class="govuk-table__head"> | ||
| <tr class="govuk-table__row"> | ||
| <% I18n.t("support.case_merge_emails.preview.table").each do |header| %> | ||
| <th scope="col" class="govuk-table__header"> <%= header %> </th> | ||
| <% end %> | ||
| </tr> | ||
| </thead> | ||
| <tbody class="govuk-table__body"> | ||
| <tr class="govuk-table__row" id="merge_emails_to"> | ||
| <td class="govuk-table__cell"> <%= @to_case.ref %> </td> | ||
| <td class="govuk-table__cell"> <%= @to_case.org_name %> </td> | ||
| <td class="govuk-table__cell"> <%= @to_case.category&.title %> </td> | ||
| <td class="govuk-table__cell"> <%= @to_case.state %> </td> | ||
| <td class="govuk-table__cell"> <%= @to_case.agent&.full_name %> </td> | ||
| <td class="govuk-table__cell"> <%= @to_case.created_at %> </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| <p class="govuk-body-m"> | ||
| <%= I18n.t("support.case_merge_emails.preview.reminder", case_ref: @from_case.ref) %> | ||
| </p> |
This file contains hidden or 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,17 @@ | ||
| <h1 class="govuk-heading-l"> <%= I18n.t("support.case_merge_emails.search.header") %> </h1> | ||
|
|
||
| <p class="govuk-body-m"> <%= I18n.t("support.case_merge_emails.search.subtitle") %> </p> | ||
|
|
||
| <span class="govuk-caption-m"> <%= I18n.t("support.case_merge_emails.search.hint") %> </span> | ||
|
|
||
| <%= | ||
| render "components/autocomplete", | ||
| container_id: "case-autocomplete-container", | ||
| label_class: "nil", | ||
| label_text: nil, | ||
| element_id: "case-autocomplete", | ||
| element_name: "merge_emails_form[merge_into_case_ref]", | ||
| template_suggestion: "{{ref}}, <strong>{{organisation_name}}</strong>, {{organisation_urn}}/{{organisation_ukprn}}, {{agent_name}}", | ||
| value_field: :ref, | ||
| query_url: support_cases_path(format: :json, q: "{{QUERY}}") | ||
| %> |
This file contains hidden or 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,25 @@ | ||
| <%= form_with model: @merge_emails_form, | ||
| scope: :merge_emails_form, | ||
| url: support_case_merge_emails_path(case_id: @from_case.id), | ||
| method: :post do |form| | ||
| %> | ||
|
|
||
| <%= form.govuk_error_summary %> | ||
|
|
||
| <%# | ||
| # 1. Search | ||
| # 2. Preview | ||
| %> | ||
| <%= render "support/cases/merge_emails/#{@stage}", form: form %> | ||
|
|
||
| <ul class="govuk-list"> | ||
| <li class="govuk-!-display-inline"> | ||
| <%= form.submit I18n.t("support.generic.continue"), class: "govuk-button" %> | ||
| </li> | ||
| <% if @stage == :preview %> | ||
| <li class="govuk-!-display-inline-block govuk-!-padding-left-3 govuk-!-padding-top-1"> | ||
| <%= link_to I18n.t("support.generic.cancel"), new_support_case_merge_emails_path, class: "govuk-link" %> | ||
| </li> | ||
| <% end %> | ||
| </ul> | ||
| <% end %> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.