summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2006-08-20 08:21:43 +0200
committermkanat%bugzilla.org <>2006-08-20 08:21:43 +0200
commit36fcbae1f486223e61e1457b2af12a1fab0fe388 (patch)
tree61c9d5329b402e3af7d72182050eaba5bfcb0a6d /Bugzilla
parent015e33633728805a62d61e49a49ee74077d4f888 (diff)
downloadbugzilla-36fcbae1f486223e61e1457b2af12a1fab0fe388.tar.gz
bugzilla-36fcbae1f486223e61e1457b2af12a1fab0fe388.tar.xz
Bug 348477: Move simple validations from post_bug.cgi to Bugzilla::Bug
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=bkor, a=myk
Diffstat (limited to 'Bugzilla')
-rwxr-xr-xBugzilla/Bug.pm110
1 files changed, 110 insertions, 0 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index b89b0cf37..08677967a 100755
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -217,6 +217,116 @@ sub remove_from_db {
return $self;
}
+#####################################################################
+# Validators
+#####################################################################
+
+sub _check_alias {
+ my ($alias) = @_;
+ $alias = trim($alias);
+ ValidateBugAlias($alias) if (defined $alias && $alias ne '');
+ return $alias;
+}
+
+sub _check_assigned_to {
+ my ($name, $component) = @_;
+ my $user = Bugzilla->user;
+
+ $name = trim($name);
+ # Default assignee is the component owner.
+ my $id;
+ if (!$user->in_group("editbugs") || !$name) {
+ $id = $component->default_assignee->id;
+ } else {
+ $id = login_to_id($name, THROW_ERROR);
+ }
+ return $id;
+}
+
+sub _check_bug_file_loc {
+ my ($url) = @_;
+ if (!defined $url) {
+ ThrowCodeError('undefined_field', { field => 'bug_file_loc' });
+ }
+ # If bug_file_loc is "http://", the default, use an empty value instead.
+ $url = '' if $url eq 'http://';
+ return $url;
+}
+
+sub _check_comment {
+ my ($comment) = @_;
+
+ if (!defined $comment) {
+ ThrowCodeError('undefined_field', { field => 'comment' });
+ }
+
+ # Remove any trailing whitespace. Leading whitespace could be
+ # a valid part of the comment.
+ $comment =~ s/\s*$//s;
+ $comment =~ s/\r\n?/\n/g; # Get rid of \r.
+
+ ValidateComment($comment);
+
+ if (Bugzilla->params->{"commentoncreate"} && !$comment) {
+ ThrowUserError("description_required");
+ }
+
+ return $comment;
+}
+
+sub _check_component {
+ my ($name, $product) = @_;
+ $name = trim($name);
+ $name || ThrowUserError("require_component");
+ my $obj = Bugzilla::Component::check_component($product, $name);
+ # XXX Right now, post_bug needs this to return an object. However,
+ # when we move to Bugzilla::Bug->create, this should just return
+ # what it was passed.
+ return $obj;
+}
+
+sub _check_product {
+ my ($name) = @_;
+ # Check that the product exists and that the user
+ # is allowed to enter bugs into this product.
+ Bugzilla->user->can_enter_product($name, THROW_ERROR);
+ # can_enter_product already does everything that check_product
+ # would do for us, so we don't need to use it.
+ my $obj = new Bugzilla::Product({ name => $name });
+ # XXX Right now, post_bug needs this to return an object. However,
+ # when we move to Bugzilla::Bug->create, this should just return
+ # what it was passed.
+ return $obj;
+}
+
+sub _check_short_desc {
+ my ($short_desc) = @_;
+ # Set the parameter to itself, but cleaned up
+ $short_desc = clean_text($short_desc) if $short_desc;
+
+ if (!defined $short_desc || $short_desc eq '') {
+ ThrowUserError("require_summary");
+ }
+ return $short_desc;
+}
+
+sub _check_qa_contact {
+ my ($name, $component) = @_;
+ my $user = Bugzilla->user;
+
+ $name = trim($name);
+
+ my $id;
+ if (!$user->in_group("editbugs") || !$name) {
+ # We want to insert NULL into the database if we get a 0.
+ $id = $component->default_qa_contact->id || undef;
+ } else {
+ $id = login_to_id($name, THROW_ERROR);
+ }
+
+ return $id;
+}
+
#####################################################################
# Class Accessors