[Rt-commit] rt branch, 4.2/validate-value-for-select-cf, created. rt-4.2.16-8-gc874202223

Steve Burr steve at bestpractical.com
Fri Jan 15 11:12:21 EST 2021


The branch, 4.2/validate-value-for-select-cf has been created
        at  c874202223b44d7a07180e5ec720ac8e4a1286cc (commit)

- Log -----------------------------------------------------------------
commit c874202223b44d7a07180e5ec720ac8e4a1286cc
Author: Steven Burr <steve at bestpractical.com>
Date:   Fri Jan 15 11:04:24 2021 -0500

    Ensure values are valid for Select custom fields
    
    The values to which Custom Fields of type 'Select' can be set should
    be constrained to the list of defined values. While the Web interface
    provided for this, the REST2 interface did not.
    
    The ValidateValue method is implemented on the CustomField object
    to ensure that values are valid for Select custom fields regardless
    of how they are set.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index f36213f9e2..3b48605de7 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -672,6 +672,34 @@ sub DeleteValue {
     return ($retval, $self->loc("Custom field value deleted"));
 }
 
+=head2 ValidateValue Value
+
+Make sure that the supplied value is valid
+
+=cut
+
+sub ValidateValue {
+    my $self = shift;
+    my $value = shift;
+
+    # NB: ensuring that the value (including possibly an empty one)
+    #     matches any validation pattern defined is already checked in
+    #     AddValueForObject and DeleteValueForObject
+
+    # make sure the value is legal for Select custom fields
+    if ( $self->Type eq "Select" ) {
+        if ( $value ) {
+            my $cfvs = $self->Values;
+            while (my $cfv = $cfvs->Next) {
+                my $name = $cfv->Name;
+                return 1 if $name eq $value;
+            }
+            return 0;
+        }
+    }
+
+    return $self->SUPER::ValidateValue($value);
+}
 
 =head2 ValidateQueue Queue
 

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


More information about the rt-commit mailing list