From 8be2f5c158331b8714fabbcce893301df0099006 Mon Sep 17 00:00:00 2001 From: Jim Brandt Date: Wed, 30 Aug 2023 15:53:09 -0400 Subject: [PATCH] Return success when disabling a disabled record via REST 2 RT's internal API returns "false" when you update a record to the value it already has. This false return caused a REST 2 DELETE (which is 'disable' on most records) to return failure (500) if you disabled an already-disabled queue. Detect the "already the current value" message and return true since the end result, the record being disabled, is true. Fixes: I#37591 --- lib/RT/REST2/Resource/Record/DeletableByDisabling.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/RT/REST2/Resource/Record/DeletableByDisabling.pm b/lib/RT/REST2/Resource/Record/DeletableByDisabling.pm index 8a82b9171d7..748ccf5963f 100644 --- a/lib/RT/REST2/Resource/Record/DeletableByDisabling.pm +++ b/lib/RT/REST2/Resource/Record/DeletableByDisabling.pm @@ -58,8 +58,16 @@ with 'RT::REST2::Resource::Record::Deletable'; sub delete_resource { my $self = shift; my ($ok, $msg) = $self->record->SetDisabled(1); - RT->Logger->debug("Failed to disable ", $self->record_class, " #", $self->record->id, ": $msg") - unless $ok; + + if ( not $ok && $msg =~ /That is already the current value/ ) { + # Don't return failure if the resource is already disabled since + # the final state is correct, the resource is disabled. + $ok = 1; + } + else { + RT->Logger->debug("Failed to disable ", $self->record_class, " #", $self->record->id, ": $msg"); + } + return $ok; }