[Rt-commit] rt branch, 4.0/force-lc-ticket-type, created. rt-4.0.11-61-g15a18f9

Alex Vandiver alexmv at bestpractical.com
Wed Apr 17 17:34:03 EDT 2013


The branch, 4.0/force-lc-ticket-type has been created
        at  15a18f9fc0c9960ef580905378c38e83bd962db8 (commit)

- Log -----------------------------------------------------------------
commit 15a18f9fc0c9960ef580905378c38e83bd962db8
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Apr 17 17:05:41 2013 -0400

    Force internal RT values for ticket Type to lower-case
    
    The three values for Type that RT uses internally are 'ticket',
    'approval', or 'reminder'; for the most part, these are not exposed to
    the user.  The exception to this is when generating approvals, as the
    CreateTickets action requires the user to specify the Type of the ticket
    created.  Improper casing on the "approval" type is a common, and
    frustrating, mistake.
    
    Be liberal in what case RT accepts for its core types, but consistently
    use lower-case in those values when they are stored.  As external
    systems may rely on case-sensitivity of non-core values for Type,
    preserve the case sensitivity of those values.

diff --git a/etc/upgrade/4.0.12/schema.Oracle b/etc/upgrade/4.0.12/schema.Oracle
new file mode 100644
index 0000000..4d2c375
--- /dev/null
+++ b/etc/upgrade/4.0.12/schema.Oracle
@@ -0,0 +1 @@
+UPDATE Tickets SET Type = LOWER(Type) WHERE LOWER(Type) IN ('ticket', 'approval', 'reminder');
diff --git a/etc/upgrade/4.0.12/schema.Pg b/etc/upgrade/4.0.12/schema.Pg
new file mode 100644
index 0000000..4d2c375
--- /dev/null
+++ b/etc/upgrade/4.0.12/schema.Pg
@@ -0,0 +1 @@
+UPDATE Tickets SET Type = LOWER(Type) WHERE LOWER(Type) IN ('ticket', 'approval', 'reminder');
diff --git a/etc/upgrade/4.0.12/schema.mysql b/etc/upgrade/4.0.12/schema.mysql
new file mode 100644
index 0000000..4d2c375
--- /dev/null
+++ b/etc/upgrade/4.0.12/schema.mysql
@@ -0,0 +1 @@
+UPDATE Tickets SET Type = LOWER(Type) WHERE LOWER(Type) IN ('ticket', 'approval', 'reminder');
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index cce5c56..1945545 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -459,6 +459,9 @@ sub Create {
         }
     }
 
+    $args{'Type'} = lc $args{'Type'}
+        if $args{'Type'} =~ /^(ticket|approval|reminder)$/i;
+
     $RT::Handle->BeginTransaction();
 
     my %params = (
@@ -717,6 +720,15 @@ sub Create {
     }
 }
 
+sub SetType {
+    my $self = shift;
+    my $value = shift;
+
+    # Force lowercase on internal RT types
+    $value = lc $value
+        if $value =~ /^(ticket|approval|reminder)$/i;
+    return $self->_Set(Field => 'Type', Value => $value, @_);
+}
 
 
 
diff --git a/t/api/ticket.t b/t/api/ticket.t
index 92c8a85..da287a6 100644
--- a/t/api/ticket.t
+++ b/t/api/ticket.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use RT;
-use RT::Test tests => 87;
+use RT::Test tests => undef;
 
 
 {
@@ -254,3 +254,32 @@ ok(!$id,$msg);
 
 }
 
+diag("Test ticket types with different cases");
+{
+    my $t = RT::Ticket->new(RT->SystemUser);
+    my ($ok) = $t->Create(
+        Queue => 'general',
+        Subject => 'type test',
+        Type => 'Ticket',
+    );
+    ok($ok, "Ticket allows passing upper-case Ticket as type during Create");
+    is($t->Type, "ticket", "Ticket type is lowercased during create");
+
+    ($ok) = $t->SetType("REMINDER");
+    ok($ok, "Ticket allows passing upper-case REMINDER to SetType");
+    is($t->Type, "reminder", "Ticket type is lowercased during set");
+
+    ($ok) = $t->SetType("OTHER");
+    ok($ok, "Allows setting Type to non-RT types");
+    is($t->Type, "OTHER", "Non-RT types are case-insensitive");
+
+    ($ok) = $t->Create(
+        Queue => 'general',
+        Subject => 'type test',
+        Type => 'Approval',
+    );
+    ok($ok, "Tickets can be created with an upper-case Approval type");
+    is($t->Type, "approval", "Approvals, the third and final internal type, are also lc'd during Create");
+}
+
+done_testing;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list