-use File::Temp qw/tempfile/;
-my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt');
-my $link_scrips_orig = RT->Config->Get( 'LinkTransactionsRun1Scrip' );
-RT->Config->Set( 'LinkTransactionsRun1Scrip', 1 );
+my $filename = File::Spec->catfile( RT::Test->temp_directory, 'link_count' );
+open my $fh, '>', $filename or die $!;
+close $fh;
my $link_acl_checks_orig = RT->Config->Get( 'StrictLinkACL' );
RT->Config->Set( 'StrictLinkACL', 1);
my $link_acl_checks_orig = RT->Config->Get( 'StrictLinkACL' );
RT->Config->Set( 'StrictLinkACL', 1);
if (\$self->TransactionObj->Type eq 'AddLink') {
\$RT::Logger->debug("AddLink");
print \$file \$data+1, "\n";
if (\$self->TransactionObj->Type eq 'AddLink') {
\$RT::Logger->debug("AddLink");
print \$file \$data+1, "\n";
$Scrips->UnLimit;
while ( my $Scrip = $Scrips->Next ) {
$Scrip->Delete if $Scrip->Description and $Scrip->Description =~ /Add or Delete Link \d+/;
}
$Scrips->UnLimit;
while ( my $Scrip = $Scrips->Next ) {
$Scrip->Delete if $Scrip->Description and $Scrip->Description =~ /Add or Delete Link \d+/;
}
($id,$msg) = $scrip->Create( Description => "Add or Delete Link $$",
ScripCondition => $condition->id,
ScripAction => $action->id,
($id,$msg) = $scrip->Create( Description => "Add or Delete Link $$",
ScripCondition => $condition->id,
ScripAction => $action->id,
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id );
ok($id,$msg);
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id );
ok($id,$msg);
is($child->_Links('Base')->Count, 0, 'link was not created, no permissions');
is($child->_Links('Target')->Count, 0, 'link was not create, no permissions');
}
is($child->_Links('Base')->Count, 0, 'link was not created, no permissions');
is($child->_Links('Target')->Count, 0, 'link was not create, no permissions');
}
{
# on q2 we have no rights, but use checking one only on thing
RT->Config->Set( StrictLinkACL => 0 );
{
# on q2 we have no rights, but use checking one only on thing
RT->Config->Set( StrictLinkACL => 0 );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id );
ok($id,$msg);
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id );
ok($id,$msg);
is($child->_Links('Base')->Count, 1, 'link was created');
is($child->_Links('Target')->Count, 0, 'link was created only one');
is($child->_Links('Base')->Count, 1, 'link was created');
is($child->_Links('Target')->Count, 0, 'link was created only one');
- # no scrip run on second ticket accroding to config option
- is(link_count($filename), undef, "scrips ok");
+ # only one scrip run (on second ticket) since this is on a ticket Create txn
+ is(link_count($filename), 1, "scrips ok");
RT->Config->Set( StrictLinkACL => 1 );
}
($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket');
ok ($id,$msg);
RT->Config->Set( StrictLinkACL => 1 );
}
($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket');
ok ($id,$msg);
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
- is(link_count($filename), undef, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ is(link_count($filename), 0, "scrips ok");
+ $child->CurrentUser( RT->SystemUser );
is($child->_Links('Base')->Count, 0, 'link was not created, no permissions');
is($child->_Links('Target')->Count, 0, 'link was not create, no permissions');
}
is($child->_Links('Base')->Count, 0, 'link was not created, no permissions');
is($child->_Links('Target')->Count, 0, 'link was not create, no permissions');
}
{
# on q2 we have no rights, but use checking one only on thing
RT->Config->Set( StrictLinkACL => 0 );
{
# on q2 we have no rights, but use checking one only on thing
RT->Config->Set( StrictLinkACL => 0 );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
my ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id );
ok($id,$msg);
my $child = RT::Ticket->new( $creator );
- is(link_count($filename), 1, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ is(link_count($filename), 2, "scrips ok");
+ $child->CurrentUser( RT->SystemUser );
is($child->_Links('Base')->Count, 1, 'link was created');
is($child->_Links('Target')->Count, 0, 'link was created only one');
$child->CurrentUser( $creator );
# turn off feature and try to delete link, we should fail
RT->Config->Set( StrictLinkACL => 1 );
is($child->_Links('Base')->Count, 1, 'link was created');
is($child->_Links('Target')->Count, 0, 'link was created only one');
$child->CurrentUser( $creator );
# turn off feature and try to delete link, we should fail
RT->Config->Set( StrictLinkACL => 1 );
- is(link_count($filename), 1, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ is(link_count($filename), 0, "scrips ok");
+ $child->CurrentUser( RT->SystemUser );
$child->_Links('Base')->_DoCount;
is($child->_Links('Base')->Count, 1, 'link was not deleted');
$child->CurrentUser( $creator );
$child->_Links('Base')->_DoCount;
is($child->_Links('Base')->Count, 1, 'link was not deleted');
$child->CurrentUser( $creator );
RT->Config->Set( StrictLinkACL => 0 );
($id, $msg) = $child->DeleteLink(Type => 'MemberOf', Target => $parent->id);
ok($id, $msg);
RT->Config->Set( StrictLinkACL => 0 );
($id, $msg) = $child->DeleteLink(Type => 'MemberOf', Target => $parent->id);
ok($id, $msg);
- is(link_count($filename), 0, "scrips ok");
- $child->CurrentUser( $RT::SystemUser );
+ is(link_count($filename), -2, "scrips ok");
+ $child->CurrentUser( RT->SystemUser );
$child->_Links('Base')->_DoCount;
is($child->_Links('Base')->Count, 0, 'link was deleted');
RT->Config->Set( StrictLinkACL => 1 );
$child->_Links('Base')->_DoCount;
is($child->_Links('Base')->Count, 0, 'link was deleted');
RT->Config->Set( StrictLinkACL => 1 );
($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id);
ok ($id,$msg);
($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id);
ok ($id,$msg);
- my ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id);
+ warning_like {
+ ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id);
+ } qr/Can't link a ticket to itself/;
($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id);
ok ($id, $msg);
($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id);
ok ($id, $msg);
($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
-is(link_count($filename), 1, "scrips ok");
-($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => -1);
-ok(!$id,$msg);
+is(link_count($filename), 2, "scrips ok");
+
+warnings_like {
+ ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => -1);
+} [
+ qr/Could not determine a URI scheme for -1/,
+];
+
my $transactions = $ticket2->Transactions;
$transactions->Limit( FIELD => 'Type', VALUE => 'AddLink' );
my $transactions = $ticket2->Transactions;
$transactions->Limit( FIELD => 'Type', VALUE => 'AddLink' );
$transactions = $ticket2->Transactions;
$transactions->Limit( FIELD => 'Type', VALUE => 'DeleteLink' );
is( $transactions->Count, 1, "Transaction found in other ticket" );
is( $transactions->First->Field , 'ReferredToBy');
is( $transactions->First->OldValue , $ticket->URI );
$transactions = $ticket2->Transactions;
$transactions->Limit( FIELD => 'Type', VALUE => 'DeleteLink' );
is( $transactions->Count, 1, "Transaction found in other ticket" );
is( $transactions->First->Field , 'ReferredToBy');
is( $transactions->First->OldValue , $ticket->URI );
($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
ok($id,$msg);
is(link_count($filename), 2, "scrips ok");
($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id);
ok($id,$msg);
($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
ok($id,$msg);
is(link_count($filename), 2, "scrips ok");
($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id);
ok($id,$msg);
# tests for silent behaviour
($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id, Silent => 1);
# tests for silent behaviour
($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id, Silent => 1);
}
($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id, SilentBase => 1);
ok($id,$msg);
}
($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id, SilentBase => 1);
ok($id,$msg);
($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id, SilentTarget => 1);
ok($id,$msg);
($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id, SilentTarget => 1);
ok($id,$msg);
}
($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id, SilentTarget => 1);
ok($id,$msg);
}
($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id, SilentTarget => 1);
ok($id,$msg);
$Scrips->Limit( FIELD => 'Description', OPERATOR => 'STARTSWITH', VALUE => 'Add or Delete Link ');
while ( my $s = $Scrips->Next ) { $s->Delete };
}
$Scrips->Limit( FIELD => 'Description', OPERATOR => 'STARTSWITH', VALUE => 'Add or Delete Link ');
while ( my $s = $Scrips->Next ) { $s->Delete };
}
($id,$msg) = $link->Create( Base => $ticket->URI, Target => $ticket2->URI, Type => 'MyLinkType' );
ok($id, $msg);
ok($link->LocalBase == $ticket->id, "LocalBase set correctly");
($id,$msg) = $link->Create( Base => $ticket->URI, Target => $ticket2->URI, Type => 'MyLinkType' );
ok($id, $msg);
ok($link->LocalBase == $ticket->id, "LocalBase set correctly");