[Rt-commit] rt branch, 4.2/scripstage-queue-columnmap-i18n, created. rt-4.2.3-8-g8e07ffe
Wallace Reis
wreis at bestpractical.com
Mon Mar 3 11:26:26 EST 2014
The branch, 4.2/scripstage-queue-columnmap-i18n has been created
at 8e07ffed3b9e76bea2fe66588c1f5316b9c9dc86 (commit)
- Log -----------------------------------------------------------------
commit 8e07ffed3b9e76bea2fe66588c1f5316b9c9dc86
Author: Wallace Reis <wreis at bestpractical.com>
Date: Fri Feb 28 12:55:20 2014 -0300
I#28739: ScripStage leaks internal value
Display Normal and Batch (and with disabled tag) instead of
TransactionCreate and TransactionBatch in Queue's ColumnMap.
Addtionally, factored the mapping out into RT::Scrip so that
we could have a single place for this logic to be used both
from form dropdown and collection listing.
diff --git a/lib/RT/ObjectScrip.pm b/lib/RT/ObjectScrip.pm
index 740f508..deab5c4 100644
--- a/lib/RT/ObjectScrip.pm
+++ b/lib/RT/ObjectScrip.pm
@@ -54,6 +54,7 @@ use base 'RT::Record::AddAndSort';
use RT::Scrip;
use RT::ObjectScrips;
+use Scalar::Util 'blessed';
=head1 NAME
@@ -129,7 +130,17 @@ Returns the current value of id.
Returns the current value of Scrip.
(In the database, Scrip is stored as int(11).)
+=head2 FriendlyStage
+Returns a localized human-readable version of the stage.
+
+=cut
+
+sub FriendlyStage {
+ my $self = shift;
+ my $scrip_class = blessed($self->ScripObj);
+ return $scrip_class->FriendlyStage($self->Stage);
+}
=head2 SetScrip VALUE
diff --git a/lib/RT/Scrip.pm b/lib/RT/Scrip.pm
index 3e065e6..f74aea2 100644
--- a/lib/RT/Scrip.pm
+++ b/lib/RT/Scrip.pm
@@ -458,6 +458,26 @@ 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',
+ UseTransactionBatch => 'Batch',
+ TransactionBatch => 'Batch (disabled by config)',
+ };
+ my $stage_prefix = RT->Config->Get('UseTransactionBatch')
+ ? 'Use'
+ : q{};
+ return $stage_i18n_lookup->{ $stage_prefix . $stage }
+ || $stage_i18n_lookup->{ $stage };
+}
=head2 Apply { TicketObj => undef, TransactionObj => undef}
diff --git a/share/html/Admin/Elements/SelectStage b/share/html/Admin/Elements/SelectStage
index 2b66d60..37f81ca 100644
--- a/share/html/Admin/Elements/SelectStage
+++ b/share/html/Admin/Elements/SelectStage
@@ -46,15 +46,11 @@
%#
%# END BPS TAGGED BLOCK }}}
<select name="<%$Name%>">
-% foreach my $stage (@stages) {
-
-%# allow [stage, display] in place of a scalar stage name
-% my ($value, $display) = ref($stage) ? @$stage : ($stage, $stage);
-
+% foreach my $value (@stages) {
<option value="<%$value%>"
<% ($value eq $Default) && qq[ selected="selected"] |n %>
<% ($value eq 'TransactionBatch' and not RT->Config->Get('UseTransactionBatch')) && qq[ disabled ] %>
-><% loc($display) %>
+><&|/l&><% RT::Scrip->FriendlyStage($value) | n %></&>
</option>
% }
@@ -63,11 +59,11 @@
if ( !defined $Default || $Default eq '') {
$Default = 'TransactionCreate';
}
-my @stages = ['TransactionCreate', loc('Normal')];
+my @stages = 'TransactionCreate';
push @stages, RT->Config->Get('UseTransactionBatch')
- ? ['TransactionBatch', loc('Batch')]
- : ['TransactionBatch', loc('Batch (disabled by config)')];
+ ? 'UseTransactionBatch'
+ : 'TransactionBatch';
</%INIT>
<%ARGS>
$Default => 'TransactionCreate'
diff --git a/share/html/Elements/RT__Queue/ColumnMap b/share/html/Elements/RT__Queue/ColumnMap
index 7183871..440432d 100644
--- a/share/html/Elements/RT__Queue/ColumnMap
+++ b/share/html/Elements/RT__Queue/ColumnMap
@@ -88,10 +88,9 @@ my $COLUMN_MAP = {
ScripStage => {
title => 'Stage', # loc
value => sub {
- my $sid = $_[-1];
my $os = RT::ObjectScrip->new( $_[0]->CurrentUser );
$os->LoadByCols( Scrip => $_[-1], ObjectId => $_[0]->id );
- return $os->Stage;
+ return $_[0]->loc( $os->FriendlyStage );
},
},
};
diff --git a/share/html/Elements/RT__Scrip/ColumnMap b/share/html/Elements/RT__Scrip/ColumnMap
index b6b3348..50e05c0 100644
--- a/share/html/Elements/RT__Scrip/ColumnMap
+++ b/share/html/Elements/RT__Scrip/ColumnMap
@@ -150,6 +150,14 @@ my $COLUMN_MAP = {
return @res;
},
},
+ Stage => {
+ title => 'Stage', # loc
+ value => sub {
+ my $os = RT::ObjectScrip->new( $_[0]->CurrentUser );
+ $os->LoadByCols( Scrip => $_[-1], ObjectId => $_[0]->id );
+ return $_[0]->loc( $os->FriendlyStage );
+ },
+ },
};
</%ONCE>
diff --git a/t/api/scrip.t b/t/api/scrip.t
index f1606d2..d6019a0 100644
--- a/t/api/scrip.t
+++ b/t/api/scrip.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Test tests => 74;
+use RT::Test;
my $queue = RT::Test->load_or_create_queue( Name => 'General' );
ok $queue && $queue->id, 'loaded or created queue';
@@ -188,6 +188,10 @@ note 'check applications vs. templates';
($status, $msg) = $scrip->AddToObject( $queue_B->id );
ok(!$status, $msg);
RT::Test->object_scrips_are($scrip, [$queue], [0, $queue_B]);
+ my $obj_scrip = RT::ObjectScrip->new( RT->SystemUser );
+ ok($obj_scrip->LoadByCols( Scrip => $scrip->id, ObjectId => $queue->id ));
+ is($obj_scrip->Stage, 'TransactionCreate');
+ is($obj_scrip->FriendlyStage, 'Normal');
$template = RT::Template->new( RT->SystemUser );
($status, $msg) = $template->Create( Queue => $queue_B->id, Name => 'foo' );
@@ -251,4 +255,12 @@ note 'basic check for disabling scrips';
ok($tid, "created ticket") or diag "error: $msg";
isnt ($ticket->Priority , '87', "Ticket priority is set right");
}
+
+ is($scrip->FriendlyStage('TransactionCreate'), 'Normal',
+ 'Correct stage wording for TransactionCreate');
+ is($scrip->FriendlyStage('TransactionBatch'), 'Batch',
+ 'Correct stage wording for TransactionBatch');
+ RT->Config->Set('UseTransactionBatch', 0);
+ is($scrip->FriendlyStage('TransactionBatch'), 'Batch (disabled by config)',
+ 'Correct stage wording for TransactionBatch with UseTransactionBatch disabled');
}
-----------------------------------------------------------------------
More information about the rt-commit
mailing list