summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Bug.pm
diff options
context:
space:
mode:
authorTiago Mello <timello@linux.vnet.ibm.com>2010-05-19 18:28:37 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-05-19 18:28:37 +0200
commit44bc791eb3aa690940d540a7154d93dc8b10f186 (patch)
tree9d489c9a0ee037d6341fd3f03f5d86d9543a6a98 /Bugzilla/Bug.pm
parentd614dd98c482a06459f5f6e4911e0f32de6c424b (diff)
downloadbugzilla-44bc791eb3aa690940d540a7154d93dc8b10f186.tar.gz
bugzilla-44bc791eb3aa690940d540a7154d93dc8b10f186.tar.xz
Bug 494395: Implement the ability to mark custom fields as mandatory when
creating/changing bugs r=mkanat, a=mkanat
Diffstat (limited to 'Bugzilla/Bug.pm')
-rw-r--r--Bugzilla/Bug.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 6f2c2b602..dcf3f96da 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -54,6 +54,7 @@ use List::Util qw(min first);
use Storable qw(dclone);
use URI;
use URI::QueryParam;
+use Scalar::Util qw(blessed);
use base qw(Bugzilla::Object Exporter);
@Bugzilla::Bug::EXPORT = qw(
@@ -632,6 +633,14 @@ sub run_create_validators {
Bugzilla::Hook::process('bug_end_of_create_validators',
{ params => $params });
+ my @mandatory_fields = Bugzilla->get_fields({ is_mandatory => 1,
+ enter_bug => 1,
+ obsolete => 0 });
+ foreach my $field (@mandatory_fields) {
+ $class->_check_field_is_mandatory($params->{$field->name}, $field,
+ $params);
+ }
+
return $params;
}
@@ -1680,6 +1689,32 @@ sub _check_work_time {
# Custom Field Validators
+sub _check_field_is_mandatory {
+ my ($invocant, $value, $field, $params) = @_;
+
+ if (!blessed($field)) {
+ $field = Bugzilla::Field->check({ name => $field });
+ }
+
+ return if !$field->is_mandatory;
+
+ return if !$field->is_visible_on_bug($params || $invocant);
+
+ if (ref($value) eq 'ARRAY') {
+ $value = join('', @$value);
+ }
+
+ $value = trim($value);
+ if (!defined($value)
+ or $value eq ""
+ or ($value eq '---' and $field->type == FIELD_TYPE_SINGLE_SELECT)
+ or ($value =~ EMPTY_DATETIME_REGEX
+ and $field->type == FIELD_TYPE_DATETIME))
+ {
+ ThrowUserError('required_field', { field => $field });
+ }
+}
+
sub _check_datetime_field {
my ($invocant, $date_time) = @_;
@@ -1843,6 +1878,7 @@ sub _set_global_validator {
newvalue => $value,
privs => $privs });
}
+ $self->_check_field_is_mandatory($value, $field);
}