Skip to content

Commit

Permalink
Return success when disabling a disabled record via REST 2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cbrandtbuffalo committed Aug 30, 2023
1 parent 2170daf commit 8be2f5c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/RT/REST2/Resource/Record/DeletableByDisabling.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8be2f5c

Please sign in to comment.