summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorJulien Heyman <jheyman@portaildulibre.fr>2012-08-07 23:59:18 +0200
committerFrédéric Buclin <LpSolit@gmail.com>2012-08-07 23:59:18 +0200
commit14d7441b73d32614aa0e086c5f69ac087b939a48 (patch)
tree281660eac457755f199b4600439e2a7973f54612 /Bugzilla
parenteb04bb66cee35f39d546403ea4f777b43452cd4d (diff)
downloadbugzilla-14d7441b73d32614aa0e086c5f69ac087b939a48.tar.gz
bugzilla-14d7441b73d32614aa0e086c5f69ac087b939a48.tar.xz
Bug 319598: Add support for saved tabular and graphical reports
r/a=LpSolit
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/DB/Schema.pm17
-rw-r--r--Bugzilla/Report.pm134
-rw-r--r--Bugzilla/User.pm30
3 files changed, 181 insertions, 0 deletions
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm
index 156dca378..728176684 100644
--- a/Bugzilla/DB/Schema.pm
+++ b/Bugzilla/DB/Schema.pm
@@ -1026,6 +1026,23 @@ use constant ABSTRACT_SCHEMA => {
],
},
+ reports => {
+ FIELDS => [
+ id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1,
+ PRIMARYKEY => 1},
+ user_id => {TYPE => 'INT3', NOTNULL => 1,
+ REFERENCES => {TABLE => 'profiles',
+ COLUMN => 'userid',
+ DELETE => 'CASCADE'}},
+ name => {TYPE => 'varchar(64)', NOTNULL => 1},
+ query => {TYPE => 'LONGTEXT', NOTNULL => 1},
+ ],
+ INDEXES => [
+ reports_user_id_idx => {FIELDS => [qw(user_id name)],
+ TYPE => 'UNIQUE'},
+ ],
+ },
+
component_cc => {
FIELDS => [
diff --git a/Bugzilla/Report.pm b/Bugzilla/Report.pm
new file mode 100644
index 000000000..4c9f33226
--- /dev/null
+++ b/Bugzilla/Report.pm
@@ -0,0 +1,134 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+use strict;
+
+package Bugzilla::Report;
+
+use base qw(Bugzilla::Object);
+
+use Bugzilla::CGI;
+use Bugzilla::Constants;
+use Bugzilla::Error;
+use Bugzilla::Util;
+
+use constant DB_TABLE => 'reports';
+
+# Do not track reports saved by users.
+use constant AUDIT_CREATES => 0;
+use constant AUDIT_UPDATES => 0;
+use constant AUDIT_REMOVES => 0;
+
+use constant DB_COLUMNS => qw(
+ id
+ user_id
+ name
+ query
+);
+
+use constant UPDATE_COLUMNS => qw(
+ name
+ query
+);
+
+use constant VALIDATORS => {
+ name => \&_check_name,
+ query => \&_check_query,
+};
+
+##############
+# Validators #
+##############
+
+sub _check_name {
+ my ($invocant, $name) = @_;
+ $name = clean_text($name);
+ $name || ThrowUserError("report_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;
+}
+
+#############
+# Accessors #
+#############
+
+sub query { return $_[0]->{'query'}; }
+
+sub set_name { $_[0]->set('name', $_[1]); }
+sub set_query { $_[0]->set('query', $_[1]); }
+
+###########
+# Methods #
+###########
+
+sub create {
+ my $class = shift;
+ my $param = shift;
+
+ Bugzilla->login(LOGIN_REQUIRED);
+ $param->{'user_id'} = Bugzilla->user->id;
+
+ unshift @_, $param;
+ my $self = $class->SUPER::create(@_);
+}
+
+sub check {
+ my $class = shift;
+ my $report = $class->SUPER::check(@_);
+ my $user = Bugzilla->user;
+ if ( grep($_->id eq $report->id, @{$user->reports})) {
+ return $report;
+ } else {
+ ThrowUserError('report_access_denied');
+ }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Bugzilla::Report - Bugzilla report class.
+
+=head1 SYNOPSIS
+
+ use Bugzilla::Report;
+
+ my $report = new Bugzilla::Report(1);
+
+ my $report = Bugzilla::Report->check({id => $id});
+
+ my $name = $report->name;
+ my $query = $report->query;
+
+ my $report = Bugzilla::Report->create({ name => $name, query => $query });
+
+ $report->set_name($new_name);
+ $report->set_query($new_query);
+ $report->update();
+
+ $report->remove_from_db;
+
+=head1 DESCRIPTION
+
+Report.pm represents a Report object. It is an implementation
+of L<Bugzilla::Object>, and thus provides all methods that
+L<Bugzilla::Object> provides.
+
+=cut
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 9c869dc63..708d12c64 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -578,6 +578,25 @@ sub save_last_search {
return $search;
}
+sub reports {
+ my $self = shift;
+ return $self->{reports} if defined $self->{reports};
+ return [] unless $self->id;
+
+ my $dbh = Bugzilla->dbh;
+ my $report_ids = $dbh->selectcol_arrayref(
+ 'SELECT id FROM reports WHERE user_id = ?', undef, $self->id);
+ require Bugzilla::Report;
+ $self->{reports} = Bugzilla::Report->new_from_list($report_ids);
+ return $self->{reports};
+}
+
+sub flush_reports_cache {
+ my $self = shift;
+
+ delete $self->{reports};
+}
+
sub settings {
my ($self) = @_;
@@ -2275,6 +2294,17 @@ Should only be called by C<Bugzilla::Auth::login>, for the most part.
Returns the disable text of the user, if any.
+=item C<reports>
+
+Returns an arrayref of the user's own saved reports. The array contains
+L<Bugzilla::Reports> objects.
+
+=item C<flush_reports_cache>
+
+Some code modifies the set of stored reports. Because C<Bugzilla::User> does
+not handle these modifications, but does cache the result of calling C<reports>
+internally, such code must call this method to flush the cached result.
+
=item C<settings>
Returns a hash of hashes which holds the user's settings. The first key is