]> git.uio.no Git - usit-rt.git/blobdiff - lib/RT/Scrip.pm
Master to 4.2.8
[usit-rt.git] / lib / RT / Scrip.pm
index 14df0c9c5db5b8d6274bbb4ce20579ada8a64210..5e153cd4770b742c7b88a90950b3b40e14ca6adf 100644 (file)
@@ -258,10 +258,48 @@ sub NotAddedTo {
         ->NotAddedTo( Scrip => $self );
 }
 
+=head2 AddToObject
+
+Adds (applies) the current scrip to the provided queue (ObjectId).
+
+Accepts a param hash of:
+
+=over
+
+=item C<ObjectId>
+
+Queue name or id. 0 makes the scrip global.
+
+=item C<Stage>
+
+Stage to run in. Valid stages are TransactionCreate or
+TransactionBatch. Defaults to TransactionCreate. As of RT 4.2, Disabled
+is no longer a stage.
+
+=item C<Template>
+
+Name of global or queue-specific template for the scrip. Use 'Blank' for
+non-notification scrips.
+
+=item C<SortOrder>
+
+Number indicating the relative order the scrip should run in.
+
+=back
+
+Returns (val, message). If val is false, the message contains an error
+message.
+
+=cut
+
 sub AddToObject {
     my $self = shift;
     my %args = @_%2? (ObjectId => @_) : (@_);
 
+    # Default Stage explicitly rather than in %args assignment to handle
+    # Stage coming in set to undef.
+    $args{'Stage'} //= 'TransactionCreate';
+
     my $queue;
     if ( $args{'ObjectId'} ) {
         $queue = RT::Queue->new( $self->CurrentUser );
@@ -293,6 +331,25 @@ sub AddToObject {
     return $rec->Add( %args, Scrip => $self );
 }
 
+=head2 RemoveFromObject
+
+Removes the current scrip to the provided queue (ObjectId).
+
+Accepts a param hash of:
+
+=over
+
+=item C<ObjectId>
+
+Queue name or id. 0 makes the scrip global.
+
+=back
+
+Returns (val, message). If val is false, the message contains an error
+message.
+
+=cut
+
 sub RemoveFromObject {
     my $self = shift;
     my %args = @_%2? (ObjectId => @_) : (@_);
@@ -401,6 +458,25 @@ sub Stage {
     return undef;
 }
 
+=head2 FriendlyStage($Stage)
+
+Helper function that returns a localized human-readable version of the
+C<$Stage> argument.
+
+=cut
+
+sub FriendlyStage {
+    my ( $class, $stage ) = @_;
+    my $stage_i18n_lookup = {
+        TransactionCreate => 'Normal', # loc
+        TransactionBatch => 'Batch', # loc
+        TransactionBatchDisabled => 'Batch (disabled by config)', # loc
+    };
+    $stage = 'TransactionBatchDisabled'
+        if $stage eq 'TransactionBatch'
+            and not RT->Config->Get('UseTransactionBatch');
+    return $stage_i18n_lookup->{$stage};
+}
 
 =head2 Apply { TicketObj => undef, TransactionObj => undef}
 
@@ -661,10 +737,7 @@ sub _Set {
 sub _Value {
     my $self = shift;
 
-    unless ( $self->CurrentUserHasRight('ShowScrips') ) {
-        $RT::Logger->debug( "CurrentUser can't see scrip #". $self->__Value('id') );
-        return (undef);
-    }
+    return unless $self->CurrentUserHasRight('ShowScrips');
 
     return $self->__Value(@_);
 }