[Rt-commit] r5484 - in rt/branches/QUEBEC-EXPERIMENTAL: .
lib/RT/Interface lib/RT/URI lib/t/regression
ruz at bestpractical.com
ruz at bestpractical.com
Wed Jun 28 17:40:00 EDT 2006
Author: ruz
Date: Wed Jun 28 17:39:57 2006
New Revision: 5484
Modified:
rt/branches/QUEBEC-EXPERIMENTAL/ (props changed)
rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Interface/Email.pm
rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Link_Overlay.pm
rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Links_Overlay.pm
rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Record.pm
rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/base.pm
rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/fsck_com_rt.pm
rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/06mailgateway.t
Log:
merge 3.4->QUEBEC
r3273 at cubic-pc (orig r5400): ruz | 2006-06-17 04:40:24 +0400
* not default mail plugins has been broken during last refactoring
** move a code back into its scope
** don't forget to store $_ in $Class when $_ matches ^RT::Interface::Email
r3310 at cubic-pc (orig r5476): ruz | 2006-06-28 01:21:07 +0400
* nothing special, small changes I'd changed during
the hunt over a bug
r3311 at cubic-pc (orig r5480): ruz | 2006-06-28 04:05:49 +0400
* minor formatting
r3491 at cubic-pc (orig r5482): ruz | 2006-06-29 01:25:18 +0400
* add tests for unsafe mailgate commands
* fix bugs that were introduced during Email.pm refactoring
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Interface/Email.pm (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Interface/Email.pm Wed Jun 28 17:39:57 2006
@@ -588,11 +588,11 @@
return ( -75, "RT couldn't find the queue: " . $args{'queue'}, undef );
}
- # Authentication Level ($AuthStat)
- # -1 - Get out. this user has been explicitly declined
- # 0 - User may not do anything (Not used at the moment)
- # 1 - Normal user
- # 2 - User is allowed to specify status updates etc. a la enhanced-mailgate
+ # Authentication Level ($AuthStat)
+ # -1 - Get out. this user has been explicitly declined
+ # 0 - User may not do anything (Not used at the moment)
+ # 1 - Normal user
+ # 2 - User is allowed to specify status updates etc. a la enhanced-mailgate
my ( $CurrentUser, $AuthStat, $error );
# Initalize AuthStat so comparisons work correctly
@@ -606,21 +606,22 @@
# Since this needs loading, no matter what
foreach (@RT::MailPlugins) {
- my ($Code, $Class, $NewAuthStat);
+ my ($Code, $NewAuthStat);
if ( ref($_) eq "CODE" ) {
$Code = $_;
} else {
- $Class = "RT::Interface::Email::" . $_
- unless $_ =~ /^RT::Interface::Email::/;
+ my $Class = $_;
+ $Class = "RT::Interface::Email::" . $Class
+ unless $Class =~ /^RT::Interface::Email::/;
$Class->require or
do { $RT::Logger->error("Couldn't load $Class: $@"); next };
- }
+
no strict 'refs';
- if ( !defined( $Code = *{ $Class . "::GetCurrentUser" }{CODE} ) ) {
- $RT::Logger->crit( "No GetCurrentUser code found in $Class module");
+ unless ( defined( $Code = *{ $Class . "::GetCurrentUser" }{CODE} ) ) {
+ $RT::Logger->crit( "No 'GetCurrentUser' function found in '$Class' module");
next;
}
-
+ }
foreach my $action (@actions) {
( $CurrentUser, $NewAuthStat ) = $Code->(
@@ -699,8 +700,7 @@
my $Ticket = RT::Ticket->new($CurrentUser);
- if (( !$SystemTicket || !$SystemTicket->Id )
- && grep /^(comment|correspond)$/, @actions )
+ if ( !$args{'ticket'} && grep /^(comment|correspond)$/, @actions )
{
my @Cc;
@@ -731,7 +731,8 @@
return ( 0, "Ticket creation failed: $ErrStr", $Ticket );
}
-# strip comments&corresponds from the actions we don't need to record them if we've created the ticket just now
+ # strip comments&corresponds from the actions we don't need
+ # to record them if we've created the ticket just now
@actions = grep !/^(comment|correspond)$/, @actions;
$args{'ticket'} = $id;
@@ -756,13 +757,8 @@
# If the action is comment, add a comment.
if ( $action =~ /^(?:comment|correspond)$/i ) {
- my ( $status, $msg );
- if ( $action =~ /^correspond$/i ) {
- ( $status, $msg )
- = $Ticket->Correspond( MIMEObj => $Message );
- } else {
- ( $status, $msg ) = $Ticket->Comment( MIMEObj => $Message );
- }
+ my $method = ucfirst lc $action;
+ my ( $status, $msg ) = $Ticket->$method( MIMEObj => $Message );
unless ($status) {
#Warn the sender that we couldn't actually submit the comment.
@@ -772,16 +768,17 @@
Explanation => $msg,
MIMEObj => $Message
);
- return ( 0, "Message not recorded", $Ticket );
+ return ( 0, "Message not recorded: $msg", $Ticket );
}
} elsif ($RT::UnsafeEmailCommands) {
- return _RunUnsafeAction(
+ my ( $status, $msg ) = _RunUnsafeAction(
Action => $action,
ErrorsTo => $ErrorsTo,
Message => $Message,
Ticket => $Ticket,
- CurrentUser => $CurrentUser
+ CurrentUser => $CurrentUser,
);
+ return ($status, $msg, $Ticket) unless $status == 1;
}
}
return ( 1, "Success", $Ticket );
@@ -806,7 +803,7 @@
Explanation => $msg,
MIMEObj => $args{'Message'}
);
- return ( 0, "Ticket not taken", $args{'Ticket'} );
+ return ( 0, "Ticket not taken" );
}
} elsif ( $args{'Action'} =~ /^resolve$/i ) {
my ( $status, $msg ) = $args{'Ticket'}->SetStatus('resolved');
@@ -819,10 +816,12 @@
Explanation => $msg,
MIMEObj => $args{'Message'}
);
- return ( 0, "Ticket not resolved", $args{'Ticket'} );
+ return ( 0, "Ticket not resolved" );
}
+ } else {
+ return ( 0, "Not supported unsafe action $args{'Action'}", $args{'Ticket'} );
}
- return ( 0, 'Unknown action' );
+ return ( 1, "Success" );
}
=head2 _NoAuthorizedUserFound
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Link_Overlay.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Link_Overlay.pm (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Link_Overlay.pm Wed Jun 28 17:39:57 2006
@@ -268,8 +268,8 @@
=cut
sub TargetObj {
- my $self = shift;
- return $self->TargetURI->Object;
+ my $self = shift;
+ return $self->TargetURI->Object;
}
# }}}
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Links_Overlay.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Links_Overlay.pm (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Links_Overlay.pm Wed Jun 28 17:39:57 2006
@@ -154,19 +154,17 @@
my $self = shift;
my $Link = $self->SUPER::Next();
- if ((defined($Link)) and (ref($Link))) {
- # Skip links to local objects thast are deleted
- if ($Link->TargetURI->IsLocal and UNIVERSAL::isa($Link->TargetObj,"RT::Ticket")
- and $Link->TargetObj->__Value('status') eq "deleted") {
- return $self->Next;
- } elsif ($Link->BaseURI->IsLocal and UNIVERSAL::isa($Link->BaseObj,"RT::Ticket")
- and $Link->BaseObj->__Value('status') eq "deleted") {
- return $self->Next;
- } else {
- return $Link;
- }
+ return $Link unless $Link && ref $Link;
+
+ # Skip links to local objects thast are deleted
+ if ( $Link->TargetURI->IsLocal and UNIVERSAL::isa($Link->TargetObj,"RT::Ticket")
+ and $Link->TargetObj->__Value('status') eq "deleted") {
+ return $self->Next;
+ } elsif ($Link->BaseURI->IsLocal and UNIVERSAL::isa($Link->BaseObj,"RT::Ticket")
+ and $Link->BaseObj->__Value('status') eq "deleted") {
+ return $self->Next;
} else {
- return undef;
+ return $Link;
}
}
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Record.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Record.pm (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Record.pm Wed Jun 28 17:39:57 2006
@@ -817,7 +817,10 @@
elsif ($RT::DropLongAttachments) {
# drop the attachment on the floor
- $RT::Logger->info( "$self: Dropped an attachment of size " . length($Body) . "\n" . "It started: " . substr( $Body, 0, 60 ) . "\n" );
+ $RT::Logger->info( "$self: Dropped an attachment of size "
+ . length($Body) . "\n"
+ . "It started: " . substr( $Body, 0, 60 ) . "\n"
+ );
return ("none", "Large attachment dropped" );
}
}
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/base.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/base.pm (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/base.pm Wed Jun 28 17:39:57 2006
@@ -81,12 +81,8 @@
my $self = shift;
my $obj = shift;
$self->{'uri'} = "unknown-object:".ref($obj);
-
-
}
-
-
sub ParseURI {
my $self = shift;
my $uri = shift;
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/fsck_com_rt.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/fsck_com_rt.pm (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/URI/fsck_com_rt.pm Wed Jun 28 17:39:57 2006
@@ -128,7 +128,7 @@
sub URIForObject {
my $self = shift;
my $obj = shift;
- return ($self->LocalURIPrefix."/".$self->ObjectType($obj)."/". $obj->Id);
+ return ($self->LocalURIPrefix ."/". $self->ObjectType($obj) ."/". $obj->Id);
}
@@ -143,12 +143,12 @@
my $self = shift;
my $uri = shift;
- if ( $uri =~ /^(\d+)$/ ) {
+ if ( $uri =~ /^\d+$/ ) {
my $ticket = RT::Ticket->new( $self->CurrentUser );
- $ticket->Load($uri);
+ $ticket->Load( $uri );
$self->{'uri'} = $ticket->URI;
$self->{'object'} = $ticket;
- return($ticket->id);
+ return ($ticket->id);
}
else {
$self->{'uri'} = $uri;
@@ -156,9 +156,8 @@
#If it's a local URI, load the ticket object and return its URI
if ( $self->IsLocal ) {
-
my $local_uri_prefix = $self->LocalURIPrefix;
- if ( $self->{'uri'} =~ /^$local_uri_prefix\/(.*?)\/(\d+)$/i ) {
+ if ( $self->{'uri'} =~ /^\Q$local_uri_prefix\E\/(.*?)\/(\d+)$/i ) {
my $type = $1;
my $id = $2;
@@ -192,9 +191,9 @@
sub IsLocal {
my $self = shift;
- my $local_uri_prefix = $self->LocalURIPrefix;
- if ($self->{'uri'} =~ /^$local_uri_prefix/i) {
- return 1;
+ my $local_uri_prefix = $self->LocalURIPrefix;
+ if ( $self->{'uri'} =~ /^\Q$local_uri_prefix/i ) {
+ return 1;
}
else {
return undef;
Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/06mailgateway.t
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/06mailgateway.t (original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/06mailgateway.t Wed Jun 28 17:39:57 2006
@@ -52,16 +52,19 @@
=cut
use strict;
-use Test::More tests => 57;
+use Test::More tests => 104;
+
use RT;
RT::LoadConfig();
RT::Init();
use RT::I18N;
+
no warnings 'once';
-my $url = "http://localhost:".$RT::WebPort.$RT::WebPath."/";
+my $url = join( ':', grep $_, "http://localhost", $RT::WebPort ) . $RT::WebPath ."/";
# Make sure that when we call the mailgate wrong, it tempfails
+$! = '';
ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url http://this.test.for.non-connection.is.expected.to.generate.an.error"), "Opened the mailgate - The error below is expected - $@");
print MAIL <<EOF;
From: root\@localhost
@@ -78,7 +81,8 @@
# {{{ Test new ticket creation by root who is privileged and superuser
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --debug --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --debug --url $url --queue general --action correspond"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: root\@localhost
To: rt\@$RT::rtname
@@ -106,7 +110,8 @@
# {{{This is a test of new ticket creation as an unknown user
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: doesnotexist\@$RT::rtname
To: rt\@$RT::rtname
@@ -142,7 +147,8 @@
ok ($val, "Granted everybody the right to create tickets - $msg");
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: doesnotexist\@$RT::rtname
To: rt\@$RT::rtname
@@ -175,7 +181,8 @@
#($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
#ok ($val, "Granted everybody the right to create tickets - $msg");
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: doesnotexist-2\@$RT::rtname
To: rt\@$RT::rtname
@@ -200,7 +207,8 @@
($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'ReplyToTicket');
ok ($val, "Granted everybody the right to reply to tickets - $msg");
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: doesnotexist-2\@$RT::rtname
To: rt\@$RT::rtname
@@ -226,7 +234,8 @@
#($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
#ok ($val, "Granted everybody the right to create tickets - $msg");
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: doesnotexist-3\@$RT::rtname
To: rt\@$RT::rtname
@@ -251,7 +260,8 @@
($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CommentOnTicket');
ok ($val, "Granted everybody the right to reply to tickets - $msg");
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: doesnotexist-3\@$RT::rtname
To: rt\@$RT::rtname
@@ -292,7 +302,8 @@
Encoding => 'base64');
# Create a ticket with a binary attachment
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
$entity->print(\*MAIL);
@@ -350,7 +361,8 @@
# {{{ Simple I18N testing
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: root\@localhost
@@ -384,7 +396,8 @@
ok($unitick->Transactions->First->Attachments->First->Content =~ /$unistring/i, $unitick->Id." appears to be unicode ". $unitick->Transactions->First->Attachments->First->Id);
# supposedly I18N fails on the second message sent in.
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: root\@localhost
@@ -423,20 +436,28 @@
($val,$msg) = $g->PrincipalObj->RevokeRight(Right => 'CreateTicket');
ok ($val, $msg);
-=for later
+##=for later
+
+SKIP: {
+skip "Advanced mailgate actions require an unsafe configuration", 47 unless $RT::UnsafeEmailCommands;
-TODO: {
+#create new queue to be shure we don't mess with rights
+use RT::Queue;
+my $queue = RT::Queue->new($RT::SystemUser);
+my ($qid) = $queue->Create( Name => 'ext-mailgate');
+ok( $qid, 'queue created for ext-mailgate tests' );
# {{{ Check take and resolve actions
# create ticket that is owned by nobody
use RT::Ticket;
$tick = RT::Ticket->new($RT::SystemUser);
-my ($id) = $tick->Create( Queue => 'general', Subject => 'test');
+my ($id) = $tick->Create( Queue => 'ext-mailgate', Subject => 'test');
ok( $id, 'new ticket created' );
is( $tick->Owner, $RT::Nobody->Id, 'owner of the new ticket is nobody' );
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action take"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: root\@localhost
Subject: [$RT::rtname \#$id] test
@@ -453,14 +474,15 @@
# check that there is no text transactions writen
is( $tick->Transactions->Count, 2, 'no superfluous transactions');
+my $status;
($status, $msg) = $tick->SetOwner( $RT::Nobody->Id, 'Force' );
ok( $status, 'successfuly changed owner: '. ($msg||'') );
is( $tick->Owner, $RT::Nobody->Id, 'set owner back to nobody');
- local $TODO = "Advanced mailgate actions require an unsafe configuration";
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $RT::WebURL --queue general --action take-correspond"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $RT::WebURL --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $@");
print MAIL <<EOF;
From: root\@localhost
Subject: [$RT::rtname \#$id] correspondence
@@ -470,17 +492,21 @@
close (MAIL);
is ($? >> 8, 0, "The mail gateway exited normally");
+DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
$tick = RT::Ticket->new($RT::SystemUser);
$tick->Load( $id );
-is( $tick->Id, $id, 'load correct ticket');
+is( $tick->Id, $id, "load correct ticket #$id");
is( $tick->OwnerObj->EmailAddress, 'root at localhost', 'successfuly take ticket via email');
my $txns = $tick->Transactions;
$txns->Limit( FIELD => 'Type', VALUE => 'Correspond');
-is( $txns->Last->Subject, "[$RT::rtname \#$id] correspondence", 'successfuly add correspond within take via email' );
+$txns->OrderBy( FIELD => 'id', ORDER => 'DESC' );
# +1 because of auto open
is( $tick->Transactions->Count, 6, 'no superfluous transactions');
+is( $txns->First->Subject, "[$RT::rtname \#$id] correspondence", 'successfuly add correspond within take via email' );
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action resolve --debug"), "Opened the mailgate - $@");
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action resolve --debug"), "Opened the mailgate - $!");
print MAIL <<EOF;
From: root\@localhost
Subject: [$RT::rtname \#$id] test
@@ -497,10 +523,115 @@
is( $tick->Status, 'resolved', 'successfuly resolved ticket via email');
is( $tick->Transactions->Count, 7, 'no superfluous transactions');
-};
+use RT::User;
+my $user = RT::User->new( $RT::SystemUser );
+my ($uid) = $user->Create( Name => 'ext-mailgate',
+ EmailAddress => 'ext-mailgate at localhost',
+ Privileged => 1,
+ Password => 'qwe123',
+ );
+ok( $uid, 'user created for ext-mailgate tests' );
+ok( !$user->HasRight( Right => 'OwnTicket', Object => $queue ), "User can't own ticket" );
+
+$tick = RT::Ticket->new($RT::SystemUser);
+($id) = $tick->Create( Queue => $qid, Subject => 'test' );
+ok( $id, 'create new ticket' );
+
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take"), "Opened the mailgate - $!");
+print MAIL <<EOF;
+From: ext-mailgate\@localhost
+Subject: [example.com \#$id] test
+
+EOF
+close (MAIL);
+is ( $? >> 8, 0, "mailgate exited normally" );
+DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+cmp_ok( $tick->Owner, '!=', $user->id, "we didn't change owner" );
+
+($status, $msg) = $user->PrincipalObj->GrantRight( Object => $queue, Right => 'ReplyToTicket' );
+ok( $status, "successfuly granted right: $msg" );
+my $ace_id = $status;
+ok( $user->HasRight( Right => 'ReplyToTicket', Object => $tick ), "User can reply to ticket" );
+
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action correspond-take"), "Opened the mailgate - $!");
+print MAIL <<EOF;
+From: ext-mailgate\@localhost
+Subject: [example.com \#$id] test
+
+correspond-take
+EOF
+close (MAIL);
+is ( $? >> 8, 0, "mailgate exited normally" );
+DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+cmp_ok( $tick->Owner, '!=', $user->id, "we didn't change owner" );
+is( $tick->Transactions->Count, 3, "one transactions added" );
+
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $!");
+print MAIL <<EOF;
+From: ext-mailgate\@localhost
+Subject: [example.com \#$id] test
+
+correspond-take
+EOF
+close (MAIL);
+is ( $? >> 8, 0, "mailgate exited normally" );
+DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+cmp_ok( $tick->Owner, '!=', $user->id, "we didn't change owner" );
+is( $tick->Transactions->Count, 3, "no transactions added, user can't take ticket first" );
+
+# revoke ReplyToTicket right
+use RT::ACE;
+my $ace = RT::ACE->new($RT::SystemUser);
+$ace->Load( $ace_id );
+$ace->Delete;
+my $acl = RT::ACL->new($RT::SystemUser);
+$acl->Limit( FIELD => 'RightName', VALUE => 'ReplyToTicket' );
+$acl->LimitToObject( $RT::System );
+while( my $ace = $acl->Next ) {
+ $ace->Delete;
+}
+
+ok( !$user->HasRight( Right => 'ReplyToTicket', Object => $tick ), "User can't reply to ticket any more" );
+
+
+my $group = RT::Group->new( $RT::SystemUser );
+ok( $group->LoadQueueRoleGroup( Queue => $qid, Type=> 'Owner' ), "load queue owners role group" );
+$ace = RT::ACE->new( $RT::SystemUser );
+($ace_id, $msg) = $group->PrincipalObj->GrantRight( Right => 'ReplyToTicket', Object => $queue );
+ok( $ace_id, "Granted queue owners role group with ReplyToTicket right" );
+
+($status, $msg) = $user->PrincipalObj->GrantRight( Object => $queue, Right => 'OwnTicket' );
+ok( $status, "successfuly granted right: $msg" );
+($status, $msg) = $user->PrincipalObj->GrantRight( Object => $queue, Right => 'TakeTicket' );
+ok( $status, "successfuly granted right: $msg" );
+
+$! = '';
+ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $!");
+print MAIL <<EOF;
+From: ext-mailgate\@localhost
+Subject: [example.com \#$id] test
+
+take-correspond with reply right granted to owner role
+EOF
+close (MAIL);
+is ( $? >> 8, 0, "mailgate exited normally" );
+DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+$tick->Load( $id );
+is( $tick->Owner, $user->id, "we changed owner" );
+ok( $user->HasRight( Right => 'ReplyToTicket', Object => $tick ), "owner can reply to ticket" );
+is( $tick->Transactions->Count, 5, "transactions added" );
-=cut
# }}}
+};
+
1;
+
More information about the Rt-commit
mailing list