Skip to content

Commit 076cd86

Browse files
committed
Merge branch '4.0/correspondents-from-makeclicky' into 4.0.1-releng
2 parents dc3e149 + 5d4c728 commit 076cd86

File tree

3 files changed

+121
-60
lines changed

3 files changed

+121
-60
lines changed

html/Callbacks/RTIR/Elements/MakeClicky/Default

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,16 @@ my %actions;
158158
RT::IR->HREFTo(qq{Tools/Lookup.html?$args{'lookup_params'}type=email&q=$escaped_email}). qq{">}
159159
.loc('lookup email') .q{</a>};
160160
if ( $args{'incident'} ) {
161+
my $uri_escaped_email = $escaped_email;
162+
RT::Interface::Web::EscapeURI(\$uri_escaped_email);
161163
if ( $r->uri =~ /Lookup.html$/ ) {
162164
$result .= qq{<input type="checkbox" name="Requestorbox-$escaped_email" unchecked />};
163165
}
164166
$result .= qq{<a class="button button-small" href="}.
165167
RT::IR->HREFTo( "CreateInQueue.html"
166168
. qq{?Incident=$args{'incident'}}
167169
. qq{&Lifecycle=}.RT::IR->lifecycle_investigation
168-
. "&Requestors=$escaped_email")
170+
. "&Requestors=$uri_escaped_email")
169171
. qq{">}
170172
. loc('Investigate to') .qq{</a>};
171173
}

html/RTIR/Elements/CreateInRTIRQueueModal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
% }
5252
% if ($Child) {
5353
<input type="hidden" name="Child" value="<%$Child%>"/>
54+
% }
55+
% if ($Requestors) {
56+
<input type="hidden" name="Requestors" value="<%$Requestors%>"/>
5457
% }
5558
<&|/l_unsafe, $ticket_type,
5659
$m->scomp('/RTIR/Elements/SelectRTIRQueue',
@@ -95,5 +98,6 @@ my $ticket_type = lc RT::IR::TicketType( Lifecycle => $Lifecycle );
9598
$Lifecycle
9699
$Incident => undef
97100
$Child => undef
101+
$Requestors => undef
98102
</%ARGS>
99103

t/015-make-clicky.t

Lines changed: 114 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,96 +19,151 @@ diag "clicky ip" if $ENV{'TEST_VERBOSE'};
1919
my @links = $agent->followable_links;
2020
if ( $clicky{'ip'} ) {
2121
my ($lookup_link) = grep lc($_->text||'') eq 'lookup ip', @links;
22-
ok($lookup_link, "found link");
23-
ok($lookup_link->url =~ /(?<!\d)1\.0\.0\.0(?!\d)/, 'url has an ip' );
22+
ok($lookup_link, "Found link for IP address");
23+
ok($lookup_link->url =~ /(?<!\d)1\.0\.0\.0(?!\d)/, 'Found IP address in URL' );
2424
} else {
25-
ok(!grep( lc $_->text eq 'lookup ip', @links ), "not found link");
25+
ok(!grep( lc $_->text eq 'lookup ip', @links ), "Didn't find link for IP address");
2626
}
2727

2828
$id = $agent->create_ir( { Subject => 'clicky ip', Content => '255.255.255.255' } );
2929
$agent->display_ticket( $id);
3030
@links = $agent->followable_links;
3131
if ( $clicky{'ip'} ) {
3232
my ($lookup_link) = grep lc($_->text||'') eq 'lookup ip', @links;
33-
ok($lookup_link, "found link");
34-
ok($lookup_link->url =~ /(?<!\d)255\.255\.255\.255(?!\d)/, 'url has an ip' );
33+
ok($lookup_link, "Found link for IP address");
34+
ok($lookup_link->url =~ /(?<!\d)255\.255\.255\.255(?!\d)/, 'Found IP address in URL' );
3535
} else {
36-
ok(!grep( lc $_->text eq 'lookup ip', @links ), "not found link");
36+
ok(!grep( lc $_->text eq 'lookup ip', @links ), "Didn't find link for IP address");
3737
}
3838

3939
$id = $agent->create_ir( { Subject => 'clicky ip', Content => '255.255.255.256' } );
4040
$agent->display_ticket( $id);
4141
@links = $agent->followable_links;
42-
ok(!grep( lc($_->text||'') eq 'lookup ip', @links ), "not found link");
42+
ok(!grep( lc($_->text||'') eq 'lookup ip', @links ), "Didn't find link for IP address");
4343

4444
$id = $agent->create_ir( { Subject => 'clicky ip', Content => '355.255.255.255' } );
4545
$agent->display_ticket( $id);
4646
@links = $agent->followable_links;
47-
ok(!grep( lc($_->text||'') eq 'lookup ip', @links ), "not found link");
47+
ok(!grep( lc($_->text||'') eq 'lookup ip', @links ), "Didn't find link for IP address");
4848
}
4949

5050
diag "clicky email" if $ENV{'TEST_VERBOSE'};
5151
{
5252

53-
for my $email (
54-
'foo@example.com', 'foo-bar+baz@example.me',
55-
'foo@example.mobi', 'foo@localhost.localhost',
53+
for my $create_method_ref (
54+
sub { $agent->create_ir( $_[0] ) },
55+
sub { $agent->create_incident( $_[0] ) },
56+
sub { $agent->create_investigation( $_[0] ) },
57+
sub {
58+
$_[0]{Incident} = $agent->create_incident(@_);
59+
$agent->create_countermeasure( $_[0] );
60+
},
5661
)
5762
{
58-
diag "test valid email $email" if $ENV{TEST_VERBOSE};
59-
my ( $name, $domain ) = split /@/, $email, 2;
60-
my $id =
61-
$agent->create_ir( { Subject => 'clicky email', Content => $email } );
62-
$agent->display_ticket($id);
63-
my $email_link = $agent->find_link( url_regex => qr/\Qq=$email\E/, text_regex => qr/\Qlookup email\E$/ );
64-
my $domain_link = $agent->find_link( text_regex => qr/^\Qlookup "$domain"\E$/i );
65-
$agent->save_content('/tmp/x.html');
66-
if ( $clicky{'email'} ) {
67-
ok( $email_link, "found link $email_link" );
68-
ok( $email_link->url =~ /(?<!\w)\Qq=$email\E(?!\w)/, 'url '.$email_link->url.' has an email - '.$email );
69-
ok( $domain_link, "found link" );
70-
ok( $domain_link->url =~ /(?<!\w)\Q$domain\E(?!\w)/, 'url has a domain' );
71-
}
72-
else {
73-
ok( !$email_link, "not found email link" );
74-
ok( !$domain_link, "not found domain link" );
75-
}
76-
77-
}
78-
79-
for my $email ( 'foo@example') {
80-
diag "test invalid email (invalid domain) $email" if $ENV{TEST_VERBOSE};
63+
for my $email (
64+
'foo@example.com', 'foo-bar+baz@example.me',
65+
'foo@example.mobi', 'foo@localhost.localhost',
66+
)
67+
{
68+
diag "test valid email $email" if $ENV{TEST_VERBOSE};
69+
my ( $name, $domain ) = split /@/, $email, 2;
70+
my $uri_escaped_email = $email;
71+
RT::Interface::Web::EscapeURI(\$uri_escaped_email);
72+
73+
my $id =
74+
$create_method_ref->( { Subject => 'clicky email', Content => $email } );
75+
$agent->display_ticket($id);
76+
77+
my $is_incident = $agent->text() =~ qr/Queue: Incidents/;
78+
79+
my $email_link = $agent->find_link( url_regex => qr/\Qq=$email\E/, text_regex => qr/\Qlookup email\E$/ );
80+
my $domain_link = $agent->find_link( text_regex => qr/^\Qlookup "$domain"\E$/i );
81+
82+
my $investigate_link = $agent->find_link( url_regex => qr/\QRequestors=$uri_escaped_email\E/,
83+
text_regex => qr/^\Qinvestigate to\E$/i ) if $is_incident;
84+
85+
if ( $clicky{'email'} ) {
86+
ok( $email_link, "Found link for $email_link" );
87+
ok( $email_link->url =~ /(?<!\w)\Qq=$email\E(?!\w)/, 'URL link '.$email_link->url.' has an email address: '.$email );
88+
ok( $domain_link, "Found link for URL domain" );
89+
ok( $domain_link->url =~ /(?<!\w)\Q$domain\E(?!\w)/, 'URL link has a domain' );
90+
91+
# Test that 'Investigate to' links go to the queue selection page for creating incidents.
92+
# Then test that the new investigation form on that page loads the investigation creation page.
93+
# Then test taht the Correspondents field is populated with the given email address.
94+
if ( $is_incident ) {
95+
ok( $investigate_link, "found investigate link" );
96+
ok( $investigate_link->url =~ /(?<!\w)\QRequestors=$uri_escaped_email\E(?!\w)/,
97+
'url '.$investigate_link->url.' has Requestors email' );
98+
$agent->follow_link_ok( { url => $investigate_link->url }, 'followed "investigate to" link' );
99+
$agent->title_is( 'Select Queue for New Investigation',
100+
'selecting queue for new investigation' );
101+
$agent->submit_form_ok(
102+
{
103+
form_id => 'CreateInQueue',
104+
},
105+
'submitted new investigation form',
106+
);
107+
$agent->title_is( 'Launch a new investigation', 'launching a new investigation' );
108+
$agent->form_name( 'TicketCreate' );
109+
my @correspondents = $agent->find_all_inputs(
110+
name => 'Requestors',
111+
type => 'text',
112+
value => $email,
113+
);
114+
ok($correspondents[0], 'Found an email address');
115+
is($correspondents[0]->value, $email, 'Email is correct: ' . $correspondents[0]->value);
116+
}
117+
}
118+
else {
119+
ok( !$email_link, "Didn't find link for email address" );
120+
ok( !$domain_link, "Didn't find link for domain" );
121+
ok( !$investigate_link, "Didn't find 'Investigate to' link") if $is_incident;
122+
}
81123

82-
my ( $name, $domain );
83-
if ($email =~ /^(.*)@(.*)$/) {
84-
($name,$domain) = ($1,$2);
85124
}
86-
my $id = $agent->create_ir( { Subject => 'clicky email', Content => $email } );
87-
$agent->display_ticket($id);
88-
my $email_link = $agent->find_link( url_regex => qr/\Qq=$email\E/, text_regex => qr/\Qlookup email\E$/ );
89-
ok( !$email_link, "not found email link for $email" );
90-
my $domain_link = $agent->find_link( text_regex => qr/^\Qlookup "$domain"\E$/i );
91-
ok( !$domain_link, "not found domain link for $domain" );
92125

93-
}
94-
95-
96-
for my $email ( '@example.com' ) {
97-
diag "test invalid email (no local part) $email" if $ENV{TEST_VERBOSE};
126+
for my $email ( 'foo@example') {
127+
diag "test invalid email (invalid domain) $email" if $ENV{TEST_VERBOSE};
128+
129+
my ( $name, $domain );
130+
if ($email =~ /^(.*)@(.*)$/) {
131+
($name,$domain) = ($1,$2);
132+
}
133+
my $id = $create_method_ref->( { Subject => 'clicky email', Content => $email } );
134+
$agent->display_ticket($id);
135+
my $is_incident = $agent->text() =~ qr/Queue: Incidents/;
136+
my $email_link = $agent->find_link( url_regex => qr/\Qq=$email\E/, text_regex => qr/\Qlookup email\E$/ );
137+
ok( !$email_link, "Didn't find an email link for $email" );
138+
my $domain_link = $agent->find_link( text_regex => qr/^\Qlookup "$domain"\E$/i );
139+
ok( !$domain_link, "Didn't find a domain link for $domain" );
140+
141+
my $investigate_link = $agent->find_link( url_regex => qr/\QRequestors=$email\E/,
142+
text_regex => qr/^\Qinvestigate to\E$/i )
143+
if $is_incident;
144+
ok( !$investigate_link, "Didn't find 'Investigate to' link for $email" );
145+
}
98146

99-
my ( $name, $domain );
100-
if ($email =~ /^(.*)@(.*)$/) {
101-
($name,$domain) = ($1,$2);
147+
for my $email ( '@example.com' ) {
148+
diag "test invalid email (no local part) $email" if $ENV{TEST_VERBOSE};
149+
150+
my ( $name, $domain );
151+
if ($email =~ /^(.*)@(.*)$/) {
152+
($name,$domain) = ($1,$2);
153+
}
154+
my $id = $create_method_ref->( { Subject => 'clicky email', Content => $email } );
155+
$agent->display_ticket($id);
156+
my $is_incident = $agent->text() =~ qr/Queue: Incidents/;
157+
my $email_link = $agent->find_link( url_regex => qr/\Qq=$email\E/, text_regex => qr/\Qlookup email\E$/ );
158+
ok( !$email_link, "Didn't find link for $email" );
159+
my $domain_link = $agent->find_link( text_regex => qr/^\Qlookup "$domain"\E$/i );
160+
ok( $domain_link, "Found the bare domain for $domain" );
161+
my $investigate_link = $agent->find_link( url_regex => qr/\QRequestors=$email\E/,
162+
text_regex => qr/^\Qinvestigate to\E$/i )
163+
if $is_incident;
164+
ok( !$investigate_link, "Didn't find 'Investigate to' link for $email" );
102165
}
103-
my $id = $agent->create_ir( { Subject => 'clicky email', Content => $email } );
104-
$agent->display_ticket($id);
105-
my $email_link = $agent->find_link( url_regex => qr/\Qq=$email\E/, text_regex => qr/\Qlookup email\E$/ );
106-
ok( !$email_link, "not found email link for $email" );
107-
my $domain_link = $agent->find_link( text_regex => qr/^\Qlookup "$domain"\E$/i );
108-
ok( $domain_link, "still found the bare domain for $domain" );
109166
}
110-
111-
112167
}
113168

114169
diag "utf8 caching " if $ENV{'TEST_VERBOSE'};

0 commit comments

Comments
 (0)