[Rt-commit] rt branch, 4.4/unique-custom-fields, created. rt-4.4.0-227-g0d0362f

Shawn Moore shawn at bestpractical.com
Fri May 20 16:07:09 EDT 2016


The branch, 4.4/unique-custom-fields has been created
        at  0d0362fe846dd43799bbf226c23b781b19b5693c (commit)

- Log -----------------------------------------------------------------
commit 0d0362fe846dd43799bbf226c23b781b19b5693c
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 20 20:06:31 2016 +0000

    Add UniqueValues column to Custom Fields
    
        It's not enforced yet, but it has an Admin UI checkbox

diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index 16ae12b..9a75f4b 100644
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -357,6 +357,7 @@ CREATE TABLE CustomFields (
         SortOrder       NUMBER(11,0) DEFAULT 0 NOT NULL,
         LookupType      VARCHAR2(255),
         EntryHint       VARCHAR2(255) NULL,
+        UniqueValues    NUMBER(11,0) DEFAULT 0 NOT NULL,
         Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
         Created         DATE,
         LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
diff --git a/etc/schema.Pg b/etc/schema.Pg
index b23dbf0..1c4f5a8 100644
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -541,6 +541,7 @@ CREATE TABLE CustomFields (
   EntryHint varchar(255) NULL,
   Description varchar(255) NULL  ,
   SortOrder integer NOT NULL DEFAULT 0  ,
+  UniqueValues integer NOT NULL DEFAULT 0 ,
 
   Creator integer NOT NULL DEFAULT 0  ,
   Created TIMESTAMP NULL  ,
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index acf3b3f..4080598 100644
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -387,6 +387,7 @@ CREATE TABLE CustomFields (
   SortOrder integer NOT NULL DEFAULT 0  ,
   LookupType varchar(255) collate NOCASE NOT NULL,
   EntryHint varchar(255) NULL,
+  UniqueValues int2 NOT NULL DEFAULT 0,
 
   Creator integer NOT NULL DEFAULT 0  ,
   Created DATETIME NULL  ,
diff --git a/etc/schema.mysql b/etc/schema.mysql
index 9b239ad..f03862d 100644
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -359,6 +359,7 @@ CREATE TABLE CustomFields (
   SortOrder integer NOT NULL DEFAULT 0  ,
   LookupType varchar(255) CHARACTER SET ascii NOT NULL,
   EntryHint varchar(255) NULL,
+  UniqueValues int2 NOT NULL DEFAULT 0 ,
 
   Creator integer NOT NULL DEFAULT 0  ,
   Created DATETIME NULL  ,
diff --git a/etc/upgrade/4.4.2/schema.Oracle b/etc/upgrade/4.4.2/schema.Oracle
new file mode 100644
index 0000000..b7ce195
--- /dev/null
+++ b/etc/upgrade/4.4.2/schema.Oracle
@@ -0,0 +1 @@
+ALTER TABLE CustomFields ADD UniqueValues NUMBER(11,0) DEFAULT 0 NOT NULL;
diff --git a/etc/upgrade/4.4.2/schema.Pg b/etc/upgrade/4.4.2/schema.Pg
new file mode 100644
index 0000000..6da8b60
--- /dev/null
+++ b/etc/upgrade/4.4.2/schema.Pg
@@ -0,0 +1 @@
+ALTER TABLE CustomFields ADD COLUMN UniqueValues integer NOT NULL DEFAULT 0;
diff --git a/etc/upgrade/4.4.2/schema.SQLite b/etc/upgrade/4.4.2/schema.SQLite
new file mode 100644
index 0000000..33540e7
--- /dev/null
+++ b/etc/upgrade/4.4.2/schema.SQLite
@@ -0,0 +1 @@
+ALTER TABLE CustomFields ADD COLUMN UniqueValues int2 NOT NULL DEFAULT 0;
diff --git a/etc/upgrade/4.4.2/schema.mysql b/etc/upgrade/4.4.2/schema.mysql
new file mode 100644
index 0000000..33540e7
--- /dev/null
+++ b/etc/upgrade/4.4.2/schema.mysql
@@ -0,0 +1 @@
+ALTER TABLE CustomFields ADD COLUMN UniqueValues int2 NOT NULL DEFAULT 0;
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index ee56a25..191fa67 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -2448,6 +2448,8 @@ sub _CoreAccessible {
         {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varchar(255)', default => ''},
         EntryHint =>
         {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0, is_numeric => 0,  type => 'varchar(255)', default => undef },
+        UniqueValues =>
+        {read => 1, write => 1, sql_type => 5, length => 6,  is_blob => 0,  is_numeric => 1,  type => 'smallint(6)', default => '0'},
         Creator => 
         {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
         Created => 
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index f9a7324..4c357ee 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -163,6 +163,12 @@ jQuery( function() {
 </td></tr>
 % }
 
+<tr><td class="label"> </td><td>
+<input type="hidden" class="hidden" name="SetUniqueValues" value="1" />
+<input type="checkbox" class="checkbox" id="UniqueValues" name="UniqueValues" value="1" <% $UniqueValuesChecked |n %> />
+<label for="UniqueValues"><&|/l&>Values must be unique</&></label>
+</td></tr>
+
 % $m->callback(CallbackName => 'BeforeEnabled', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
 
 <tr><td class="label"> </td><td>
@@ -211,6 +217,7 @@ else {
             BasedOn       => $BasedOn,
             Disabled      => ($Enabled ? 0 : 1),
             EntryHint     => $EntryHint,
+            UniqueValues  => $UniqueValues,
         );
         if (!$val) {
             push @results, loc("Could not create CustomField: [_1]", $msg);
@@ -233,7 +240,11 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
     #we're asking about enabled on the web page but really care about disabled.
     $ARGS{'Disabled'} = $Enabled? 0 : 1;
 
-    my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue EntryHint);
+    # make sure the unchecked checkbox still causes an update
+    $ARGS{UniqueValues} ||= 0 if $SetUniqueValues;
+
+    my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue EntryHint UniqueValues);
+
     push @results, UpdateRecordObject(
         AttributesRef => \@attribs,
         Object        => $CustomFieldObj,
@@ -354,6 +365,9 @@ MaybeRedirectForResults(
 my $EnabledChecked = qq[checked="checked"];
 $EnabledChecked = '' if $CustomFieldObj->Disabled;
 
+my $UniqueValuesChecked = qq[checked="checked"];
+$UniqueValuesChecked = '' if !$CustomFieldObj->UniqueValues;
+
 my @CFvalidations = (
     '(?#Mandatory).',
     '(?#Digits)^[\d.]+$',
@@ -374,6 +388,8 @@ $Pattern => undef
 $Name => undef
 $SetEnabled => undef
 $Enabled => 0
+$SetUniqueValues => undef
+$UniqueValues => 0
 $ValuesClass => 'RT::CustomFieldValues'
 $RenderType => undef
 $LinkValueTo => undef

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


More information about the rt-commit mailing list