[Rt-commit] rt branch 5.0/rest2-delete-queue created. rt-5.0.4-137-g8be2f5c158

BPS Git Server git at git.bestpractical.com
Wed Aug 30 20:13:48 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/rest2-delete-queue has been created
        at  8be2f5c158331b8714fabbcce893301df0099006 (commit)

- Log -----------------------------------------------------------------
commit 8be2f5c158331b8714fabbcce893301df0099006
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Aug 30 15:53:09 2023 -0400

    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

diff --git a/lib/RT/REST2/Resource/Record/DeletableByDisabling.pm b/lib/RT/REST2/Resource/Record/DeletableByDisabling.pm
index 8a82b9171d..748ccf5963 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;
 }
 

commit 2170dafe7a36ca380520c9140008c27ceb4857d0
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Aug 30 15:52:48 2023 -0400

    Add test for deleting a disabled queue via REST 2

diff --git a/t/rest2/queues.t b/t/rest2/queues.t
index 25c2b06df9..77e0c554ff 100644
--- a/t/rest2/queues.t
+++ b/t/rest2/queues.t
@@ -192,6 +192,12 @@ my $queue_url;
     my $content = $mech->json_response;
     is($content->{Name}, 'Bugs');
     is($content->{Disabled}, 1);
+
+    diag 'Try to call delete on a disabled queue';
+    $res = $mech->delete($queue_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 204);
 }
 
 # Queue create

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list