[Rt-commit] r8564 - in rtir/branches/2.3-EXPERIMENTAL: html/RTIR
t/constituency
ruz at bestpractical.com
ruz at bestpractical.com
Wed Aug 15 19:43:53 EDT 2007
Author: ruz
Date: Wed Aug 15 19:43:52 2007
New Revision: 8564
Modified:
rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html
rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Edit.html
rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t
rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t
rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-reject.t
Log:
* implement reject algo for constituency propagation on Edit pages
* tests
Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html (original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Edit.html Wed Aug 15 19:43:52 2007
@@ -85,6 +85,7 @@
<td class="label"><&|/l&>Time Worked</&>:</td>
<td class="value"><input name="TimeWorked" value="<%$Ticket->TimeWorked|h%>" size="5" /></td>
</tr>
+% if ( $constituency_propagation ne 'reject' || !$has_parent ) {
<tr>
<td class="labeltop"><&|/l&>Constituency</&>:</td>
<td class="value">
@@ -93,6 +94,7 @@
Name => 'Constituency' &>
</td>
</tr>
+% }
% if ($Type eq 'Report') {
<tr>
@@ -255,6 +257,15 @@
$CanComment = 1 if ( $Ticket->CurrentUserHasRight('CommentOnTicket') or
$Ticket->CurrentUserHasRight('ModifyTicket') );
+my $constituency_propagation = RT->Config->Get('_RTIR_Constituency_Propagation');
+my $has_parent = 0;
+if ( $constituency_propagation eq 'reject' ) {
+ my $query = "Queue = 'Incidents' AND HasMember = ". $Ticket->id;
+ my $tickets = RT::Tickets->new( $RT::SystemUser );
+ $tickets->FromSQL( $query );
+ $tickets->RowsPerPage(1);
+ $has_parent = $tickets->First ? 1 : 0;
+}
if ( $SaveChanges && !$OnlySearchForPeople ) {
my $checks_failure = 0;
Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Edit.html
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Edit.html (original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Edit.html Wed Aug 15 19:43:52 2007
@@ -86,6 +86,7 @@
<td class="label"><&|/l&>Time Worked</&>:</td>
<td class="value"><input name="TimeWorked" value="<%$Ticket->TimeWorked|h%>" size="5" /></td>
</tr>
+% if ( $constituency_propagation ne 'reject' || !$has_children ) {
<tr>
<td class="label"><&|/l&>Constituency</&>:</td>
<td class="value">
@@ -95,6 +96,7 @@
Rows => 1 &>
</td>
</tr>
+% }
<tr>
<td class="label"><&|/l&>Function</&>:</td>
<td class="value">
@@ -169,6 +171,17 @@
$CanComment = 1 if ( $Ticket->CurrentUserHasRight('CommentOnTicket') or
$Ticket->CurrentUserHasRight('ModifyTicket') );
+my $constituency_propagation = RT->Config->Get('_RTIR_Constituency_Propagation');
+my $has_children = 0;
+if ( $constituency_propagation eq 'reject' ) {
+ my $query = "( Queue = 'Incident Reports' OR Queue = 'Investigations' OR Queue = 'Blocks' )"
+ ." AND MemberOf = ". $Ticket->id;
+ my $tickets = RT::Tickets->new( $RT::SystemUser );
+ $tickets->FromSQL( $query );
+ $tickets->RowsPerPage(1);
+ $has_children = $tickets->First ? 1 : 0;
+}
+
my @results;
if ( $SaveChanges && !$OnlySearchForPeople ) {
my $checks_failure = 0;
Modified: rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t (original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/basics.t Wed Aug 15 19:43:52 2007
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 109;
+use Test::More tests => 82;
require "t/rtir-test.pl";
use_ok('RT::IR');
@@ -108,32 +108,31 @@
}
}
-my $eduhandler = RT::User->new($RT::SystemUser);
-$eduhandler->Create(Name => 'eduhandler-'.$$, Privileged => 1);
-ok($eduhandler->id, "Created eduhandler");
-my $govhandler = RT::User->new($RT::SystemUser);
-$govhandler->Create(Name => 'govhandler-'.$$, Privileged => 1);
-ok($govhandler->id, "Created govhandler");
-
-my $govqueue = RT::Queue->new($RT::SystemUser);
-$govqueue->LoadByCols(Name => 'Incident Reports - GOVNET');
-unless ($govqueue->id) {
-$govqueue->Create(Name => 'Incident Reports - GOVNET', CorrespondAddress => 'govnet at example.com');
-}
-ok ($govqueue->id);
-my $eduqueue = RT::Queue->new($RT::SystemUser);
-$eduqueue->LoadByCols(Name => 'Incident Reports - EDUNET');
-unless ($eduqueue->id) {$eduqueue->Create(Name => 'Incident Reports - EDUNET', CorrespondAddress => 'edunet at example.com' )};
-ok($eduqueue->id);
-diag "Grant govhandler the right to see tickets in Incident Reports - GOVNET" if $ENV{'TEST_VERBOSE'};
+my $eduhandler = RT::Test->load_or_create_user( Name => 'eduhandler' );
+ok $eduhandler->id, "Created eduhandler";
+
+my $govhandler = RT::Test->load_or_create_user( Name => 'govhandler' );
+ok $govhandler->id, "Created govhandler";
+my $govqueue = RT::Test->load_or_create_queue(
+ Name => 'Incident Reports - GOVNET',
+ CorrespondAddress => 'govnet at example.com',
+);
+ok $govqueue->id, "loaded or created queue";
+
+my $eduqueue = RT::Test->load_or_create_queue(
+ Name => 'Incident Reports - EDUNET',
+ CorrespondAddress => 'edunet at example.com',
+);
+ok $eduqueue->id, "loaded or created queue";
+
+diag "Grant govhandler the right to see tickets in Incident Reports - GOVNET" if $ENV{'TEST_VERBOSE'};
{
my ($val,$msg) = $govhandler->PrincipalObj->GrantRight(Right => 'ShowTicket', Object => $govqueue);
ok ($val,$msg);
ok($govqueue->HasRight(Principal => $govhandler, Right => 'ShowTicket'), "Govhnadler can see govtix");
ok(!$govqueue->HasRight(Principal => $eduhandler, Right => 'ShowTicket'), "eduhandler can not see gov tix");
-
}
@@ -144,6 +143,8 @@
ok($eduqueue->HasRight(Principal => $eduhandler, Right => 'ShowTicket'), "For the eduqueue, eduhandler can see tix");
ok(!$eduqueue->HasRight(Principal => $govhandler, Right => 'ShowTicket'), "For the eduqueue, govhandler can not seetix");
}
+
+
diag "Create an incident report with a default constituency of EDUNET" if $ENV{'TEST_VERBOSE'};
@@ -161,13 +162,18 @@
$ticket->AddWatcher(Type => 'Requestor', Email => 'enduser at example.com');
$ticket->Correspond(Content => 'Testing');
my $txns = $ticket->Transactions;
-my $from;
-while (my $txn = $txns->Next) {
- next unless ($txn->Type eq 'EmailRecord');
- $from = $txn->Attachments->First->GetHeader('From');
+$txns->Limit( FIELD => 'Type', VALUE => 'EmailRecord' );
+ok $txns->Count, 'we have at least one email record';
+
+my $from_ok = 1;
+while ( my $txn = $txns->Next ) {
+ my $from = $txn->Attachments->First->GetHeader('From');
+ next if $from =~ /edunet/;
+
+ $from_ok = 0;
last;
}
-ok($from =~ /edunet/, "The from address pciked up the edunet address");
+ok $from_ok, "The from address picked up the edunet address";
diag "govhandler can't see the incident report" if $ENV{'TEST_VERBOSE'};
Modified: rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t (original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t Wed Aug 15 19:43:52 2007
@@ -117,7 +117,7 @@
my $id = create_rtir_ticket_ok(
$agent, $queue,
{
- Subject => "test ip",
+ Subject => "test constituency",
Incident => $incident_id,
},
{ Constituency => 'GOVNET' },
@@ -155,7 +155,7 @@
my $child_id = create_rtir_ticket_ok(
$agent, $queue,
{
- Subject => "test ip",
+ Subject => "test constituency",
Incident => $incident_id,
},
{ Constituency => 'GOVNET' },
Modified: rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-reject.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-reject.t (original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-reject.t Wed Aug 15 19:43:52 2007
@@ -9,7 +9,7 @@
# XXX: we should use new RT::Test features and start server with
# option we want.
if ( RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject' ) {
- plan tests => 127;
+ plan tests => 200;
} else {
plan skip_all => 'constituency propagation algorithm is not "reject"';
}
@@ -116,7 +116,7 @@
my $id = create_rtir_ticket(
$agent, $queue,
{
- Subject => "test ip",
+ Subject => "test constituency",
Incident => $incident_id,
},
{ Constituency => 'GOVNET' },
@@ -152,7 +152,7 @@
my $id = create_rtir_ticket_ok(
$agent, $queue,
{
- Subject => "test ip",
+ Subject => "test constituency",
Incident => $incident_id,
},
{ Constituency => 'EDUNET' },
@@ -219,5 +219,93 @@
$agent->content_unlike(qr/incident report #$ir_id/, 'no IR on the page');
}
-# TODO: decide what to do with Edit page when we're using reject algorithm
+
+diag "check that we can change constituency of an unlinked ticket using 'Edit' page"
+ if $ENV{'TEST_VERBOSE'};
+{
+ # blocks are always linked to an incident
+ foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations' ) {
+ my $id = create_rtir_ticket_ok(
+ $agent, $queue,
+ { Subject => "test constituency" },
+ { Constituency => 'GOVNET' },
+ );
+ DBIx::SearchBuilder::Record::Cachable::FlushCache();
+
+ {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $id );
+ ok $ticket->id, 'loaded ticket';
+ is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'GOVNET', 'correct value';
+ }
+
+ display_ticket($agent, $id);
+ $agent->follow_link( text => 'Edit' );
+ $agent->form_number(3);
+ $agent->select("Object-RT::Ticket-$id-CustomField-". $cf->id ."-Values" => 'EDUNET' );
+ $agent->click('SaveChanges');
+ $agent->content_like(qr/Constituency .* changed to EDUNET/mi, 'field is changed');
+ DBIx::SearchBuilder::Record::Cachable::FlushCache();
+
+ {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $id );
+ ok $ticket->id, 'loaded ticket';
+ is uc $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'EDUNET', 'correct value';
+ }
+ }
+}
+
+diag "check that we can change constituency of an unlinked ticket using 'Edit' page"
+ if $ENV{'TEST_VERBOSE'};
+{
+ my $incident_id = create_rtir_ticket_ok(
+ $agent, 'Incidents',
+ { Subject => "test" },
+ { Constituency => 'EDUNET' },
+ );
+ {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $incident_id );
+ ok $ticket->id, 'loaded ticket';
+ is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'EDUNET', 'correct value';
+ }
+
+ foreach my $queue( 'Blocks', 'Incident Reports', 'Investigations' ) {
+ my $id = create_rtir_ticket_ok(
+ $agent, $queue,
+ {
+ Subject => "test constituency",
+ Incident => $incident_id,
+ },
+ { Constituency => 'EDUNET' },
+ );
+ DBIx::SearchBuilder::Record::Cachable::FlushCache();
+ {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $id );
+ ok $ticket->id, 'loaded ticket';
+ is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'EDUNET', 'correct value';
+ }
+
+ display_ticket($agent, $id);
+ $agent->follow_link( text => 'Edit' );
+ my $form = $agent->form_number(3);
+ ok !eval { $form->value('Constituency') }, 'no constituency hidden field';
+ ok !$form->find_input( "Object-RT::Ticket-$id-CustomField-". $cf->id ."-Values" ),
+ 'no constituency select box';
+ }
+
+ # check incident as it's linked now
+ display_ticket($agent, $incident_id);
+ $agent->follow_link( text => 'Edit' );
+ my $form = $agent->form_number(3);
+ ok !eval { $form->value('Constituency') }, 'no constituency hidden field';
+ ok !$form->find_input( "Object-RT::Ticket-$incident_id-CustomField-". $cf->id ."-Values" ),
+ 'no constituency select box';
+}
More information about the Rt-commit
mailing list