summaryrefslogtreecommitdiffstats
path: root/extensions/MyDashboard/lib
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/MyDashboard/lib')
-rw-r--r--extensions/MyDashboard/lib/BugInterest.pm70
-rw-r--r--extensions/MyDashboard/lib/Queries.pm17
-rw-r--r--extensions/MyDashboard/lib/WebService.pm27
3 files changed, 114 insertions, 0 deletions
diff --git a/extensions/MyDashboard/lib/BugInterest.pm b/extensions/MyDashboard/lib/BugInterest.pm
new file mode 100644
index 000000000..4f14eb4fd
--- /dev/null
+++ b/extensions/MyDashboard/lib/BugInterest.pm
@@ -0,0 +1,70 @@
+# 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.
+
+package Bugzilla::Extension::MyDashboard::BugInterest;
+
+use 5.10.1;
+use strict;
+
+use parent qw(Bugzilla::Object);
+
+#####################################################################
+# Overriden Constants that are used as methods
+#####################################################################
+
+use constant DB_TABLE => 'bug_interest';
+use constant DB_COLUMNS => qw( id bug_id user_id modification_time );
+use constant UPDATE_COLUMNS => qw( modification_time );
+use constant VALIDATORS => {};
+use constant LIST_ORDER => 'id';
+use constant NAME_FIELD => 'id';
+
+# turn off auditing and exclude these objects from memcached
+use constant { AUDIT_CREATES => 0,
+ AUDIT_UPDATES => 0,
+ AUDIT_REMOVES => 0,
+ USE_MEMCACHED => 0 };
+
+#####################################################################
+# Provide accessors for our columns
+#####################################################################
+
+sub id { return $_[0]->{id} }
+sub bug_id { return $_[0]->{bug_id} }
+sub user_id { return $_[0]->{user_id} }
+sub modification_time { return $_[0]->{modification_time} }
+
+sub mark {
+ my ($class, $user_id, $bug_id, $timestamp) = @_;
+
+ my ($interest) = @{ $class->match({ user_id => $user_id,
+ bug_id => $bug_id }) };
+ if ($interest) {
+ $interest->set(modification_time => $timestamp);
+ $interest->update();
+ return $interest;
+ }
+ else {
+ return $class->create({
+ user_id => $user_id,
+ bug_id => $bug_id,
+ modification_time => $timestamp,
+ });
+ }
+}
+
+sub unmark {
+ my ($class, $user_id, $bug_id) = @_;
+
+ my ($interest) = @{ $class->match({ user_id => $user_id,
+ bug_id => $bug_id }) };
+ if ($interest) {
+ $interest->remove_from_db();
+ }
+}
+
+1;
diff --git a/extensions/MyDashboard/lib/Queries.pm b/extensions/MyDashboard/lib/Queries.pm
index 9dff5abe4..34c63e07b 100644
--- a/extensions/MyDashboard/lib/Queries.pm
+++ b/extensions/MyDashboard/lib/Queries.pm
@@ -106,6 +106,7 @@ sub QUERY_DEFS {
name => 'lastvisitedbugs',
heading => 'Updated Since Last Visit',
description => 'Bugs updated since last visited',
+ mark_read => 'Mark Visited',
params => {
o1 => 'lessthan',
v1 => '%last_changed%',
@@ -113,9 +114,25 @@ sub QUERY_DEFS {
},
},
{
+ name => 'interestingbugs',
+ heading => 'Interesting Bugs',
+ description => 'Bugs that you may find interesting',
+ mark_read => 'Remove Interest',
+ params => {
+ j_top => 'OR',
+ f1 => 'bug_interest_ts',
+ o1 => 'isnotempty',
+
+ f2 => 'last_visit_ts',
+ o2 => 'lessthan',
+ v2 => '%last_changed%',
+ }
+ },
+ {
name => 'nevervisitbugs',
heading => 'Involved with and Never Visited',
description => "Bugs you've never visited, but are involved with",
+ mark_read => 'Mark Visited',
params => {
query_format => "advanced",
bug_status => ['__open__'],,
diff --git a/extensions/MyDashboard/lib/WebService.pm b/extensions/MyDashboard/lib/WebService.pm
index 87061eabe..9e9de42be 100644
--- a/extensions/MyDashboard/lib/WebService.pm
+++ b/extensions/MyDashboard/lib/WebService.pm
@@ -17,6 +17,7 @@ use Bugzilla::Util qw(detaint_natural trick_taint template_var datetime_from);
use Bugzilla::WebService::Util qw(validate);
use Bugzilla::Extension::MyDashboard::Queries qw(QUERY_DEFS query_bugs query_flags);
+use Bugzilla::Extension::MyDashboard::BugInterest;
use constant READ_ONLY => qw(
run_bug_query
@@ -127,6 +128,32 @@ sub run_flag_query {
return { result => { $type => $results }};
}
+sub bug_interest_unmark {
+ my ($self, $params) = @_;
+ my $user = Bugzilla->login(LOGIN_REQUIRED);
+
+ ThrowCodeError('param_required', { function => 'MyDashboard.bug_interest_unmark', param => 'bug_ids' })
+ unless $params->{bug_ids};
+
+ my @bug_ids = ref($params->{bug_ids}) ? @{$params->{bug_ids}} : ( $params->{bug_ids} );
+
+ Bugzilla->dbh->bz_start_transaction();
+ foreach my $bug_id (@bug_ids) {
+ Bugzilla::Extension::MyDashboard::BugInterest->unmark($user->id, $bug_id);
+ }
+ Bugzilla->dbh->bz_commit_transaction();
+}
+
+sub rest_resources {
+ return [
+ qr{^/bug_interest_unmark$}, {
+ PUT => {
+ method => 'bug_interest_unmark'
+ }
+ }
+ ];
+}
+
1;
__END__