summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKohei Yoshino <kohei.yoshino@gmail.com>2018-07-27 19:26:55 +0200
committerDylan William Hardison <dylan@hardison.net>2018-07-27 19:26:55 +0200
commitf3f85f5bb8328a7264534a121c412938febda824 (patch)
treeda9e3a86ab62c77dbf725839c845ef6ec2ad1fcf
parent694a37b9debdf280d279b39b44329adda5caff40 (diff)
downloadbugzilla-f3f85f5bb8328a7264534a121c412938febda824.tar.gz
bugzilla-f3f85f5bb8328a7264534a121c412938febda824.tar.xz
Bug 1320977 - Add review/feedback/needinfo request counts and block statuses to /rest/user and /rest/user/suggest responses
-rw-r--r--Bugzilla/WebService/User.pm6
-rw-r--r--extensions/Review/Extension.pm49
2 files changed, 54 insertions, 1 deletions
diff --git a/Bugzilla/WebService/User.pm b/Bugzilla/WebService/User.pm
index 5bb5e32c1..c569cf9d8 100644
--- a/Bugzilla/WebService/User.pm
+++ b/Bugzilla/WebService/User.pm
@@ -154,7 +154,7 @@ sub suggest {
return { users => [] } if length($s) < 3;
my $dbh = Bugzilla->dbh;
- my @select = ('realname AS real_name', 'login_name AS name');
+ my @select = ('userid AS id', 'realname AS real_name', 'login_name AS name');
my $order = 'last_seen_date DESC';
my $where;
state $have_mysql = $dbh->isa('Bugzilla::DB::Mysql');
@@ -190,11 +190,15 @@ sub suggest {
my @users = map {
{
+ id => $self->type(int => $_->{id}),
real_name => $self->type(string => $_->{real_name}),
name => $self->type(email => $_->{name}),
}
} @$results;
+ Bugzilla::Hook::process('webservice_user_suggest',
+ { webservice => $self, params => $params, users => \@users });
+
return { users => \@users };
}
diff --git a/extensions/Review/Extension.pm b/extensions/Review/Extension.pm
index 47edd69a6..406c29c7c 100644
--- a/extensions/Review/Extension.pm
+++ b/extensions/Review/Extension.pm
@@ -25,6 +25,8 @@ use Bugzilla::Search;
use Bugzilla::User;
use Bugzilla::User::Setting;
use Bugzilla::Util qw(clean_text datetime_from diff_arrays);
+use Bugzilla::WebService::Util qw(filter_wants);
+use Scalar::Util qw(blessed);
use constant UNAVAILABLE_RE => qr/\b(?:unavailable|pto|away)\b/i;
use constant MENTOR_LIMIT => 10;
@@ -1064,4 +1066,51 @@ sub config_modify_panels {
};
}
+#
+# hooks
+#
+
+sub webservice_user_get {
+ my ($self, $args) = @_;
+ my ($webservice, $params, $users) = @$args{qw(webservice params users)};
+
+ return unless filter_wants($params, 'requests');
+
+ my $ids = [
+ map { blessed($_->{id}) ? $_->{id}->value : $_->{id} }
+ grep { exists $_->{id} }
+ @$users
+ ];
+
+ return unless @$ids;
+
+ my %user_map = map { $_->id => $_ } @{ Bugzilla::User->new_from_list($ids) };
+
+ foreach my $user (@$users) {
+ my $id = blessed($user->{id}) ? $user->{id}->value : $user->{id};
+ my $user_obj = $user_map{$id};
+
+ $user->{requests} = {
+ review => {
+ blocked => $webservice->type('boolean', $user_obj->reviews_blocked),
+ pending => $webservice->type('int', $user_obj->{review_request_count}),
+ },
+ feedback => {
+ # reviews_blocked includes feedback as well
+ blocked => $webservice->type('boolean', $user_obj->reviews_blocked),
+ pending => $webservice->type('int', $user_obj->{feedback_request_count}),
+ },
+ needinfo => {
+ blocked => $webservice->type('boolean', $user_obj->needinfo_blocked),
+ pending => $webservice->type('int', $user_obj->{needinfo_request_count}),
+ },
+ };
+ }
+}
+
+sub webservice_user_suggest {
+ my ($self, $args) = @_;
+ $self->webservice_user_get($args);
+}
+
__PACKAGE__->NAME;