Skip to content

Commit

Permalink
Remove subscriptions for deleted dashboards w/rt-validator
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jason Crome committed Jan 19, 2024
1 parent b4de1a9 commit 8a44a60
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sbin/rt-validator.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8a44a60

Please sign in to comment.