summaryrefslogtreecommitdiffstats
path: root/extensions/MyDashboard/Extension.pm
diff options
context:
space:
mode:
authorDave Lawrence <dlawrence@mozilla.com>2012-11-30 21:03:59 +0100
committerDave Lawrence <dlawrence@mozilla.com>2012-11-30 21:03:59 +0100
commit37c8ef5cb2750f8039f3b26422d5a5c7cfc61f59 (patch)
treec372513c649a32eb0273a4a8b4004b676bdad133 /extensions/MyDashboard/Extension.pm
parentd83a1c136214a5663a09987c48d66f9a527e7798 (diff)
downloadbugzilla-37c8ef5cb2750f8039f3b26422d5a5c7cfc61f59.tar.gz
bugzilla-37c8ef5cb2750f8039f3b26422d5a5c7cfc61f59.tar.xz
Current dashboard work
Diffstat (limited to 'extensions/MyDashboard/Extension.pm')
-rw-r--r--extensions/MyDashboard/Extension.pm245
1 files changed, 4 insertions, 241 deletions
diff --git a/extensions/MyDashboard/Extension.pm b/extensions/MyDashboard/Extension.pm
index 82c995442..036d1ce24 100644
--- a/extensions/MyDashboard/Extension.pm
+++ b/extensions/MyDashboard/Extension.pm
@@ -13,87 +13,12 @@ use base qw(Bugzilla::Extension);
use Bugzilla;
use Bugzilla::Constants;
-use Bugzilla::Search;
-use Bugzilla::Util;
-use Bugzilla::Status;
-use Bugzilla::Field;
use Bugzilla::Search::Saved;
-use Bugzilla::Extension::MyDashboard::Util qw(open_states closed_states
- quoted_open_states quoted_closed_states);
-use Bugzilla::Extension::MyDashboard::TimeAgo qw(time_ago);
-
-use DateTime;
+use Bugzilla::Extension::MyDashboard::Queries qw(QUERY_DEFS);
our $VERSION = BUGZILLA_VERSION;
-sub QUERY_DEFS {
- my $user = Bugzilla->user;
-
- my @query_defs = (
- {
- name => 'assignedbugs',
- heading => 'Assigned to You',
- description => 'The bug has been assigned to you and it is not resolved or closed yet.',
- params => {
- 'bug_status' => ['__open__'],
- 'emailassigned_to1' => 1,
- 'emailtype1' => 'exact',
- 'email1' => $user->login
- }
- },
- {
- name => 'newbugs',
- heading => 'New Reported by You',
- description => 'You reported the bug but nobody has accepted it yet.',
- params => {
- 'bug_status' => ['NEW'],
- 'emailreporter1' => 1,
- 'emailtype1' => 'exact',
- 'email1' => $user->login
- }
- },
- {
- name => 'inprogressbugs',
- heading => "In Progress Reported by You",
- description => 'You reported the bug, the developer accepted the bug and is hopefully working on it.',
- params => {
- 'bug_status' => [ map { $_->name } grep($_->name ne 'NEW' && $_->name ne 'MODIFIED', open_states()) ],
- 'emailreporter1' => 1,
- 'emailtype1' => 'exact',
- 'email1' => $user->login
- }
- },
- {
- name => 'openccbugs',
- heading => "You Are CC'd On",
- description => 'You are in the CC list of the bug, so you are watching it.',
- params => {
- 'bug_status' => ['__open__'],
- 'emailcc1' => 1,
- 'emailtype1' => 'exact',
- 'email1' => $user->login
- }
- },
- );
-
- if (Bugzilla->params->{'useqacontact'}) {
- push(@query_defs, {
- name => 'qacontactbugs',
- heading => 'You Are QA Contact',
- description => 'You are the qa contact on this bug and it is not resolved or closed yet.',
- params => {
- 'bug_status' => ['__open__'],
- 'emailqa_contact1' => 1,
- 'emailtype1' => 'exact',
- 'email1' => $user->login
- }
- });
- }
-
- return @query_defs;
-}
-
################
# Installation #
################
@@ -151,172 +76,10 @@ sub page_before_template {
return if $page ne 'mydashboard.html';
- # If we're using bug groups to restrict bug entry, we need to know who the
- # user is right from the start.
- my $user = Bugzilla->login(LOGIN_REQUIRED);
-
- # Switch to shadow db since we are just reading information
- Bugzilla->switch_to_shadow_db();
-
- _standard_saved_queries($vars);
- _flags_requested($vars);
-
- $vars->{'severities'} = get_legal_field_values('bug_severity');
-}
-
-sub _standard_saved_queries {
- my ($vars) = @_;
- my $dbh = Bugzilla->dbh;
- my $user = Bugzilla->user;
-
- # Default sort order
- my $order = ["changeddate desc", "bug_id"];
-
- # List of columns that we will be selecting. In the future this should be configurable
- # Share with buglist.cgi?
- my @select_columns = ('bug_id','product','bug_status','bug_severity','version', 'component','short_desc', 'changeddate');
-
- # Define the columns that can be selected in a query
- my $columns = Bugzilla::Search::COLUMNS;
-
- # Weed out columns that don't actually exist and detaint along the way.
- @select_columns = grep($columns->{$_} && trick_taint($_), @select_columns);
-
- ### Standard query definitions
- my @query_defs = QUERY_DEFS;
-
- ### Saved query definitions
- ### These are enabled through the userprefs.cgi UI
-
- if ($user->showmybugslink) {
- my $query = Bugzilla->params->{mybugstemplate};
- my $login = $user->login;
- $query =~ s/%userid%/$login/;
- $query =~ s/^buglist.cgi\?//;
- push(@query_defs, {
- name => 'mybugs',
- heading => "My Bugs",
- saved => 1,
- params => $query,
- });
- }
-
- foreach my $q (@{$user->queries}) {
- next if !$q->in_mydashboard;
- push(@query_defs, { name => $q->name,
- heading => $q->name,
- saved => 1,
- params => $q->url });
- }
-
- #my $date_now = DateTime->now(time_zone => Bugzilla->local_timezone);
-
- ### Collect the query results for display in the template
-
- my @results;
- foreach my $qdef (@query_defs) {
- my $params = new Bugzilla::CGI($qdef->{params});
-
- my $search = new Bugzilla::Search( fields => \@select_columns,
- params => scalar $params->Vars,
- order => $order );
- my $query = $search->sql();
-
- my $sth = $dbh->prepare($query);
- $sth->execute();
-
- my $rows = $sth->fetchall_arrayref();
-
- my @bugs;
- foreach my $row (@$rows) {
- my $bug = {};
- foreach my $column (@select_columns) {
- $bug->{$column} = shift @$row;
- #if ($column eq 'changeddate') {
- # my $date_then = datetime_from($bug->{$column});
- # $bug->{'updated'} = time_ago($date_then, $date_now);
- #}
- }
- push(@bugs, $bug);
- }
-
- $qdef->{bugs} = \@bugs;
- $qdef->{buffer} = $params->canonicalise_query();
-
- push(@results, $qdef);
- }
-
- $vars->{'results'} = \@results;
-}
-
-sub _flags_requested {
- my ($vars) = @_;
- my $user = Bugzilla->user;
- my $dbh = Bugzilla->dbh;
-
- my $attach_join_clause = "flags.attach_id = attachments.attach_id";
- if (Bugzilla->params->{insidergroup} && !$user->in_group(Bugzilla->params->{insidergroup})) {
- $attach_join_clause .= " AND attachments.isprivate < 1";
- }
-
- my $query =
- # Select columns describing each flag, the bug/attachment on which
- # it has been set, who set it, and of whom they are requesting it.
- " SELECT flags.id AS id,
- flagtypes.name AS type,
- flags.status AS status,
- flags.bug_id AS bug_id,
- bugs.short_desc AS bug_summary,
- flags.attach_id AS attach_id,
- attachments.description AS attach_summary,
- requesters.realname AS requester,
- requestees.realname AS requestee,
- " . $dbh->sql_date_format('flags.creation_date', '%Y:%m:%d') . " AS created
- FROM flags
- LEFT JOIN attachments
- ON ($attach_join_clause)
- INNER JOIN flagtypes
- ON flags.type_id = flagtypes.id
- INNER JOIN bugs
- ON flags.bug_id = bugs.bug_id
- LEFT JOIN profiles AS requesters
- ON flags.setter_id = requesters.userid
- LEFT JOIN profiles AS requestees
- ON flags.requestee_id = requestees.userid
- LEFT JOIN bug_group_map AS bgmap
- ON bgmap.bug_id = bugs.bug_id
- LEFT JOIN cc AS ccmap
- ON ccmap.who = " . $user->id . "
- AND ccmap.bug_id = bugs.bug_id ";
-
- # Limit query to pending requests and open bugs only
- $query .= " WHERE bugs.bug_status IN (" . join(',', quoted_open_states()) . ")
- AND flags.status = '?' ";
-
- # Weed out bug the user does not have access to
- $query .= " AND ((bgmap.group_id IS NULL)
- OR bgmap.group_id IN (" . $user->groups_as_string . ")
- OR (ccmap.who IS NOT NULL AND cclist_accessible = 1)
- OR (bugs.reporter = " . $user->id . " AND bugs.reporter_accessible = 1)
- OR (bugs.assigned_to = " . $user->id .") ";
- if (Bugzilla->params->{useqacontact}) {
- $query .= " OR (bugs.qa_contact = " . $user->id . ") ";
- }
- $query .= ") ";
-
- # Order the records (within each group).
- my $group_order_by = " GROUP BY flags.bug_id ORDER BY flags.creation_date, flagtypes.name";
+ # require user to be logged in for this page
+ Bugzilla->login(LOGIN_REQUIRED);
- my $requestee_list = $dbh->selectall_arrayref($query .
- " AND requestees.login_name = ? " .
- $group_order_by,
- { Slice => {} }, $user->login);
- $vars->{'requestee_list'} = $requestee_list;
- my $requester_list = $dbh->selectall_arrayref($query .
- " AND requesters.login_name = ? " .
- $group_order_by,
- { Slice => {} }, $user->login);
- $vars->{'requester_list'} = $requester_list;
+ $vars->{queries} = [ QUERY_DEFS ];
}
#########