Skip to content

Commit 03056ff

Browse files
Move Menu() calls to the new PrivilegedMainNav callback
RT 6 doesn't always refresh the top menu, so Menu is no longer available on every call. Move the top menu items to the new callback that will be called at least on the initial page load. Search menus are intentionally removed because both Edit Search and Show Results are available in the page menu when working with a search, so they are not needed in the top level RTIR menu.
1 parent 4b69c58 commit 03056ff

2 files changed

Lines changed: 158 additions & 87 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
%# BEGIN BPS TAGGED BLOCK {{{
2+
%#
3+
%# COPYRIGHT:
4+
%#
5+
%# This software is Copyright (c) 1996-2024 Best Practical Solutions, LLC
6+
%# <sales@bestpractical.com>
7+
%#
8+
%# (Except where explicitly superseded by other copyright notices)
9+
%#
10+
%#
11+
%# LICENSE:
12+
%#
13+
%# This work is made available to you under the terms of Version 2 of
14+
%# the GNU General Public License. A copy of that license should have
15+
%# been provided with this software, but in any event can be snarfed
16+
%# from www.gnu.org.
17+
%#
18+
%# This work is distributed in the hope that it will be useful, but
19+
%# WITHOUT ANY WARRANTY; without even the implied warranty of
20+
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21+
%# General Public License for more details.
22+
%#
23+
%# You should have received a copy of the GNU General Public License
24+
%# along with this program; if not, write to the Free Software
25+
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26+
%# 02110-1301 or visit their web page on the internet at
27+
%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28+
%#
29+
%#
30+
%# CONTRIBUTION SUBMISSION POLICY:
31+
%#
32+
%# (The following paragraph is not intended to limit the rights granted
33+
%# to you to modify and distribute this software under the terms of
34+
%# the GNU General Public License and is only of importance to you if
35+
%# you choose to contribute your changes and enhancements to the
36+
%# community by submitting them to Best Practical Solutions, LLC.)
37+
%#
38+
%# By intentionally submitting any modifications, corrections or
39+
%# derivatives to this work, or any other work intended for use with
40+
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41+
%# you are the copyright holder for those contributions and you grant
42+
%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43+
%# royalty-free, perpetual, license to use, copy, create derivative
44+
%# works based on those contributions, and sublicense and distribute
45+
%# those contributions and any derivatives thereof.
46+
%#
47+
%# END BPS TAGGED BLOCK }}}
48+
<%INIT>
49+
50+
my $query_string = sub {
51+
my %args = @_;
52+
my $u = URI->new();
53+
$u->query_form(map { $_ => $args{$_} } sort keys %args);
54+
return $u->query || '';
55+
};
56+
57+
if ( my $admin = Menu->child('admin') ) {
58+
if ( my $global = $admin->child('global') ) {
59+
$global->child(
60+
'my-rtir' => title => 'RTIR at a glance',
61+
path => '/Admin/Global/MyRT.html?'
62+
. $query_string->(
63+
Title => loc('Customize Global RTIR at a glance'),
64+
WidgetTitle => loc('Set RTIR Homepage'),
65+
AttributeName => 'RTIRDefaultDashboard',
66+
AttributeDescription => 'RTIR Default Dashboard',
67+
),
68+
sort_order => 8.1,
69+
);
70+
}
71+
}
72+
73+
my $args = $DECODED_ARGS;
74+
75+
my @query_fields = qw(Query Format RowsPerPage Page OrderBy Order ExtraQueryParams);
76+
77+
my $search_arguments = sub {
78+
my %res = ();
79+
my $caller_args = $m->caller_args(1);
80+
if ( $caller_args->{'SearchArgs'} ) {
81+
@res{ @query_fields } = @{ $caller_args->{'SearchArgs'} }{ @query_fields };
82+
if ( $res{ExtraQueryParams} ) {
83+
$res{$_} = $caller_args->{'SearchArgs'}{$_}
84+
for ref $res{ExtraQueryParams} ? @{ $res{ExtraQueryParams} } : $res{ExtraQueryParams};
85+
}
86+
} else {
87+
@res{ @query_fields } = @{ $args }{ @query_fields };
88+
if ( $res{ExtraQueryParams} ) {
89+
$res{$_} = $args->{$_}
90+
for ref $res{ExtraQueryParams} ? @{ $res{ExtraQueryParams} } : $res{ExtraQueryParams};
91+
}
92+
}
93+
94+
delete $res{$_} foreach grep !defined $res{$_}, keys %res;
95+
return %res;
96+
};
97+
98+
my $root = Menu->child( rtir => title => loc('RTIR'), path => '/RTIR/', sort_order => '1.5' );
99+
100+
my $search = $root->child( search => title => loc('Search'), path => RT::IR->HREFTo('', IncludeWebPath => 0) );
101+
$search->child( new => title => loc('New Search'), path => '/Search/Build.html?NewQuery=1&ExtraQueryParams=RTIR&RTIR=1' );
102+
103+
$root->child(
104+
incidents => title => loc('Incidents'),
105+
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='.RT::IR->lifecycle_incident,
106+
)->child(
107+
create => title => loc('Create'),
108+
path => RT::IR->HREFTo('Incident/Create.html?Lifecycle='.RT::IR->lifecycle_incident, IncludeWebPath => 0),
109+
);
110+
$root->child(
111+
reports => title => loc('Incident Reports'),
112+
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='. RT::IR->lifecycle_report,
113+
)->child(
114+
create => title => loc('Create'),
115+
path => RT::IR->HREFTo('Create.html?Lifecycle='.RT::IR->lifecycle_report, IncludeWebPath => 0),
116+
);
117+
$root->child(
118+
investigations => title => loc('Investigations'),
119+
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='.RT::IR->lifecycle_investigation,
120+
)->child(
121+
launch => title => loc('Launch'),
122+
path => RT::IR->HREFTo('Create.html?Lifecycle='.RT::IR->lifecycle_investigation, IncludeWebPath => 0),
123+
);
124+
unless ( RT->Config->Get('RTIR_DisableCountermeasures') ) {
125+
$root->child(
126+
countermeasures => title => loc('Countermeasures'),
127+
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='.RT::IR->lifecycle_countermeasure,
128+
)->child(
129+
create => title => loc('Create'),
130+
path => RT::IR->HREFTo('Create.html?Lifecycle='.RT::IR->lifecycle_countermeasure, IncludeWebPath => 0),
131+
);
132+
}
133+
134+
my $tools = $root->child( tools => title => loc('Tools'), path => RT::IR->HREFTo('Tools/', IncludeWebPath => 0) );
135+
$tools->child( lookup => title => loc('Lookup'), path => RT::IR->HREFTo('Tools/Lookup.html', IncludeWebPath => 0));
136+
$tools->child( reporting => title => loc('Reporting'), path => RT::IR->HREFTo('Reporting/', IncludeWebPath => 0) );
137+
my $scripted_actions = $tools->child( scripted_actions => title => loc('Scripted Action') );
138+
$scripted_actions->child( email => title => loc('By Email address'), path => RT::IR->HREFTo('Tools/ScriptedAction.html', IncludeWebPath => 0) );
139+
$scripted_actions->child( ip => title => loc('By IP address'), path => RT::IR->HREFTo('Tools/ScriptedAction.html?loop=IP', IncludeWebPath => 0) );
140+
my $external_feeds = $tools->child( 'external_feeds', title => loc('External Feeds'), path => RT::IR->HREFTo('Tools/ExternalFeeds.html', IncludeWebPath => 0) );
141+
142+
my $request_path = $HTML::Mason::Commands::r->path_info;
143+
$request_path =~ s!/{2,}!/!g;
144+
145+
my $re_rtir_path = qr'^/RTIR/(?:c/[^/]*/?)?';
146+
my $re_rtir_types = '(?:'. join( '|', map "\Q$_\E", RT::IR->Types ) .')';
147+
148+
if ( $session{'CurrentUser'}->HasRight(Right => 'ModifySelf', Object => $RT::System) ) {
149+
if ( $request_path =~ m{(?:$re_rtir_path)(?:index\.html|)$} ) {
150+
PageMenu()->child( edit => raw_html => q[<a id="page-edit" class="menu-item" href="] . RT::IR->HREFTo("Prefs/Home.html") . qq["><span class="fas fa-cog" alt="].loc('Edit').q[" data-toggle="tooltip" data-placement="top" data-original-title="].loc('Edit').q["></span></a>]);
151+
}
152+
Menu->child('preferences')->child('settings')->child(
153+
rtir_home_page => title => loc('RTIR at a glance'),
154+
path => RT::IR->HREFTo('Prefs/Home.html', IncludeWebPath => 0),
155+
);
156+
}
157+
158+
</%INIT>

html/Callbacks/RTIR/Elements/Tabs/Privileged

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ my $query_string = sub {
5454
return $u->query || '';
5555
};
5656

57-
if ( my $admin = Menu->child('admin') ) {
58-
if ( my $global = $admin->child('global') ) {
59-
$global->child(
60-
'my-rtir' => title => 'RTIR at a glance',
61-
path => '/Admin/Global/MyRT.html?'
62-
. $query_string->(
63-
Title => loc('Customize Global RTIR at a glance'),
64-
WidgetTitle => loc('Set RTIR Homepage'),
65-
AttributeName => 'RTIRDefaultDashboard',
66-
AttributeDescription => 'RTIR Default Dashboard',
67-
),
68-
sort_order => 8.1,
69-
);
70-
}
71-
}
72-
7357
my $args = $DECODED_ARGS;
7458

7559
my @query_fields = qw(Query Format RowsPerPage Page OrderBy Order ExtraQueryParams);
@@ -147,76 +131,11 @@ if ( $m->request_comp->path =~ m{^/Search/} ) {
147131
}
148132
}
149133

150-
my $root = Menu->child( rtir => title => loc('RTIR'), path => '/RTIR/', sort_order => '1.5' );
151-
152-
my $search = $root->child( search => title => loc('Search'), path => RT::IR->HREFTo('', IncludeWebPath => 0) );
153-
$search->child( new => title => loc('New Search'), path => '/Search/Build.html?NewQuery=1&ExtraQueryParams=RTIR&RTIR=1' );
154-
155-
{
156-
my $current_search = $session{'CurrentSearchHash'} ? { map { $_ => $session{'CurrentSearchHash'}{$_} } @query_fields } : {};
157-
158-
if ( my $extra_params = $current_search->{ExtraQueryParams} ) {
159-
for my $param ( ref $extra_params eq 'ARRAY' ? @$extra_params : $extra_params ) {
160-
$current_search->{$param} = $session{'CurrentSearchHash'}{$param};
161-
}
162-
}
163-
164-
my $has_query = 1 if ( $args->{'Query'} or $current_search->{'Query'} );
165-
166-
if ( $has_query ) {
167-
$search->child( build => title => loc('Edit Search'), path => '/Search/Build.html', );
168-
$search->child( results => title => loc('Show Results'),
169-
path =>'/Search/Results.html?'.
170-
$query_string->( $args->{'Query'} ? $search_arguments->() : %$current_search ) );
171-
}
172-
}
173-
174-
$root->child(
175-
incidents => title => loc('Incidents'),
176-
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='.RT::IR->lifecycle_incident,
177-
)->child(
178-
create => title => loc('Create'),
179-
path => RT::IR->HREFTo('Incident/Create.html?Lifecycle='.RT::IR->lifecycle_incident, IncludeWebPath => 0),
180-
);
181-
$root->child(
182-
reports => title => loc('Incident Reports'),
183-
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='. RT::IR->lifecycle_report,
184-
)->child(
185-
create => title => loc('Create'),
186-
path => RT::IR->HREFTo('Create.html?Lifecycle='.RT::IR->lifecycle_report, IncludeWebPath => 0),
187-
);
188-
$root->child(
189-
investigations => title => loc('Investigations'),
190-
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='.RT::IR->lifecycle_investigation,
191-
)->child(
192-
launch => title => loc('Launch'),
193-
path => RT::IR->HREFTo('Create.html?Lifecycle='.RT::IR->lifecycle_investigation, IncludeWebPath => 0),
194-
);
195-
unless ( RT->Config->Get('RTIR_DisableCountermeasures') ) {
196-
$root->child(
197-
countermeasures => title => loc('Countermeasures'),
198-
path => '/Search/Results.html?ExtraQueryParams=RTIR&RTIR=1&Lifecycle='.RT::IR->lifecycle_countermeasure,
199-
)->child(
200-
create => title => loc('Create'),
201-
path => RT::IR->HREFTo('Create.html?Lifecycle='.RT::IR->lifecycle_countermeasure, IncludeWebPath => 0),
202-
);
203-
}
204-
205-
my $tools = $root->child( tools => title => loc('Tools'), path => RT::IR->HREFTo('Tools/', IncludeWebPath => 0) );
206-
$tools->child( lookup => title => loc('Lookup'), path => RT::IR->HREFTo('Tools/Lookup.html', IncludeWebPath => 0));
207-
$tools->child( reporting => title => loc('Reporting'), path => RT::IR->HREFTo('Reporting/', IncludeWebPath => 0) );
208-
my $scripted_actions = $tools->child( scripted_actions => title => loc('Scripted Action') );
209-
$scripted_actions->child( email => title => loc('By Email address'), path => RT::IR->HREFTo('Tools/ScriptedAction.html', IncludeWebPath => 0) );
210-
$scripted_actions->child( ip => title => loc('By IP address'), path => RT::IR->HREFTo('Tools/ScriptedAction.html?loop=IP', IncludeWebPath => 0) );
211-
my $external_feeds = $tools->child( 'external_feeds', title => loc('External Feeds'), path => RT::IR->HREFTo('Tools/ExternalFeeds.html', IncludeWebPath => 0) );
212-
213134
my $request_path = $HTML::Mason::Commands::r->path_info;
214135
$request_path =~ s!/{2,}!/!g;
215136
return unless $request_path =~ m{^/RTIR/};
216137

217-
218138
my $re_rtir_path = qr'^/RTIR/(?:c/[^/]*/?)?';
219-
220139
my $re_rtir_types = '(?:'. join( '|', map "\Q$_\E", RT::IR->Types ) .')';
221140

222141
if ( $request_path =~ m{(?:$re_rtir_path)(?:$re_rtir_types/)?(Display|Edit|Update|Forward|Advanced)\.html$} ) {
@@ -523,13 +442,11 @@ if ( $request_path =~ m{(?:$re_rtir_path)(?:$re_rtir_types/)?(Display|Edit|Updat
523442
# full RTIR Search UI, only from the Bulk screens.
524443
my $bulk_path = 1 if $request_path =~ m{(?:$re_rtir_path)(Incident/BulkAbandon\.html$|Report/BulkReject\.html$)};
525444

526-
$search->child( build => title => loc('Edit Search'), path => '/Search/Build.html?RTIR=1', );
527445
PageMenu()->child(
528446
edit_search => title => loc('Edit Search'),
529447
path => '/Search/Build.html?' . $query_string->( %args ),
530448
);
531449
if ( $args{'Query'} && !$bulk_path ) {
532-
$search->child( new => title => loc('New Search'), path => '/Search/Build.html?NewQuery=1&ExtraQueryParams=RTIR&RTIR=1' );
533450
PageMenu()->child(
534451
new_search => title => loc('New Search'),
535452
path => '/Search/Build.html?NewQuery=1&ExtraQueryParams=RTIR&RTIR=1'
@@ -613,10 +530,6 @@ if ( $session{'CurrentUser'}->HasRight(Right => 'ModifySelf', Object => $RT::Sys
613530
if ( $request_path =~ m{(?:$re_rtir_path)(?:index\.html|)$} ) {
614531
PageMenu()->child( edit => raw_html => q[<a id="page-edit" class="menu-item" href="] . RT::IR->HREFTo("Prefs/Home.html") . qq["><span class="fas fa-cog" alt="].loc('Edit').q[" data-toggle="tooltip" data-placement="top" data-original-title="].loc('Edit').q["></span></a>]);
615532
}
616-
Menu->child('preferences')->child('settings')->child(
617-
rtir_home_page => title => loc('RTIR at a glance'),
618-
path => RT::IR->HREFTo('Prefs/Home.html', IncludeWebPath => 0),
619-
);
620533
}
621534

622535
PageWidgets()->child('simple_search')->raw_html( $m->scomp(

0 commit comments

Comments
 (0)