diff options
author | ivan <ivan> | 2008-03-02 04:06:06 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-03-02 04:06:06 +0000 |
commit | 9c68254528b6f2c7d8c1921b452fa56064783782 (patch) | |
tree | 09623ba39355e74f1cff2f3c35b7347bd309f306 /rt/lib/RT/Interface/Web.pm | |
parent | ef20b2b6b1feb47ad02b5ff7525f1a0fd11d0fa4 (diff) |
import rt 3.4.6
Diffstat (limited to 'rt/lib/RT/Interface/Web.pm')
-rw-r--r-- | rt/lib/RT/Interface/Web.pm | 207 |
1 files changed, 58 insertions, 149 deletions
diff --git a/rt/lib/RT/Interface/Web.pm b/rt/lib/RT/Interface/Web.pm index 16945ab07..8bc840ba4 100644 --- a/rt/lib/RT/Interface/Web.pm +++ b/rt/lib/RT/Interface/Web.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC # <jesse@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) @@ -22,9 +22,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301 or visit their web page on the internet at -# http://www.gnu.org/copyleft/gpl.html. +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # # CONTRIBUTION SUBMISSION POLICY: @@ -64,13 +62,10 @@ use_ok(RT::Interface::Web); =cut +package RT::Interface::Web; use strict; -use warnings; -package RT::Interface::Web; -use HTTP::Date; -use RT::SavedSearches; -use URI; + # {{{ EscapeUTF8 @@ -132,7 +127,7 @@ sub WebCanonicalizeInfo { my $user; if ( defined $ENV{'REMOTE_USER'} ) { - $user = lc ( $ENV{'REMOTE_USER'} ) if( length($ENV{'REMOTE_USER'}) ); + $user = lc ( $ENV{'REMOTE_USER'} ) if( length($ENV{'REMOTE_USER'}) ); } return $user; @@ -156,14 +151,14 @@ sub WebExternalAutoInfo { $user_info{'Privileged'} = 1; if ($^O !~ /^(?:riscos|MacOS|MSWin32|dos|os2)$/) { - # Populate fields with information from Unix /etc/passwd + # Populate fields with information from Unix /etc/passwd - my ($comments, $realname) = (getpwnam($user))[5, 6]; - $user_info{'Comments'} = $comments if defined $comments; - $user_info{'RealName'} = $realname if defined $realname; + my ($comments, $realname) = (getpwnam($user))[5, 6]; + $user_info{'Comments'} = $comments if defined $comments; + $user_info{'RealName'} = $realname if defined $realname; } elsif ($^O eq 'MSWin32' and eval 'use Net::AdminMisc; 1') { - # Populate fields with information from NT domain controller + # Populate fields with information from NT domain controller } # and return the wad of stuff @@ -173,57 +168,8 @@ sub WebExternalAutoInfo { # }}} - -=head2 Redirect URL - -This routine ells the current user's browser to redirect to URL. -Additionally, it unties the user's currently active session, helping to avoid -A bug in Apache::Session 1.81 and earlier which clobbers sessions if we try to use -a cached DBI statement handle twice at the same time. - -=cut - - -sub Redirect { - my $redir_to = shift; - untie $HTML::Mason::Commands::session; - my $uri = URI->new($redir_to); - my $server_uri = URI->new($RT::WebURL); - - # If the user is coming in via a non-canonical - # hostname, don't redirect them to the canonical host, - # it will just upset them (and invalidate their credentials) - if ($uri->host eq $server_uri->host && - $uri->port eq $server_uri->port) { - $uri->host($ENV{'HTTP_HOST'}); - $uri->port($ENV{'SERVER_PORT'}); - } - - $HTML::Mason::Commands::m->redirect($uri->canonical); - $HTML::Mason::Commands::m->abort; -} - - -=head2 StaticFileHeaders - -Send the browser a few headers to try to get it to (somewhat agressively) -cache RT's static Javascript and CSS files. - -This routine could really use _accurate_ heuristics. (XXX TODO) - -=cut - -sub StaticFileHeaders { - # Expire things in a month. - $HTML::Mason::Commands::r->headers_out->{'Expires'} = HTTP::Date::time2str( time() + 2592000 ); - - # Last modified at server start time - $HTML::Mason::Commands::r->headers_out->{'Last-Modified'} = HTTP::Date::time2str($^T); - -} - - package HTML::Mason::Commands; +use strict; use vars qw/$r $m %session/; @@ -248,8 +194,8 @@ sub loc { return ($u->loc(@_)); } else { - # pathetic case -- SystemUser is gone. - return $_[0]; + # pathetic case -- SystemUser is gone. + return $_[0]; } } @@ -375,12 +321,13 @@ sub CreateTicket { MIMEObj => $MIMEObj ); foreach my $arg (keys %ARGS) { - next if $arg =~ /-(?:Magic|Category)$/; + my $cfid = $1; + next if ($arg =~ /-Magic$/); + #Object-RT::Ticket--CustomField-3-Values if ($arg =~ /^Object-RT::Transaction--CustomField-/) { $create_args{$arg} = $ARGS{$arg}; } - # Object-RT::Ticket--CustomField-3-Values elsif ($arg =~ /^Object-RT::Ticket--CustomField-(\d+)(.*?)$/) { my $cfid = $1; my $cf = RT::CustomField->new( $session{'CurrentUser'}); @@ -411,42 +358,42 @@ sub CreateTicket { my (@dependson, @dependedonby, @parents, @children, @refersto, @referredtoby); foreach my $luri ( split ( / /, $ARGS{"new-DependsOn"} ) ) { - $luri =~ s/\s*$//; # Strip trailing whitespace - push @dependson, $luri; + $luri =~ s/\s*$//; # Strip trailing whitespace + push @dependson, $luri; } $create_args{'DependsOn'} = \@dependson; foreach my $luri ( split ( / /, $ARGS{"DependsOn-new"} ) ) { - push @dependedonby, $luri; + push @dependedonby, $luri; } $create_args{'DependedOnBy'} = \@dependedonby; foreach my $luri ( split ( / /, $ARGS{"new-MemberOf"} ) ) { - $luri =~ s/\s*$//; # Strip trailing whitespace - push @parents, $luri; + $luri =~ s/\s*$//; # Strip trailing whitespace + push @parents, $luri; } $create_args{'Parents'} = \@parents; foreach my $luri ( split ( / /, $ARGS{"MemberOf-new"} ) ) { - push @children, $luri; + push @children, $luri; } $create_args{'Children'} = \@children; foreach my $luri ( split ( / /, $ARGS{"new-RefersTo"} ) ) { - $luri =~ s/\s*$//; # Strip trailing whitespace - push @refersto, $luri; + $luri =~ s/\s*$//; # Strip trailing whitespace + push @refersto, $luri; } $create_args{'RefersTo'} = \@refersto; foreach my $luri ( split ( / /, $ARGS{"RefersTo-new"} ) ) { - push @referredtoby, $luri; + push @referredtoby, $luri; } $create_args{'ReferredToBy'} = \@referredtoby; # }}} my ( $id, $Trans, $ErrMsg ) = $Ticket->Create(%create_args); - unless ( $id ) { + unless ( $id && $Trans ) { Abort($ErrMsg); } @@ -627,7 +574,7 @@ sub MakeMIMEEntity { Subject => $args{'Subject'} || "", From => $args{'From'}, Cc => $args{'Cc'}, - 'Charset:' => 'utf8', + Charset => 'utf8', Data => [ $args{'Body'} ] ); } @@ -955,7 +902,7 @@ sub ProcessACLChanges { if ($object_type eq 'RT::System') { $obj = $RT::System; - } elsif ($RT::ACE::OBJECT_TYPES{$object_type}) { + } elsif ($RT::ACE::OBJECT_TYPES{$object_type}) { $obj = $object_type->new($session{'CurrentUser'}); $obj->Load($object_id); } else { @@ -984,7 +931,7 @@ sub ProcessACLChanges { if ($object_type eq 'RT::System') { $obj = $RT::System; - } elsif ($RT::ACE::OBJECT_TYPES{$object_type}) { + } elsif ($RT::ACE::OBJECT_TYPES{$object_type}) { $obj = $object_type->new($session{'CurrentUser'}); $obj->Load($object_id); } else { @@ -1026,9 +973,9 @@ sub UpdateRecordObject { my $Object = $args{'Object'}; my @results = $Object->Update(AttributesRef => $args{'AttributesRef'}, - ARGSRef => $args{'ARGSRef'}, + ARGSRef => $args{'ARGSRef'}, AttributePrefix => $args{'AttributePrefix'} - ); + ); return (@results); } @@ -1126,7 +1073,6 @@ sub ProcessTicketBasics { Queue ); - if ( $ARGSRef->{'Queue'} and ( $ARGSRef->{'Queue'} !~ /^(\d+)$/ ) ) { my $tempqueue = RT::Queue->new($RT::SystemUser); $tempqueue->Load( $ARGSRef->{'Queue'} ); @@ -1177,11 +1123,11 @@ sub ProcessTicketCustomFieldUpdates { my %custom_fields_to_mod; foreach my $arg ( keys %$ARGSRef ) { if ( $arg =~ /^Ticket-(\d+-.*)/) { - $ARGSRef->{"Object-RT::Ticket-$1"} = delete $ARGSRef->{$arg}; - } + $ARGSRef->{"Object-RT::Ticket-$1"} = delete $ARGSRef->{$arg}; + } elsif ( $arg =~ /^CustomField-(\d+-.*)/) { - $ARGSRef->{"Object-RT::Ticket--$1"} = delete $ARGSRef->{$arg}; - } + $ARGSRef->{"Object-RT::Ticket--$1"} = delete $ARGSRef->{$arg}; + } } return ProcessObjectCustomFieldUpdates(%args, ARGSRef => $ARGSRef); @@ -1356,8 +1302,8 @@ sub _ProcessObjectCustomFieldUpdates { } } else { - push ( @results, - loc("User asked for an unknown update type for custom field [_1] for [_2] object #[_3]", + push ( @results, loc("User asked for an unknown update type" + ." for custom field [_1] for [_2] object #[_3]", $cf->Name, ref $args{'Object'}, $args{'Object'}->id ) ); } @@ -1384,30 +1330,27 @@ sub ProcessTicketWatchers { my $Ticket = $args{'TicketObj'}; my $ARGSRef = $args{'ARGSRef'}; - # Munge watchers + # {{{ Munge watchers foreach my $key ( keys %$ARGSRef ) { - # Delete deletable watchers - if ( ( $key =~ /^Ticket-DeleteWatcher-Type-(.*)-Principal-(\d+)$/ ) ) - { - my ( $code, $msg ) = $Ticket->DeleteWatcher( - PrincipalId => $2, - Type => $1 - ); + # {{{ Delete deletable watchers + if ( ( $key =~ /^Ticket-DeleteWatcher-Type-(.*)-Principal-(\d+)$/ ) ) { + my ( $code, $msg ) = + $Ticket->DeleteWatcher(PrincipalId => $2, + Type => $1); push @results, $msg; } # Delete watchers in the simple style demanded by the bulk manipulator - elsif ( $key =~ /^Delete(Requestor|Cc|AdminCc)$/ ) { - my ( $code, $msg ) = $Ticket->DeleteWatcher( - Email => $ARGSRef->{$key}, - Type => $1 - ); + elsif ( $key =~ /^Delete(Requestor|Cc|AdminCc)$/ ) { + my ( $code, $msg ) = $Ticket->DeleteWatcher( Email => $ARGSRef->{$key}, Type => $1 ); push @results, $msg; } - # Add new wathchers by email address + # }}} + + # Add new wathchers by email address elsif ( ( $ARGSRef->{$key} =~ /^(AdminCc|Cc|Requestor)$/ ) and ( $key =~ /^WatcherTypeEmail(\d*)$/ ) ) { @@ -1430,21 +1373,18 @@ sub ProcessTicketWatchers { } # Add new watchers by owner - elsif ( $key =~ /^Ticket-AddWatcher-Principal-(\d*)$/ ) { - my $principal_id = $1; - my $form = $ARGSRef->{$key}; - foreach my $value ( ref($form) ? @{$form} : ($form) ) { - next unless $value =~ /^(?:AdminCc|Cc|Requestor)$/i; + elsif ( ( $ARGSRef->{$key} =~ /^(AdminCc|Cc|Requestor)$/ ) + and ( $key =~ /^Ticket-AddWatcher-Principal-(\d*)$/ ) ) { - my ( $code, $msg ) = $Ticket->AddWatcher( - Type => $value, - PrincipalId => $principal_id - ); - push @results, $msg; - } + #They're in this order because otherwise $1 gets clobbered :/ + my ( $code, $msg ) = + $Ticket->AddWatcher( Type => $ARGSRef->{$key}, PrincipalId => $1 ); + push @results, $msg; } - } + + # }}} + return (@results); } @@ -1526,7 +1466,7 @@ sub ProcessTicketLinks { my (@results) = ProcessRecordLinks(RecordObj => $Ticket, - ARGSRef => $ARGSRef); + ARGSRef => $ARGSRef); #Merge if we need to if ( $ARGSRef->{ $Ticket->Id . "-MergeInto" } ) { @@ -1622,37 +1562,6 @@ sub _UploadedFile { }; } -=head2 _load_container_object ( $type, $id ); - -Instantiate container object for saving searches. - -=cut - -sub _load_container_object { - my ($obj_type, $obj_id) = @_; - return RT::SavedSearch->new($session{'CurrentUser'})->_load_privacy_object($obj_type, $obj_id); -} - -=head2 _parse_saved_search ( $arg ); - -Given a serialization string for saved search, and returns the -container object and the search id. - -=cut - -sub _parse_saved_search { - my $spec = shift; - return unless $spec; - if ($spec !~ /^(.*?)-(\d+)-SavedSearch-(\d+)$/ ) { - return; - } - my $obj_type = $1; - my $obj_id = $2; - my $search_id = $3; - - return (_load_container_object ($obj_type, $obj_id), $search_id); -} - eval "require RT::Interface::Web_Vendor"; die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Web_Vendor.pm}); eval "require RT::Interface::Web_Local"; |