[Rt-commit] rt branch 5.0/validator-remove-invalid-subscriptions created. rt-5.0.5-120-g8a44a6099d

BPS Git Server git at git.bestpractical.com
Fri Jan 19 21:04:01 UTC 2024


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/validator-remove-invalid-subscriptions has been created
        at  8a44a6099d953dfabfe6376049d1171c3a6343e3 (commit)

- Log -----------------------------------------------------------------
commit 8a44a6099d953dfabfe6376049d1171c3a6343e3
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Fri Jan 19 16:03:29 2024 -0500

    Remove subscriptions for deleted dashboards w/rt-validator
    
    Serializing initialdata to JSON will fail when trying to serialize a
    dashboard subscription for a dashboard that no longer exists (i.e.,
    deleted). The dashboard ID ends up as a scalar reference that JSON can't
    encode. This allows rt-validator to find and remove these subscriptions
    when they're present.

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index 87a4c3da1a..10497484a7 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -1321,6 +1321,34 @@ push @CHECKS, 'Links: missing object' => sub {
     return $res;
 };
 
+push @CHECKS, 'Subscriptions with deleted dashboards' => sub {
+    my $res   = 1;
+    my $table = 'Attributes';
+    my $sth   = execute_query( "SELECT id FROM $table WHERE ObjectType = ? AND Name = ?",
+        'RT::User', 'Subscription' );
+
+    my @subs_to_delete;
+    while ( my ( $id ) = $sth->fetchrow_array ) {
+        $res = 0;
+
+        my $attr = RT::Attribute->new( RT->SystemUser );
+        my ( $ok, $msg ) = $attr->Load( $id );
+        next unless $ok;
+
+        my $content = $attr->Content;
+        if( $content->{ DashboardId } =~ /(\d+)$/ ) {
+            my $dashboard_id = $1;
+            my $dash = RT::Dashboard->new( RT->SystemUser );
+            ( $ok, $msg ) = $dash->LoadById( $dashboard_id );
+            next if $ok || $msg eq "Permission Denied"
+        }
+        print STDERR "Subscription $id is for a deleted dashboard.\n";
+        next unless prompt( 'Delete', 'Subscriptions should only be for existing dashboards.' );
+        print "Deleting subscription $id from $table.\n" if $opt{'verbose'};
+        delete_record( $table, $id );
+    }
+    return $res;
+};
 
 my %CHECKS = @CHECKS;
 

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list