[rt-commit] [svn] r551 - in rt/branches/rt-3.1/lib/RT: . Condition
URI
jesse at fsck.com
jesse at fsck.com
Thu Mar 11 22:40:55 EST 2004
Author: jesse
Date: Thu Mar 11 22:40:50 2004
New Revision: 551
Modified:
rt/branches/rt-3.1/lib/RT/Condition/OwnerChange.pm
rt/branches/rt-3.1/lib/RT/Link_Overlay.pm
rt/branches/rt-3.1/lib/RT/Record.pm
rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm
rt/branches/rt-3.1/lib/RT/URI/fsck_com_rt.pm
Log:
RT Links and URIs can now work with any RT object, not just tickets
Modified: rt/branches/rt-3.1/lib/RT/Condition/OwnerChange.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Condition/OwnerChange.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Condition/OwnerChange.pm Thu Mar 11 22:40:50 2004
@@ -50,9 +50,7 @@
CustomIsApplicableCode => '',
CustomPrepareCode => 'return 1',
CustomCommitCode => '
- $RT::Logger->crit("Before, prio is ".$self->TicketObj->Priority);
$self->TicketObj->SetPriority($self->TicketObj->Priority+1);
- $RT::Logger->crit("After, prio is ".$self->TicketObj->Priority);
return(1);
',
Template => 'Blank'
Modified: rt/branches/rt-3.1/lib/RT/Link_Overlay.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Link_Overlay.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Link_Overlay.pm Thu Mar 11 22:40:50 2004
@@ -87,8 +87,6 @@
. $base->Scheme
. "' into a URI\n" );
- #use Data::Dumper;
- #$RT::Logger->warning(scalar Dumper $base);
return (undef);
}
@@ -100,8 +98,6 @@
. $args{'Target'} . " - "
. "' into a URI\n" );
- #use Data::Dumper;
- #$RT::Logger->warning(scalar Dumper $target);
return (undef);
}
Modified: rt/branches/rt-3.1/lib/RT/Record.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Record.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Record.pm Thu Mar 11 22:40:50 2004
@@ -460,6 +460,25 @@
# }}}
+# {{{ sub URI
+
+=head2 URI
+
+Returns this record's URI
+
+=cut
+
+sub URI {
+ my $self = shift;
+ my $uri = RT::URI::fsck_com_rt->new($self->CurrentUser);
+ return($uri->URIForObject($self));
+}
+
+# }}}
+
+
+
+
=head2 SQLType attribute
Modified: rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm Thu Mar 11 22:40:50 2004
@@ -2562,14 +2562,18 @@
my $t3 = RT::Ticket->new($RT::SystemUser);
my ($id3, $trans, $msg3) = $t3->Create(Subject => 'DepTest3', Queue => 'general', Type => 'approval');
ok($id3, "Created dep test 3 - $msg3");
+my ($addid, $addmsg);
+ok (($addid, $addmsg) =$t1->AddLink( Type => 'DependsOn', Target => $t2->id));
+ok ($addid, $addmsg);
+ok (($addid, $addmsg) =$t1->AddLink( Type => 'DependsOn', Target => $t3->id));
-ok ($t1->AddLink( Type => 'DependsOn', Target => $t2->id));
-ok ($t1->AddLink( Type => 'DependsOn', Target => $t3->id));
-
+ok ($addid, $addmsg);
ok ($t1->HasUnresolvedDependencies, "Ticket ".$t1->Id." has unresolved deps");
ok (!$t1->HasUnresolvedDependencies( Type => 'blah' ), "Ticket ".$t1->Id." has no unresolved blahs");
ok ($t1->HasUnresolvedDependencies( Type => 'approval' ), "Ticket ".$t1->Id." has unresolved approvals");
ok (!$t2->HasUnresolvedDependencies, "Ticket ".$t2->Id." has no unresolved deps");
+;
+
my ($rid, $rmsg)= $t1->Resolve();
ok(!$rid, $rmsg);
ok($t2->Resolve);
@@ -2844,6 +2848,7 @@
Silent => undef,
@_ );
+
unless ( $self->CurrentUserHasRight('ModifyTicket') ) {
return ( 0, $self->loc("Permission Denied") );
}
@@ -2859,13 +2864,13 @@
}
elsif ( $args{'Base'} ) {
$args{'Target'} = $self->URI();
- $remote_link = $args{'Base'};
- $direction = 'Target';
+ $remote_link = $args{'Base'};
+ $direction = 'Target';
}
elsif ( $args{'Target'} ) {
$args{'Base'} = $self->URI();
- $remote_link = $args{'Target'};
- $direction='Base';
+ $remote_link = $args{'Target'};
+ $direction = 'Base';
}
else {
return ( 0, $self->loc('Either base or target must be specified') );
@@ -2889,11 +2894,12 @@
# Storing the link in the DB.
my $link = RT::Link->new( $self->CurrentUser );
- my ($linkid) = $link->Create( Target => $args{Target},
+ my ($linkid, $linkmsg) = $link->Create( Target => $args{Target},
Base => $args{Base},
Type => $args{Type} );
unless ($linkid) {
+ $RT::Logger->error("Link could not be created: ".$linkmsg);
return ( 0, $self->loc("Link could not be created") );
}
@@ -2917,22 +2923,6 @@
return ( $Trans, $self->loc( "Link created ([_1])", $TransString ) );
}
-}
-
-# }}}
-
-# {{{ sub URI
-
-=head2 URI
-
-Returns this ticket's URI
-
-=cut
-
-sub URI {
- my $self = shift;
- my $uri = RT::URI::fsck_com_rt->new($self->CurrentUser);
- return($uri->URIForObject($self));
}
# }}}
Modified: rt/branches/rt-3.1/lib/RT/URI/fsck_com_rt.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/URI/fsck_com_rt.pm (original)
+++ rt/branches/rt-3.1/lib/RT/URI/fsck_com_rt.pm Thu Mar 11 22:40:50 2004
@@ -34,9 +34,9 @@
-=head2 LocalURIPrefix
+=head2 LocalURIPrefix
-Returns the prefix for a local ticket URI
+Returns the prefix for a local URI.
=begin testing
@@ -53,7 +53,7 @@
ok ($uri->isa('RT::URI::base'), "It's an RT::URI::base");
ok ($uri->isa('RT::Base'), "It's an RT::Base");
-is ($uri->LocalURIPrefix , 'fsck.com-rt://example.com/ticket/');
+is ($uri->LocalURIPrefix , 'fsck.com-rt://example.com');
=end testing
@@ -63,99 +63,100 @@
sub LocalURIPrefix {
my $self = shift;
- my $prefix = $self->Scheme. "://$RT::Organization/ticket/";
+
+ my $prefix = $self->Scheme. "://$RT::Organization";
+
return ($prefix);
}
+=head2 ObjectType
+
+=cut
+
+sub ObjectType {
+ my $self = shift;
+ my $object = shift;
+ my $type = 'ticket';
+ if (ref($object) && (ref($object) ne 'RT::Ticket')) {
+ $type = ref($object);
+ }
+ return ($type);
+}
-=head2 URIForObject RT::Ticket
-Returns the RT URI for a local RT::Ticket object
+
+=head2 URIForObject RT::Record
+
+Returns the RT URI for a local RT::Record object
=begin testing
my $ticket = RT::Ticket->new($RT::SystemUser);
$ticket->Load(1);
my $uri = RT::URI::fsck_com_rt->new($ticket->CurrentUser);
-is($uri->LocalURIPrefix . "1" , $uri->URIForObject($ticket));
+is($uri->LocalURIPrefix. "/ticket/1" , $uri->URIForObject($ticket));
=end testing
=cut
sub URIForObject {
-
my $self = shift;
-
my $obj = shift;
- return ($self->LocalURIPrefix. $obj->Id);
+ return ($self->LocalURIPrefix."/".$self->ObjectType($obj)."/". $obj->Id);
}
-=head2 ParseObject $TicketObj
-
-When handed an RT::Ticekt object, figure out its URI
+=head2 ParseURI URI
+When handed an fsck.com-rt: URI, figures out things like whether its a local record and what its ID is
=cut
+sub ParseURI {
+ my $self = shift;
+ my $uri = shift;
-=head2 ParseURI URI
+ if ( $uri =~ /^(\d+)$/ ) {
+ my $ticket = RT::Ticket->new( $self->CurrentUser );
+ $ticket->Load($uri);
+ $self->{'uri'} = $ticket->URI;
+ $self->{'object'} = $ticket;
+ return($ticket->id);
+ }
+ else {
+ $self->{'uri'} = $uri;
+ }
-When handed an fsck.com-rt: URI, figures out things like whether its a local ticket
-and what its ID is
+ #If it's a local URI, load the ticket object and return its URI
+ if ( $self->IsLocal ) {
-=cut
+ my $local_uri_prefix = $self->LocalURIPrefix;
+ if ( $self->{'uri'} =~ /^$local_uri_prefix\/(.*?)\/(\d+)$/i ) {
+ my $type = $1;
+ my $id = $2;
+ if ( $type eq 'ticket' ) { $type = 'RT::Ticket' }
-sub ParseURI {
- my $self = shift;
- my $uri = shift;
-
- my $ticket;
-
- if ($uri =~ /^(\d+)$/) {
- $ticket = RT::Ticket->new($self->CurrentUser);
- $ticket->Load($uri);
- $self->{'uri'} = $ticket->URI;
- }
- else {
- $self->{'uri'} = $uri;
- }
-
-
-
- #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) {
- my $id = $1;
-
-
- $ticket = RT::Ticket->new( $self->CurrentUser );
- $ticket->Load($id);
+ # We can instantiate any RT::Record subtype. but not anything else
- #If we couldn't find a ticket, return undef.
- unless ( defined $ticket->Id ) {
- return undef;
- }
- } else {
- return undef;
- }
- }
-
- $self->{'object'} = $ticket;
- if ( UNIVERSAL::can( $ticket, 'Id' ) ) {
- return ( $ticket->Id );
- }
- else {
- return undef;
+ if ( UNIVERSAL::isa( $type, 'RT::Record' ) ) {
+ my $record = $type->new( $self->CurrentUser );
+ $record->Load($id);
+
+ if ( $record->Id ) {
+ $self->{'object'} = $record;
+ return ( $record->Id );
+ }
+ }
+
+ }
}
+ return undef;
}
=head2 IsLocal
@@ -194,7 +195,7 @@
=head2 Scheme
-Return the URI scheme for RT tickets
+Return the URI scheme for RT records
=cut
@@ -214,7 +215,7 @@
sub HREF {
my $self = shift;
- if ($self->IsLocal && $self->Object) {
+ if ($self->IsLocal && $self->Object && ($self->ObjectType eq 'ticket')) {
return ( $RT::WebURL . "Ticket/Display.html?id=".$self->Object->Id);
}
else {
@@ -231,7 +232,7 @@
sub AsString {
my $self = shift;
if ($self->IsLocal && $self->Object) {
- return $self->loc("ticket #[_1]", $self->Object->Id);
+ return $self->loc("[_1] #[_2]", $self->ObjectType, $self->Object->Id);
}
else {
return $self->URI;
More information about the Rt-commit
mailing list