summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/CGI.pm25
-rw-r--r--Bugzilla/Constants.pm5
-rw-r--r--Bugzilla/Search/Saved.pm78
3 files changed, 108 insertions, 0 deletions
diff --git a/Bugzilla/CGI.pm b/Bugzilla/CGI.pm
index 091362306..7b76f6af0 100644
--- a/Bugzilla/CGI.pm
+++ b/Bugzilla/CGI.pm
@@ -135,6 +135,31 @@ sub canonicalise_query {
return join("&", @parameters);
}
+sub clean_search_url {
+ my $self = shift;
+ # Delete any empty URL parameter
+ my @cgi_params = $self->param;
+
+ foreach my $param (@cgi_params) {
+ if (defined $self->param($param) && $self->param($param) eq '') {
+ $self->delete($param);
+ $self->delete("${param}_type");
+ }
+
+ # Boolean Chart stuff is empty if it's "noop"
+ if ($param =~ /\d-\d-\d/ && defined $self->param($param)
+ && $self->param($param) eq 'noop')
+ {
+ $self->delete($param);
+ }
+ }
+
+ # Delete certain parameters if the associated parameter is empty.
+ $self->delete('bugidtype') if !$self->param('bug_id');
+ $self->delete('emailtype1') if !$self->param('email1');
+ $self->delete('emailtype2') if !$self->param('email2');
+}
+
# Overwrite to ensure nph doesn't get set, and unset HEADERS_ONCE
sub multipart_init {
my $self = shift;
diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm
index 7fb95e8f2..9c2cf77b4 100644
--- a/Bugzilla/Constants.pm
+++ b/Bugzilla/Constants.pm
@@ -128,6 +128,8 @@ use File::Basename;
MAX_TOKEN_AGE
SAFE_PROTOCOLS
+
+ MAX_LEN_QUERY_NAME
);
@Bugzilla::Constants::EXPORT_OK = qw(contenttypes);
@@ -350,6 +352,9 @@ use constant ROOT_USER => $^O =~ /MSWin32/i ? 'Administrator' : 'root';
# True if we're on Win32.
use constant ON_WINDOWS => ($^O =~ /MSWin32/i);
+# The longest that a saved search name can be.
+use constant MAX_LEN_QUERY_NAME => 64;
+
sub bz_locations {
# We know that Bugzilla/Constants.pm must be in %INC at this point.
# So the only question is, what's the name of the directory
diff --git a/Bugzilla/Search/Saved.pm b/Bugzilla/Search/Saved.pm
index 2cb53439d..1ef10c36b 100644
--- a/Bugzilla/Search/Saved.pm
+++ b/Bugzilla/Search/Saved.pm
@@ -29,6 +29,7 @@ use Bugzilla::Constants;
use Bugzilla::Group;
use Bugzilla::Search qw(IsValidQueryType);
use Bugzilla::User;
+use Bugzilla::Util;
#############
# Constants #
@@ -44,6 +45,76 @@ use constant DB_COLUMNS => qw(
query_type
);
+use constant REQUIRED_CREATE_FIELDS => qw(name query);
+
+use constant VALIDATORS => {
+ name => \&_check_name,
+ query => \&_check_query,
+ query_type => \&_check_query_type,
+ link_in_footer => \&_check_link_in_footer,
+};
+
+use constant UPDATE_COLUMNS => qw(query query_type);
+
+##############
+# Validators #
+##############
+
+sub _check_link_in_footer { return $_[1] ? 1 : 0; }
+
+sub _check_name {
+ my ($invocant, $name) = @_;
+ $name = trim($name);
+ $name || ThrowUserError("query_name_missing");
+ $name !~ /[<>&]/ || ThrowUserError("illegal_query_name");
+ if (length($name) > MAX_LEN_QUERY_NAME) {
+ ThrowUserError("query_name_too_long");
+ }
+ return $name;
+}
+
+sub _check_query {
+ my ($invocant, $query) = @_;
+ $query || ThrowUserError("buglist_parameters_required");
+ my $cgi = new Bugzilla::CGI($query);
+ $cgi->clean_search_url;
+ return $cgi->query_string;
+}
+
+sub _check_query_type {
+ my ($invocant, $type) = @_;
+ # Right now the only query type is LIST_OF_BUGS.
+ return $type ? LIST_OF_BUGS : QUERY_LIST;
+}
+
+#########################
+# Database Manipulation #
+#########################
+
+sub create {
+ my $class = shift;
+ Bugzilla->login(LOGIN_REQUIRED);
+ my $dbh = Bugzilla->dbh;
+ $class->check_required_create_fields(@_);
+ my $params = $class->run_create_validators(@_);
+
+ # Right now you can only create a Saved Search for the current user.
+ $params->{userid} = Bugzilla->user->id;
+
+ $dbh->bz_lock_tables('namedqueries WRITE',
+ 'namedqueries_link_in_footer WRITE');
+ my $lif = delete $params->{link_in_footer};
+ my $obj = $class->insert_create_data($params);
+ if ($lif) {
+ $dbh->do('INSERT INTO namedqueries_link_in_footer
+ (user_id, namedquery_id) VALUES (?,?)',
+ undef, $params->{userid}, $obj->id);
+ }
+ $dbh->bz_unlock_tables();
+
+ return $obj;
+}
+
#####################
# Complex Accessors #
#####################
@@ -112,6 +183,13 @@ sub user {
return $self->{user};
}
+############
+# Mutators #
+############
+
+sub set_url { $_[0]->set('query', $_[1]); }
+sub set_query_type { $_[0]->set('query_type', $_[1]); }
+
1;
__END__