Skip to content
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

[Open311] Check for identical latest update. #4007

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Permit control over database connection `sslmode` via $FMS_DB_SSLMODE
- Open311 improvements:
- Increase default timeout.
- Check for an identical latest update when adding a new one.

* v4.0 (3rd December 2021)
- Front end improvements:
Expand Down
13 changes: 0 additions & 13 deletions perllib/FixMyStreet/Cobrand/Merton.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ sub open311_extra_data_include {
return [];
}

sub open311_get_update_munging {
my ($self, $comment) = @_;

my $latest = $comment->problem->comments->search({ state => 'confirmed' }, {
order_by => [ { -desc => 'confirmed' }, { -desc => 'id' } ],
rows => 1,
})->first;
# If last update has same text and is the system user, hide it
if ($latest && $latest->text eq $comment->text && $latest->user_id == $comment->user_id) {
$comment->state('hidden');
}
}

sub report_new_munge_before_insert {
my ($self, $report) = @_;

Expand Down
9 changes: 9 additions & 0 deletions perllib/Open311/UpdatesBase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ sub process_update {
$comment->state('hidden') unless $comment->text || $comment->photo
|| ($comment->problem_state && $state ne $old_state);

# Hide if the new comment is the same as the latest comment
my $latest = $comment->problem->comments->search({ state => 'confirmed' }, {
order_by => [ { -desc => 'confirmed' }, { -desc => 'id' } ],
rows => 1,
})->first;
if ($latest && $latest->text eq $comment->text && $latest->user_id == $comment->user_id && $latest->problem_state eq $comment->problem_state) {
$comment->state('hidden');
}

my $cobrand = $body->get_cobrand_handler;
$cobrand->call_hook(open311_get_update_munging => $comment)
if $cobrand;
Expand Down
53 changes: 53 additions & 0 deletions t/open311/getservicerequestupdates.t
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,59 @@ subtest 'check that existing comments are not duplicated' => sub {
is $problem->comments->count, 2, 'if comments are deleted then they are added';
};

subtest "hides duplicate updates from endpoint" => sub {
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>
<request_update>
<update_id>UPDATE_1</update_id>
<service_request_id>@{[ $problem->external_id ]}</service_request_id>
<status>IN_PROGRESS</status>
<description>This is a note</description>
<updated_datetime>UPDATED_DATETIME</updated_datetime>
</request_update>
</service_requests_updates>
};
my $requests_xml2 = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>
<request_update>
<update_id>UPDATE_2</update_id>
<service_request_id>@{[ $problem->external_id ]}</service_request_id>
<status>IN_PROGRESS</status>
<description>This is a note</description>
<updated_datetime>UPDATED_DATETIME</updated_datetime>
</request_update>
</service_requests_updates>
};

$problem->comments->delete;

my $update_dt = DateTime->now(formatter => DateTime::Format::W3CDTF->new);

$requests_xml =~ s/UPDATED_DATETIME/$update_dt/g;
$requests_xml2 =~ s/UPDATED_DATETIME/$update_dt/g;

my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com');

my $update = Open311::GetServiceRequestUpdates->new(
system_user => $user,
current_open311 => $o,
current_body => $bodies{2482},
);

Open311->_inject_response('/servicerequestupdates.xml', $requests_xml);
$update->process_body;
$problem->discard_changes;
is $problem->comments->count, 1;
is $problem->comments->search({ state => 'confirmed' })->count, 1;

Open311->_inject_response('/servicerequestupdates.xml', $requests_xml2);
$update->process_body;
$problem->discard_changes;
is $problem->comments->count, 2;
is $problem->comments->search({ state => 'confirmed' })->count, 1;

};

subtest 'check that can limit fetching to a body' => sub {
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>
Expand Down