From c7dc5d1ef23808e1913bcc32c774d97619ed43cd Mon Sep 17 00:00:00 2001 From: Louis Kirkham Date: Thu, 30 Nov 2023 13:45:21 +0000 Subject: [PATCH 1/3] Allow admins to edit letters of support https://app.asana.com/0/1199154381249427/1203411987771110/f Remove deadline condition for removing letters of support --- app/views/qae_form/_supporter_fields.html.slim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index da075390c..abca4341b 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -49,5 +49,4 @@ li.js-add-example class="#{'read-only js-support-letter-received' if persisted}" - else - url = "#" - - if submission_deadline.trigger_at >= Time.zone.now - = link_to "Remove", url, class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link", data: { url: url }, 'aria-label' => "Delete support letter from #{supporter["first_name"]} #{supporter["last_name"]}" + = link_to "Remove", url, class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link", data: { url: url }, 'aria-label' => "Delete support letter from #{supporter["first_name"]} #{supporter["last_name"]}" From 8cdb79d6ba8e38d24d0d4338896f67f6d2b0f64f Mon Sep 17 00:00:00 2001 From: Louis Kirkham Date: Thu, 30 Nov 2023 18:33:30 +0000 Subject: [PATCH 2/3] Add support letter policy for removal https://app.asana.com/0/1199154381249427/1203411987771110/f Adds can_remove? policy for letters of support --- app/policies/support_letter_policy.rb | 4 ++++ app/views/qae_form/_supporter_fields.html.slim | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/policies/support_letter_policy.rb b/app/policies/support_letter_policy.rb index 5d14ec5a0..f3ccc3004 100644 --- a/app/policies/support_letter_policy.rb +++ b/app/policies/support_letter_policy.rb @@ -4,4 +4,8 @@ class SupportLetterPolicy < ApplicationPolicy def show? true end + + def can_remove? + admin? + end end diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index abca4341b..39c94654a 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -48,5 +48,5 @@ li.js-add-example class="#{'read-only js-support-letter-received' if persisted}" - url = users_form_answer_support_letter_path(form_answer_id: @form_answer.id, id: supporter["support_letter_id"]) - else - url = "#" - - = link_to "Remove", url, class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link", data: { url: url }, 'aria-label' => "Delete support letter from #{supporter["first_name"]} #{supporter["last_name"]}" + = if current_user || policy(:support_letter).can_remove? + = link_to "Remove", url, class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link", data: { url: url }, 'aria-label' => "Delete support letter from #{supporter["first_name"]} #{supporter["last_name"]}" From 06f9dc1a1325ac9c765d32e6f2d2a775e3d68c42 Mon Sep 17 00:00:00 2001 From: Louis Kirkham Date: Sun, 3 Dec 2023 13:34:41 +0000 Subject: [PATCH 3/3] Fix typo causing duplicate support letters --- app/views/qae_form/_supporter_fields.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index 39c94654a..658c73940 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -48,5 +48,5 @@ li.js-add-example class="#{'read-only js-support-letter-received' if persisted}" - url = users_form_answer_support_letter_path(form_answer_id: @form_answer.id, id: supporter["support_letter_id"]) - else - url = "#" - = if current_user || policy(:support_letter).can_remove? + - if current_user || policy(:support_letter).can_remove? = link_to "Remove", url, class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link", data: { url: url }, 'aria-label' => "Delete support letter from #{supporter["first_name"]} #{supporter["last_name"]}"