- my $session = FS::TicketSystem->session;
- my $CurrentUser = $session->{CurrentUser};
- $UnrepliedTickets = RT::Tickets->new($CurrentUser);
- my $search = $class->new(TicketsObj => $UnrepliedTickets);
- $search->Prepare;
+ my $session = eval { FS::TicketSystem->session; };
+ if ( $session ) {
+ my $CurrentUser = $session->{CurrentUser};
+ # if there are no tickets the current user could see, always hide it
+ my $AnyTickets = RT::Tickets->new($CurrentUser);
+ foreach my $status (qw(resolved rejected deleted)) {
+ $AnyTickets->RT::SearchBuilder::Limit(
+ FIELD => 'Status',
+ OPERATOR => '!=',
+ ENTRYAGGREGATOR => 'AND',
+ VALUE => $status,
+ );
+ }
+ $enabled = 0 if $AnyTickets->Count == 0;
+
+ $UnrepliedTickets = RT::Tickets->new($CurrentUser);
+ my $search = $class->new(TicketsObj => $UnrepliedTickets);
+ $search->Prepare;
+ } else {
+ $enabled = 0;
+ }