Skip to content

Commit 994767a

Browse files
Convert default RTIR homepage components to saved searches
Saved searches are convenient for admins because they can easily update the format and even the search itself in the web UI. RT 6 now allows saved searches to have properties, so searches can be identified as "RTIR searches". That property can then be used to enable constituencies features, which was the main reason these searches were coded as mason templates. These elements will now gain other features of saved searches in RT 6, like individual refresh.
1 parent dd29600 commit 994767a

7 files changed

Lines changed: 272 additions & 392 deletions

File tree

etc/RTIR_Config.pm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -560,20 +560,11 @@ Set(%RTIRSearchResultFormats,
560560
'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject',
561561
KeyRequestors,KeyOwnerName,CreatedRelative,DueRelative,QueueName},
562562

563-
DueIncidents =>
564-
q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#',}.
565-
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject',DueRelative,OwnerName,__Priority__,'UnreadMessages/TITLE:Updates'},
566-
567563
AbandonIncidents =>
568564
q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#',}.
569565
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject',}.
570566
q{OwnerName,Priority,DueRelative},
571567

572-
NewReports =>
573-
q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#',}.
574-
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject',}.
575-
q{Requestors,OwnerName,DueRelative,QueueName,Take},
576-
577568
ChildReport =>
578569
q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#',}.
579570
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject',}.
@@ -624,10 +615,6 @@ Set(@RTIR_HomepageComponents, qw(
624615
RefreshHomepage
625616
Dashboards
626617
SavedSearches
627-
/RTIR/Elements/NewReports
628-
/RTIR/Elements/UserDueIncidents
629-
/RTIR/Elements/NobodyDueIncidents
630-
/RTIR/Elements/DueIncidents
631618
/RTIR/Elements/QueueSummary
632619
/RTIR/Elements/WorkWithConstituency
633620
));

etc/initialdata

Lines changed: 133 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,66 @@ push @ACL, (
686686
},
687687
);
688688

689+
# Predefined searches
690+
691+
@SavedSearches = (
692+
{ Name => 'New unlinked Incident Reports',
693+
Description => 'New unlinked Incident Reports', # loc
694+
ExtraQueryParams => 'RTIR',
695+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#',}.
696+
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject',}.
697+
q{Requestors,OwnerName,DueRelative,QueueName,Take},
698+
Order => 'ASC|ASC|ASC|ASC',
699+
OrderBy => 'Due',
700+
Query => 'Lifecycle = \'incident_reports\' AND Status = \'new\'',
701+
RTIR => '1',
702+
RTIRSearchEnabled => 'Yes',
703+
RowsPerPage => '10'
704+
},
705+
{ Name => 'My most due incidents',
706+
Description => 'Most due incidents owned by [_1]', # loc
707+
ExtraQueryParams => 'RTIR',
708+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#\',}.
709+
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject\',}.
710+
q{DueRelative, OwnerName, __Priority__,}.
711+
q{'UnreadMessages/TITLE:Updates\''},
712+
Order => 'ASC|DESC|ASC|ASC',
713+
OrderBy => 'Due|Priority',
714+
Query => 'Lifecycle = \'incidents\' AND Status = \'__Active__\' AND Owner = \'__CurrentUser__\'',
715+
RTIR => '1',
716+
RTIRSearchEnabled => 'Yes',
717+
RowsPerPage => '10'
718+
},
719+
{ Name => 'Most due unowned incidents',
720+
Description => 'Most due unowned incidents', # loc
721+
ExtraQueryParams => 'RTIR',
722+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#\',}
723+
. q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject\',}
724+
. q{DueRelative, OwnerName, __Priority__,}
725+
. q{'UnreadMessages/TITLE:Updates\''},
726+
Order => 'ASC|DESC|ASC|ASC',
727+
OrderBy => 'Due|Priority',
728+
Query => 'Lifecycle = \'incidents\' AND Status = \'__Active__\' AND Owner = \'Nobody\'',
729+
RTIR => '1',
730+
RTIRSearchEnabled => 'Yes',
731+
RowsPerPage => '10'
732+
},
733+
{ Name => 'Most due incidents',
734+
Description => 'Most due incidents', # loc
735+
ExtraQueryParams => 'RTIR',
736+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#\',}.
737+
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject\',}.
738+
q{DueRelative, OwnerName, __Priority__,}.
739+
q{'UnreadMessages/TITLE:Updates\''},
740+
Order => 'ASC|DESC|ASC|ASC',
741+
OrderBy => 'Due|Priority',
742+
Query => 'Lifecycle = \'incidents\' AND Status = \'__Active__\'',
743+
RTIR => '1',
744+
RTIRSearchEnabled => 'Yes',
745+
RowsPerPage => '10'
746+
},
747+
);
748+
689749
for my $cf (@CustomFields) {
690750
push @ACL,
691751
(
@@ -786,63 +846,6 @@ for my $cf (@CustomFields) {
786846
}
787847
);
788848

789-
@Dashboards = (
790-
{
791-
Name => 'RTIR Homepage',
792-
Description => 'RTIR Homepage',
793-
Content => {
794-
Elements => [
795-
{
796-
Layout => 'col-md-8,col-md-4',
797-
Elements => [
798-
[
799-
{
800-
portlet_type => 'component',
801-
component => '/RTIR/Elements/NewReports',
802-
description => '/RTIR/Elements/NewReports',
803-
path => '/RTIR/Elements/NewReports',
804-
},
805-
{
806-
portlet_type => 'component',
807-
component => '/RTIR/Elements/UserDueIncidents',
808-
description => '/RTIR/Elements/UserDueIncidents',
809-
path => '/RTIR/Elements/UserDueIncidents',
810-
},
811-
{
812-
portlet_type => 'component',
813-
component => '/RTIR/Elements/NobodyDueIncidents',
814-
description => '/RTIR/Elements/NobodyDueIncidents',
815-
path => '/RTIR/Elements/NobodyDueIncidents',
816-
},
817-
{
818-
portlet_type => 'component',
819-
component => '/RTIR/Elements/DueIncidents',
820-
description => '/RTIR/Elements/DueIncidents',
821-
path => '/RTIR/Elements/DueIncidents',
822-
},
823-
],
824-
[
825-
{
826-
portlet_type => 'component',
827-
component => '/RTIR/Elements/WorkWithConstituency',
828-
description => '/RTIR/Elements/WorkWithConstituency',
829-
path => '/RTIR/Elements/WorkWithConstituency',
830-
},
831-
{
832-
portlet_type => 'component',
833-
component => '/RTIR/Elements/QueueSummary',
834-
description => '/RTIR/Elements/QueueSummary',
835-
path => '/RTIR/Elements/QueueSummary',
836-
},
837-
]
838-
],
839-
}
840-
],
841-
},
842-
}
843-
);
844-
845-
846849
@Final = (
847850
sub {
848851
$| = 1;
@@ -901,8 +904,80 @@ for my $cf (@CustomFields) {
901904

902905
},
903906
sub {
907+
# The last 4 saved searches should be the ones added above.
908+
# Don't load by name since there could be other existing searches with
909+
# these names.
910+
my ($new_reports, $user_incidents, $nobody_incidents, $due_incidents);
911+
my $saved_searches = RT::SavedSearches->new(RT->SystemUser);
912+
$saved_searches->UnLimit;
913+
$due_incidents = $saved_searches->Last;
914+
915+
my $new_reports = RT::SavedSearch->new(RT->SystemUser);
916+
$new_reports->Load( $due_incidents->Id - 3 );
917+
918+
my $user_incidents = RT::SavedSearch->new(RT->SystemUser);
919+
$user_incidents->Load( $due_incidents->Id - 2 );
920+
921+
my $nobody_incidents = RT::SavedSearch->new(RT->SystemUser);
922+
$nobody_incidents->Load( $due_incidents->Id - 1 );
923+
924+
my $rtir_dashboard = {
925+
Elements => [
926+
{
927+
Layout => 'col-md-8,col-md-4',
928+
Elements => [
929+
[
930+
{
931+
portlet_type => 'search',
932+
id => $new_reports->Id,
933+
description => 'Ticket: ' . $new_reports->Description,
934+
},
935+
{
936+
portlet_type => 'search',
937+
id => $user_incidents->Id,
938+
description => 'Ticket: ' . $user_incidents->Description,
939+
},
940+
{
941+
portlet_type => 'search',
942+
id => $nobody_incidents->Id,
943+
description => 'Ticket: ' . $nobody_incidents->Description,
944+
},
945+
{
946+
portlet_type => 'search',
947+
id => $due_incidents->Id,
948+
description => 'Ticket: ' . $due_incidents->Description,
949+
},
950+
],
951+
[
952+
{
953+
portlet_type => 'component',
954+
component => '/RTIR/Elements/WorkWithConstituency',
955+
description => '/RTIR/Elements/WorkWithConstituency',
956+
path => '/RTIR/Elements/WorkWithConstituency',
957+
},
958+
{
959+
portlet_type => 'component',
960+
component => '/RTIR/Elements/QueueSummary',
961+
description => '/RTIR/Elements/QueueSummary',
962+
path => '/RTIR/Elements/QueueSummary',
963+
},
964+
]
965+
],
966+
}
967+
],
968+
};
969+
904970
my $dashboard = RT::Dashboard->new( RT->SystemUser );
905-
my ( $ret, $msg ) = $dashboard->LoadByCols( Name => 'RTIR Homepage' );
971+
my ( $ret, $msg ) = $dashboard->Create(
972+
Name => 'RTIRDefaultDashboard',
973+
Description => 'RTIR Default Dashboard',
974+
PrincipalId => RT->SystemUser->PrincipalId,
975+
Content => $rtir_dashboard,
976+
);
977+
978+
if ( !$ret ) {
979+
RT->Logger->error("Couldn't create RTIRDefaultDashboard: $msg");
980+
}
906981

907982
if ( $ret ) {
908983
( $ret, $msg ) = RT->System->SetAttribute(
@@ -914,9 +989,6 @@ for my $cf (@CustomFields) {
914989
RT->Logger->error("Couldn't set RTIRDefaultDashboard: $msg");
915990
}
916991
}
917-
else {
918-
RT->Logger->error("Couldn't load dashboard RTIR Homepage: $msg");
919-
}
920992
},
921993
sub {
922994
my $class = RT::Class->new( RT->SystemUser );

etc/upgrade/5.9.0/content

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
@SavedSearches = (
3+
{ Name => 'New unlinked Incident Reports',
4+
Description => 'New unlinked Incident Reports', # loc
5+
ExtraQueryParams => 'RTIR',
6+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#',}.
7+
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject',}.
8+
q{Requestors,OwnerName,DueRelative,QueueName,Take},
9+
Order => 'ASC|ASC|ASC|ASC',
10+
OrderBy => 'Due',
11+
Query => 'Lifecycle = \'incident_reports\' AND Status = \'new\'',
12+
RTIR => '1',
13+
RTIRSearchEnabled => 'Yes',
14+
RowsPerPage => '10'
15+
},
16+
{ Name => 'My most due incidents',
17+
Description => 'Most due incidents owned by [_1]', # loc
18+
ExtraQueryParams => 'RTIR',
19+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#\',}.
20+
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject\',}.
21+
q{DueRelative, OwnerName, __Priority__,}.
22+
q{'UnreadMessages/TITLE:Updates\''},
23+
Order => 'ASC|DESC|ASC|ASC',
24+
OrderBy => 'Due|Priority',
25+
Query => 'Lifecycle = \'incidents\' AND Status = \'__Active__\' AND Owner = \'__CurrentUser__\'',
26+
RTIR => '1',
27+
RTIRSearchEnabled => 'Yes',
28+
RowsPerPage => '10'
29+
},
30+
{ Name => 'Most due unowned incidents',
31+
Description => 'Most due unowned incidents', # loc
32+
ExtraQueryParams => 'RTIR',
33+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#\',}
34+
. q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject\',}
35+
. q{DueRelative, OwnerName, __Priority__,}
36+
. q{'UnreadMessages/TITLE:Updates\''},
37+
Order => 'ASC|DESC|ASC|ASC',
38+
OrderBy => 'Due|Priority',
39+
Query => 'Lifecycle = \'incidents\' AND Status = \'__Active__\' AND Owner = \'Nobody\'',
40+
RTIR => '1',
41+
RTIRSearchEnabled => 'Yes',
42+
RowsPerPage => '10'
43+
},
44+
{ Name => 'Most due incidents',
45+
Description => 'Most due incidents', # loc
46+
ExtraQueryParams => 'RTIR',
47+
Format => q{'<b><a href="__RTIRTicketURI__">__id__</a></b>/TITLE:#\',}.
48+
q{'<b><a href="__RTIRTicketURI__">__Subject__</a></b>/TITLE:Subject\',}.
49+
q{DueRelative, OwnerName, __Priority__,}.
50+
q{'UnreadMessages/TITLE:Updates\''},
51+
Order => 'ASC|DESC|ASC|ASC',
52+
OrderBy => 'Due|Priority',
53+
Query => 'Lifecycle = \'incidents\' AND Status = \'__Active__\'',
54+
RTIR => '1',
55+
RTIRSearchEnabled => 'Yes',
56+
RowsPerPage => '10'
57+
},
58+
);
59+
60+
@Final = (
61+
sub {
62+
# Update the RTIR default homepage to use new saved searches.
63+
# The last 4 saved searches should be the ones added above.
64+
# Don't load by name since there could be other existing searches with
65+
# these names.
66+
my ($new_reports, $user_incidents, $nobody_incidents, $due_incidents);
67+
my $saved_searches = RT::SavedSearches->new(RT->SystemUser);
68+
$saved_searches->UnLimit;
69+
$due_incidents = $saved_searches->Last;
70+
71+
my $new_reports = RT::SavedSearch->new(RT->SystemUser);
72+
$new_reports->Load( $due_incidents->Id - 3 );
73+
74+
my $user_incidents = RT::SavedSearch->new(RT->SystemUser);
75+
$user_incidents->Load( $due_incidents->Id - 2 );
76+
77+
my $nobody_incidents = RT::SavedSearch->new(RT->SystemUser);
78+
$nobody_incidents->Load( $due_incidents->Id - 1 );
79+
80+
# The existing dashboard should have been updated during the RT 6 upgrade.
81+
# Update the entries that contain the old elements.
82+
my $dashboard = RT::Dashboard->new( RT->SystemUser );
83+
my ( $ret, $msg ) = $dashboard->LoadByCols( Name => 'RTIR Homepage' );
84+
85+
if ( !$ret ) {
86+
RT->Logger->error("Couldn't load RTIR Homepage: $msg");
87+
}
88+
else {
89+
my $content = $dashboard->Content;
90+
91+
for my $item (@{$content->{'Elements'}}) {
92+
if ( ref $item eq 'HASH' ) {
93+
if ( $item->{Elements} ) {
94+
for my $element ( @{ $item->{Elements} } ) {
95+
for my $item ( ref $element eq 'ARRAY' ? @$element : $element ) {
96+
if ( $item->{portlet_type} && $item->{portlet_type} eq 'component' ) {
97+
if ( $item->{path} =~ /NewReports$/ ) {
98+
$item = {
99+
portlet_type => 'search',
100+
id => $new_reports->Id,
101+
description => 'Ticket: ' . $new_reports->Description,
102+
};
103+
}
104+
if ( $item->{path} =~ /UserDueIncidents$/ ) {
105+
$item = {
106+
portlet_type => 'search',
107+
id => $user_incidents->Id,
108+
description => 'Ticket: ' . $user_incidents->Description,
109+
};
110+
}
111+
if ( $item->{path} =~ /NobodyDueIncidents$/ ) {
112+
$item = {
113+
portlet_type => 'search',
114+
id => $nobody_incidents->Id,
115+
description => 'Ticket: ' . $nobody_incidents->Description,
116+
};
117+
}
118+
if ( $item->{path} =~ /DueIncidents$/ ) {
119+
$item = {
120+
portlet_type => 'search',
121+
id => $due_incidents->Id,
122+
description => 'Ticket: ' . $due_incidents->Description,
123+
};
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
( $ret, $msg ) = $dashboard->SetContent( $content );
132+
133+
if ( !$ret ) {
134+
RT->Logger->error("Unable to update RTIR Homepage dashboard " . $dashboard->Id . " : $msg");
135+
}
136+
}
137+
138+
},
139+
);

0 commit comments

Comments
 (0)