X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FTemplate.pm;h=f73ea3ed6a791df2abba783b08b8de63e89d5148;hp=3ef96c7df888a266a53103491bdc07a48f92d5eb;hb=ded0451e9582df33cae6099a2fb72b4ea25076cf;hpb=0ebeec96313dd7edfca340f01f8fbbbac1f4aa1d diff --git a/rt/lib/RT/Template.pm b/rt/lib/RT/Template.pm index 3ef96c7df..f73ea3ed6 100755 --- a/rt/lib/RT/Template.pm +++ b/rt/lib/RT/Template.pm @@ -1,395 +1,363 @@ -# $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Template.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $ -# Copyright 1996-2002 Jesse Vincent -# Portions Copyright 2000 Tobias Brox -# Released under the terms of the GNU General Public License +# BEGIN LICENSE BLOCK +# +# Copyright (c) 1996-2003 Jesse Vincent +# +# (Except where explictly superceded by other copyright notices) +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# Unless otherwise specified, all modifications, corrections or +# extensions to this work which alter its source code become the +# property of Best Practical Solutions, LLC when submitted for +# inclusion in the work. +# +# +# END LICENSE BLOCK +# Autogenerated by DBIx::SearchBuilder factory (by ) +# WARNING: THIS FILE IS AUTOGENERATED. ALL CHANGES TO THIS FILE WILL BE LOST. +# +# !! DO NOT EDIT THIS FILE !! +# + +use strict; + =head1 NAME - RT::Template - RT's template object +RT::Template + =head1 SYNOPSIS - use RT::Template; +=head1 DESCRIPTION +=head1 METHODS -=head1 DESCRIPTION +=cut +package RT::Template; +use RT::Record; +use RT::Queue; -=head1 METHODS -=begin testing +use vars qw( @ISA ); +@ISA= qw( RT::Record ); + +sub _Init { + my $self = shift; + + $self->Table('Templates'); + $self->SUPER::_Init(@_); +} + + + + + +=item Create PARAMHASH -ok(require RT::TestHarness); -ok(require RT::Template); +Create takes a hash of values and creates a row in the database: -=end testing + int(11) 'Queue'. + varchar(200) 'Name'. + varchar(255) 'Description'. + varchar(16) 'Type'. + varchar(16) 'Language'. + int(11) 'TranslationOf'. + blob 'Content'. =cut -package RT::Template; -use RT::Record; -use MIME::Entity; -use MIME::Parser; -@ISA = qw(RT::Record); -# {{{ sub _Init -sub _Init { +sub Create { my $self = shift; - $self->{'table'} = "Templates"; - return ( $self->SUPER::_Init(@_) ); + my %args = ( + Queue => '0', + Name => '', + Description => '', + Type => '', + Language => '', + TranslationOf => '0', + Content => '', + + @_); + $self->SUPER::Create( + Queue => $args{'Queue'}, + Name => $args{'Name'}, + Description => $args{'Description'}, + Type => $args{'Type'}, + Language => $args{'Language'}, + TranslationOf => $args{'TranslationOf'}, + Content => $args{'Content'}, +); + } -# }}} -# {{{ sub _Accessible -sub _Accessible { - my $self = shift; - my %Cols = ( - id => 'read', - Name => 'read/write', - Description => 'read/write', - Type => 'read/write', #Type is one of Action or Message - Content => 'read/write', - Queue => 'read/write', - Creator => 'read/auto', - Created => 'read/auto', - LastUpdatedBy => 'read/auto', - LastUpdated => 'read/auto' - ); - return $self->SUPER::_Accessible( @_, %Cols ); -} +=item id -# }}} +Returns the current value of id. +(In the database, id is stored as int(11).) -# {{{ sub _Set -sub _Set { - my $self = shift; +=cut - # use super::value or we get acl blocked - if ( ( defined $self->SUPER::_Value('Queue') ) - && ( $self->SUPER::_Value('Queue') == 0 ) ) - { - unless ( $self->CurrentUser->HasSystemRight('ModifyTemplate') ) { - return ( 0, 'Permission Denied' ); - } - } - else { - - unless ( $self->CurrentUserHasQueueRight('ModifyTemplate') ) { - return ( 0, 'Permission Denied' ); - } - } - return ( $self->SUPER::_Set(@_) ); -} +=item Queue + +Returns the current value of Queue. +(In the database, Queue is stored as int(11).) -# }}} -# {{{ sub _Value -=head2 _Value +=item SetQueue VALUE + + +Set Queue to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Queue will be stored as a int(11).) -Takes the name of a table column. -Returns its value as a string, if the user passes an ACL check =cut -sub _Value { - my $self = shift; - my $field = shift; +=item QueueObj - #If the current user doesn't have ACLs, don't let em at it. - #use super::value or we get acl blocked - if ( ( !defined $self->__Value('Queue') ) - || ( $self->__Value('Queue') == 0 ) ) - { - unless ( $self->CurrentUser->HasSystemRight('ShowTemplate') ) { - return (undef); - } - } - else { - unless ( $self->CurrentUserHasQueueRight('ShowTemplate') ) { - return (undef); - } - } - return ( $self->__Value($field) ); +Returns the Queue Object which has the id returned by Queue + +=cut + +sub QueueObj { + my $self = shift; + my $Queue = RT::Queue->new($self->CurrentUser); + $Queue->Load($self->__Value('Queue')); + return($Queue); } -# }}} +=item Name + +Returns the current value of Name. +(In the database, Name is stored as varchar(200).) + + -# {{{ sub Load +=item SetName VALUE -=head2 Load -Load a template, either by number or by name +Set Name to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Name will be stored as a varchar(200).) + =cut -sub Load { - my $self = shift; - my $identifier = shift; - if ( !$identifier ) { - return (undef); - } +=item Description + +Returns the current value of Description. +(In the database, Description is stored as varchar(255).) - if ( $identifier !~ /\D/ ) { - $self->SUPER::LoadById($identifier); - } - else { - $self->LoadByCol( 'Name', $identifier ); - } -} -# }}} +=item SetDescription VALUE -# {{{ sub LoadGlobalTemplate -=head2 LoadGlobalTemplate NAME +Set Description to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Description will be stored as a varchar(255).) -Load the global tempalte with the name NAME =cut -sub LoadGlobalTemplate { - my $self = shift; - my $id = shift; - return ( $self->LoadQueueTemplate( Queue => 0, Name => $id ) ); -} +=item Type -# }}} +Returns the current value of Type. +(In the database, Type is stored as varchar(16).) -# {{{ sub LoadQueueTemplate -=head2 LoadQueueTemplate (Queue => QUEUEID, Name => NAME) -Loads the Queue template named NAME for Queue QUEUE. +=item SetType VALUE + + +Set Type to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Type will be stored as a varchar(16).) + =cut -sub LoadQueueTemplate { - my $self = shift; - my %args = ( - Queue => undef, - Name => undef - ); - return ( $self->LoadByCols( Name => $args{'Name'}, Queue => {'Queue'} ) ); +=item Language -} +Returns the current value of Language. +(In the database, Language is stored as varchar(16).) -# }}} -# {{{ sub Create -=head2 Create +=item SetLanguage VALUE -Takes a paramhash of Content, Queue, Name and Description. -Name should be a unique string identifying this Template. -Description and Content should be the template's title and content. -Queue should be 0 for a global template and the queue # for a queue-specific -template. -Returns the Template's id # if the create was successful. Returns undef for -unknown database failure. +Set Language to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Language will be stored as a varchar(16).) =cut -sub Create { - my $self = shift; - my %args = ( - Content => undef, - Queue => 0, - Description => '[no description]', - Type => 'Action', #By default, template are 'Action' templates - Name => undef, - @_ - ); - - if ( $args{'Queue'} == 0 ) { - unless ( $self->CurrentUser->HasSystemRight('ModifyTemplate') ) { - return (undef); - } - } - else { - my $QueueObj = new RT::Queue( $self->CurrentUser ); - $QueueObj->Load( $args{'Queue'} ) || return ( 0, 'Invalid queue' ); - - unless ( $QueueObj->CurrentUserHasRight('ModifyTemplate') ) { - return (undef); - } - } - - my $result = $self->SUPER::Create( - Content => $args{'Content'}, - Queue => $args{'Queue'}, - , - Description => $args{'Description'}, - Name => $args{'Name'} - ); - - return ($result); -} +=item TranslationOf + +Returns the current value of TranslationOf. +(In the database, TranslationOf is stored as int(11).) + + -# }}} +=item SetTranslationOf VALUE -# {{{ sub Delete -=head2 Delete +Set TranslationOf to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, TranslationOf will be stored as a int(11).) -Delete this template. =cut -sub Delete { - my $self = shift; - unless ( $self->CurrentUserHasRight('ModifyTemplate') ) { - return ( 0, 'Permission Denied' ); - } +=item Content - return ( $self->SUPER::Delete(@_) ); -} +Returns the current value of Content. +(In the database, Content is stored as blob.) -# }}} -# {{{ sub MIMEObj -sub MIMEObj { - my $self = shift; - return ( $self->{'MIMEObj'} ); -} -# }}} +=item SetContent VALUE -# {{{ sub Parse -=item Parse +Set Content to VALUE. +Returns (1, 'Status message') on success and (0, 'Error Message') on failure. +(In the database, Content will be stored as a blob.) - This routine performs Text::Template parsing on thte template and then imports the - results into a MIME::Entity so we can really use it - It returns a tuple of (val, message) - If val is 0, the message contains an error message =cut -sub Parse { - my $self = shift; - #We're passing in whatever we were passed. it's destined for _ParseContent - my $content = $self->_ParseContent(@_); +=item LastUpdated - #Lets build our mime Entity +Returns the current value of LastUpdated. +(In the database, LastUpdated is stored as datetime.) - my $parser = MIME::Parser->new(); - - # Do work on the parsed template in memory, rather than on disk - $parser->output_to_core(1); - ### Should we forgive normally-fatal errors? - $parser->ignore_errors(1); - $self->{'MIMEObj'} = eval { $parser->parse_data($content) }; - $error = ( $@ || $parser->last_error ); +=cut - if ($error) { - $RT::Logger->error("$error"); - return ( 0, $error ); - } - # Unfold all headers - $self->{'MIMEObj'}->head->unfold(); +=item LastUpdatedBy - return ( 1, "Template parsed" ); - +Returns the current value of LastUpdatedBy. +(In the database, LastUpdatedBy is stored as int(11).) -} -# }}} +=cut -# {{{ sub _ParseContent -# Perform Template substitutions on the template +=item Creator -sub _ParseContent { - my $self = shift; - my %args = ( - Argument => undef, - TicketObj => undef, - TransactionObj => undef, - @_ - ); - - # Might be subject to change - use Text::Template; - - $T::Ticket = $args{'TicketObj'}; - $T::Transaction = $args{'TransactionObj'}; - $T::Argument = $args{'Argument'}; - $T::rtname = $RT::rtname; - - # We need to untaint the content of the template, since we'll be working - # with it - my $content = $self->Content(); - $content =~ s/^(.*)$/$1/; - $template = Text::Template->new( - TYPE => STRING, - SOURCE => $content - ); - - my $retval = $template->fill_in( PACKAGE => T ); - return ($retval); -} +Returns the current value of Creator. +(In the database, Creator is stored as int(11).) -# }}} -# {{{ sub QueueObj +=cut -=head2 QueueObj -Takes nothing. returns this ticket's queue object +=item Created + +Returns the current value of Created. +(In the database, Created is stored as datetime.) + =cut -sub QueueObj { - my $self = shift; - if ( !defined $self->{'queue'} ) { - require RT::Queue; - $self->{'queue'} = RT::Queue->new( $self->CurrentUser ); - - unless ( $self->{'queue'} ) { - $RT::Logger->crit( - "RT::Queue->new(" . $self->CurrentUser . ") returned false" ); - return (undef); - } - my ($result) = $self->{'queue'}->Load( $self->__Value('Queue') ); - - } - return ( $self->{'queue'} ); -} -# }}} -# {{{ sub CurrentUserHasQueueRight +sub _ClassAccessible { + { + + id => + {read => 1, type => 'int(11)', default => ''}, + Queue => + {read => 1, write => 1, type => 'int(11)', default => '0'}, + Name => + {read => 1, write => 1, type => 'varchar(200)', default => ''}, + Description => + {read => 1, write => 1, type => 'varchar(255)', default => ''}, + Type => + {read => 1, write => 1, type => 'varchar(16)', default => ''}, + Language => + {read => 1, write => 1, type => 'varchar(16)', default => ''}, + TranslationOf => + {read => 1, write => 1, type => 'int(11)', default => '0'}, + Content => + {read => 1, write => 1, type => 'blob', default => ''}, + LastUpdated => + {read => 1, auto => 1, type => 'datetime', default => ''}, + LastUpdatedBy => + {read => 1, auto => 1, type => 'int(11)', default => '0'}, + Creator => + {read => 1, auto => 1, type => 'int(11)', default => '0'}, + Created => + {read => 1, auto => 1, type => 'datetime', default => ''}, + + } +}; + + + eval "require RT::Template_Overlay"; + if ($@ && $@ !~ qr{^Can't locate RT/Template_Overlay.pm}) { + die $@; + }; + + eval "require RT::Template_Vendor"; + if ($@ && $@ !~ qr{^Can't locate RT/Template_Vendor.pm}) { + die $@; + }; + + eval "require RT::Template_Local"; + if ($@ && $@ !~ qr{^Can't locate RT/Template_Local.pm}) { + die $@; + }; -=head2 CurrentUserHasQueueRight -Helper function to call the template's queue's CurrentUserHasQueueRight with the passed in args. + + +=head1 SEE ALSO + +This class allows "overlay" methods to be placed +into the following files _Overlay is for a System overlay by the original author, +_Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations. + +These overlay files can contain new subs or subs to replace existing subs in this module. + +If you'll be working with perl 5.6.0 or greater, each of these files should begin with the line + + no warnings qw(redefine); + +so that perl does not kick and scream when you redefine a subroutine or variable in your overlay. + +RT::Template_Overlay, RT::Template_Vendor, RT::Template_Local =cut -sub CurrentUserHasQueueRight { - my $self = shift; - return ( $self->QueueObj->CurrentUserHasRight(@_) ); -} -# }}} 1;