Skip to content

[Dumfries] Handle Cancelled Job response templates for Open311 updates#6000

Draft
davea wants to merge 1 commit into
masterfrom
dumfries-cancelled-job-template-2
Draft

[Dumfries] Handle Cancelled Job response templates for Open311 updates#6000
davea wants to merge 1 commit into
masterfrom
dumfries-cancelled-job-template-2

Conversation

@davea

@davea davea commented May 29, 2026

Copy link
Copy Markdown
Member

For https://github.com/mysociety/societyworks/issues/5475

This adds a cobrand hook which allows a specific response template to be chosen according to the problem's old/new status. For Dumfries that hook looks for a response template whose title begins 'Cancelled Job' and uses that when a problem state goes from 'planned' to 'confirmed'. Also adds validation for these response templates when edited via the admin - can't be marked as auto response, can't have an external status, must be for 'confirmed' state.

(alternative approach to #5968)

[skip changelog]

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.41%. Comparing base (47e7ca7) to head (edd997c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6000      +/-   ##
==========================================
- Coverage   83.43%   83.41%   -0.02%     
==========================================
  Files         500      500              
  Lines       37304    37324      +20     
  Branches     6162     6171       +9     
==========================================
+ Hits        31124    31135      +11     
- Misses       4370     4377       +7     
- Partials     1810     1812       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


Performs some custom validation for templates whose title start with 'Cancelled Job':
can't be auto-response; can't be for an external status code; must be for 'confirmed' state.
=cut

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would look better to move one of the empty lines down to be just above =cut.

my $errors = $body_cobrand->call_hook(validate_response_template => $template);
if ($errors && ref $errors eq 'HASH') {
$c->stash->{errors} ||= {};
%{ $c->stash->{errors} } = (%{ $c->stash->{errors} }, %$errors);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this would read better as something like
$c->stash->{errors}{$_} = $errors->{$_} for keys %$errors;

Comment thread t/cobrand/dumfries.t
title => 'Cancelled Job - Planned to Confirmed',
text => 'Cancelled job template text',
auto_response => 0,
state => '',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the template have either state or external_status_code?

Comment thread t/cobrand/dumfries.t

is $mech->uri->path, '/admin/templates/' . $body->id . '/new',
'Not redirected when reserved template is set as auto-response';
$mech->content_contains('reserved for the cancelled job feature',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to specifically test for the 'cannot be set as auto-response' bit.


if (($template->state || '') ne 'confirmed') {
$errors{state} =
'Templates whose title starts with "Cancelled Job" are reserved for cancelled job handling and must use the Open state.';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could put the initial part of the error message into a shared variable, as it is used by all the error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants