diff options
author | Simon Green <sgreen@redhat.com> | 2014-02-26 23:33:45 +0100 |
---|---|---|
committer | Simon Green <sgreen@redhat.com> | 2014-02-26 23:33:45 +0100 |
commit | 3776f86ebdfb6169a35c525ce6b8363eb0cabbe1 (patch) | |
tree | a4c68a99923b16df2628af32e3a20064cdbe84b0 | |
parent | 64f44ef195aedfa291ffa474fab1db13624f60d7 (diff) | |
download | bugzilla-3776f86ebdfb6169a35c525ce6b8363eb0cabbe1.tar.gz bugzilla-3776f86ebdfb6169a35c525ce6b8363eb0cabbe1.tar.xz |
Bug 466178 - Add an INTEGER custom field type
r=glob, a=justdave
-rw-r--r-- | Bugzilla/Bug.pm | 24 | ||||
-rw-r--r-- | Bugzilla/Constants.pm | 6 | ||||
-rw-r--r-- | Bugzilla/Field.pm | 1 | ||||
-rw-r--r-- | template/en/default/bug/field.html.tmpl | 4 | ||||
-rw-r--r-- | template/en/default/global/field-descs.none.tmpl | 1 | ||||
-rw-r--r-- | template/en/default/global/user-error.html.tmpl | 6 |
6 files changed, 39 insertions, 3 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index dd22426bb..a6347cb2e 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -158,6 +158,9 @@ sub VALIDATORS { elsif ($field->type == FIELD_TYPE_TEXTAREA) { $validator = \&_check_textarea_field; } + elsif ($field->type == FIELD_TYPE_INTEGER) { + $validator = \&_check_integer_field; + } else { $validator = \&_check_default_field; } @@ -2110,6 +2113,27 @@ sub _check_textarea_field { return $text; } +sub _check_integer_field { + my ($invocant, $value, $field) = @_; + $value = defined($value) ? trim($value) : ''; + + if ($value eq '') { + return 0; + } + + my $orig_value = $value; + if (!detaint_signed($value)) { + ThrowUserError("number_not_integer", + {field => $field, num => $orig_value}); + } + elsif ($value > MAX_INT_32) { + ThrowUserError("number_too_large", + {field => $field, num => $orig_value, max_num => MAX_INT_32}); + } + + return $value; +} + sub _check_relationship_loop { # Generates a dependency tree for a given bug. Calls itself recursively # to generate sub-trees for the bug's dependencies. diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index 7154d4536..a296e2e25 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -111,8 +111,9 @@ use Memoize; FIELD_TYPE_BUG_ID FIELD_TYPE_BUG_URLS FIELD_TYPE_KEYWORDS + FIELD_TYPE_INTEGER FIELD_TYPE_HIGHEST_PLUS_ONE - + EMPTY_DATETIME_REGEX ABNORMAL_SELECTS @@ -398,9 +399,10 @@ use constant FIELD_TYPE_BUG_ID => 6; use constant FIELD_TYPE_BUG_URLS => 7; use constant FIELD_TYPE_KEYWORDS => 8; use constant FIELD_TYPE_DATE => 9; +use constant FIELD_TYPE_INTEGER => 10; # Add new field types above this line, and change the below value in the # obvious fashion -use constant FIELD_TYPE_HIGHEST_PLUS_ONE => 10; +use constant FIELD_TYPE_HIGHEST_PLUS_ONE => 11; use constant EMPTY_DATETIME_REGEX => qr/^[0\-:\sA-Za-z]+$/; diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index dce16f83b..fd71cc321 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -153,6 +153,7 @@ use constant SQL_DEFINITIONS => { FIELD_TYPE_DATETIME, { TYPE => 'DATETIME' }, FIELD_TYPE_DATE, { TYPE => 'DATE' }, FIELD_TYPE_BUG_ID, { TYPE => 'INT3' }, + FIELD_TYPE_INTEGER, { TYPE => 'INT4', NOTNULL => 1, DEFAULT => 0 }, }; # Field definitions for the fields that ship with Bugzilla. diff --git a/template/en/default/bug/field.html.tmpl b/template/en/default/bug/field.html.tmpl index 0ef19c1c4..f8612eebb 100644 --- a/template/en/default/bug/field.html.tmpl +++ b/template/en/default/bug/field.html.tmpl @@ -35,11 +35,13 @@ [% Hook.process('start_field_column') %] [% IF editable %] [% SWITCH field.type %] - [% CASE constants.FIELD_TYPE_FREETEXT %] + [% CASE [ constants.FIELD_TYPE_FREETEXT + constants.FIELD_TYPE_INTEGER ] %] <input id="[% field.name FILTER html %]" class="text_input" name="[% field.name FILTER html %]" value="[% value FILTER html %]" size="40" maxlength="[% constants.MAX_FREETEXT_LENGTH FILTER none %]" + [% ' pattern="\d+"' IF field.type == constants.FIELD_TYPE_INTEGER %] [% ' aria-required="true"' IF field.is_mandatory %]> [% CASE [constants.FIELD_TYPE_DATETIME, constants.FIELD_TYPE_DATE] %] [% size = (field.type == constants.FIELD_TYPE_DATE) ? 10 : 20 %] diff --git a/template/en/default/global/field-descs.none.tmpl b/template/en/default/global/field-descs.none.tmpl index 34c4dc9ed..2afabd0c6 100644 --- a/template/en/default/global/field-descs.none.tmpl +++ b/template/en/default/global/field-descs.none.tmpl @@ -41,6 +41,7 @@ [% field_types = { ${constants.FIELD_TYPE_UNKNOWN} => "Unknown Type", ${constants.FIELD_TYPE_FREETEXT} => "Free Text", + ${constants.FIELD_TYPE_INTEGER} => "Integer", ${constants.FIELD_TYPE_SINGLE_SELECT} => "Drop Down", ${constants.FIELD_TYPE_MULTI_SELECT} => "Multiple-Selection Box", ${constants.FIELD_TYPE_TEXTAREA} => "Large Text Box", diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index d7648320c..11d4f8ad1 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1366,6 +1366,12 @@ Either no products have been defined to enter [% terms.bugs %] against or you have not been given access to any. + [% ELSIF error == "number_not_integer" %] + [% title = "Integer Value Required" %] + The value '[% num FILTER html %]' in the + <em>[% field_descs.$field FILTER html %]</em> field + is not an integer value (i.e. a whole number). + [% ELSIF error == "number_not_numeric" %] [% title = "Numeric Value Required" %] The value '[% num FILTER html %]' in the |