diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index a6e2c08e5..e38d1bdf0 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -116,6 +116,7 @@ private def merge_request_params merge_params = params.fetch(:merge_request, {}).permit( :requesting_organisation_id, + :has_helpdesk_ticket, :helpdesk_ticket, :status, :absorbing_organisation_id, @@ -124,6 +125,7 @@ private ) merge_params[:requesting_organisation_id] = current_user.organisation.id + merge_params[:helpdesk_ticket] = nil if merge_params[:has_helpdesk_ticket] == "false" merge_params end @@ -151,6 +153,14 @@ private if merge_request_params[:existing_absorbing_organisation].nil? @merge_request.errors.add(:existing_absorbing_organisation, :blank) end + when "helpdesk_ticket" + @merge_request.has_helpdesk_ticket = merge_request_params[:has_helpdesk_ticket] + @merge_request.helpdesk_ticket = merge_request_params[:helpdesk_ticket] + if merge_request_params[:has_helpdesk_ticket].blank? + @merge_request.errors.add(:has_helpdesk_ticket, :blank) + elsif merge_request_params[:has_helpdesk_ticket] == "true" && merge_request_params[:helpdesk_ticket].blank? + @merge_request.errors.add(:helpdesk_ticket, :blank) + end end end diff --git a/app/helpers/merge_requests_helper.rb b/app/helpers/merge_requests_helper.rb index 28c693935..a8ed72120 100644 --- a/app/helpers/merge_requests_helper.rb +++ b/app/helpers/merge_requests_helper.rb @@ -9,7 +9,7 @@ module MergeRequestsHelper def request_details(merge_request) [ { label: "Requester", value: display_value_or_placeholder(merge_request.requester&.name) }, - { label: "Helpdesk ticket", value: merge_request.helpdesk_ticket.present? ? link_to("#{merge_request.helpdesk_ticket} (opens in a new tab)", "https://mhclgdigital.atlassian.net/browse/#{merge_request.helpdesk_ticket}", target: "_blank", rel: "noopener noreferrer") : display_value_or_placeholder(nil), action: merge_request_action(merge_request, "helpdesk_ticket") }, + { label: "Helpdesk ticket", value: helpdesk_ticket_value(merge_request), action: merge_request_action(merge_request, "helpdesk_ticket") }, { label: "Status", value: status_tag(merge_request.status) }, ] end @@ -280,4 +280,14 @@ module MergeRequestsHelper def begin_merge_disabled?(merge_request) merge_request.status != "ready_to_merge" || merge_request.merge_date.future? end + + def helpdesk_ticket_value(merge_request) + if merge_request.helpdesk_ticket.present? + link_to("#{merge_request.helpdesk_ticket} (opens in a new tab)", "https://mhclgdigital.atlassian.net/browse/#{merge_request.helpdesk_ticket}", target: "_blank", rel: "noopener noreferrer") + elsif merge_request.has_helpdesk_ticket == false + "Not reported by a helpdesk ticket" + else + display_value_or_placeholder(nil) + end + end end diff --git a/app/views/merge_requests/helpdesk_ticket.html.erb b/app/views/merge_requests/helpdesk_ticket.html.erb index 4ebd11395..9ebed7a90 100644 --- a/app/views/merge_requests/helpdesk_ticket.html.erb +++ b/app/views/merge_requests/helpdesk_ticket.html.erb @@ -7,14 +7,27 @@ <%= form_with model: @merge_request, url: submit_merge_request_url(request.query_parameters["referrer"]), method: :patch do |f| %> <%= f.govuk_error_summary %> -
If this merge was reported via a helpdesk ticket, provide the ticket number.
The ticket will be linked to the merge request for reference.