Skip to content

Commit f3f85f5

Browse files
kyoshinodylanwh
authored andcommitted
Bug 1320977 - Add review/feedback/needinfo request counts and block statuses to /rest/user and /rest/user/suggest responses
1 parent 694a37b commit f3f85f5

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

Bugzilla/WebService/User.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ sub suggest {
154154
return { users => [] } if length($s) < 3;
155155

156156
my $dbh = Bugzilla->dbh;
157-
my @select = ('realname AS real_name', 'login_name AS name');
157+
my @select = ('userid AS id', 'realname AS real_name', 'login_name AS name');
158158
my $order = 'last_seen_date DESC';
159159
my $where;
160160
state $have_mysql = $dbh->isa('Bugzilla::DB::Mysql');
@@ -190,11 +190,15 @@ sub suggest {
190190

191191
my @users = map {
192192
{
193+
id => $self->type(int => $_->{id}),
193194
real_name => $self->type(string => $_->{real_name}),
194195
name => $self->type(email => $_->{name}),
195196
}
196197
} @$results;
197198

199+
Bugzilla::Hook::process('webservice_user_suggest',
200+
{ webservice => $self, params => $params, users => \@users });
201+
198202
return { users => \@users };
199203
}
200204

extensions/Review/Extension.pm

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use Bugzilla::Search;
2525
use Bugzilla::User;
2626
use Bugzilla::User::Setting;
2727
use Bugzilla::Util qw(clean_text datetime_from diff_arrays);
28+
use Bugzilla::WebService::Util qw(filter_wants);
29+
use Scalar::Util qw(blessed);
2830

2931
use constant UNAVAILABLE_RE => qr/\b(?:unavailable|pto|away)\b/i;
3032
use constant MENTOR_LIMIT => 10;
@@ -1064,4 +1066,51 @@ sub config_modify_panels {
10641066
};
10651067
}
10661068

1069+
#
1070+
# hooks
1071+
#
1072+
1073+
sub webservice_user_get {
1074+
my ($self, $args) = @_;
1075+
my ($webservice, $params, $users) = @$args{qw(webservice params users)};
1076+
1077+
return unless filter_wants($params, 'requests');
1078+
1079+
my $ids = [
1080+
map { blessed($_->{id}) ? $_->{id}->value : $_->{id} }
1081+
grep { exists $_->{id} }
1082+
@$users
1083+
];
1084+
1085+
return unless @$ids;
1086+
1087+
my %user_map = map { $_->id => $_ } @{ Bugzilla::User->new_from_list($ids) };
1088+
1089+
foreach my $user (@$users) {
1090+
my $id = blessed($user->{id}) ? $user->{id}->value : $user->{id};
1091+
my $user_obj = $user_map{$id};
1092+
1093+
$user->{requests} = {
1094+
review => {
1095+
blocked => $webservice->type('boolean', $user_obj->reviews_blocked),
1096+
pending => $webservice->type('int', $user_obj->{review_request_count}),
1097+
},
1098+
feedback => {
1099+
# reviews_blocked includes feedback as well
1100+
blocked => $webservice->type('boolean', $user_obj->reviews_blocked),
1101+
pending => $webservice->type('int', $user_obj->{feedback_request_count}),
1102+
},
1103+
needinfo => {
1104+
blocked => $webservice->type('boolean', $user_obj->needinfo_blocked),
1105+
pending => $webservice->type('int', $user_obj->{needinfo_request_count}),
1106+
},
1107+
};
1108+
}
1109+
}
1110+
1111+
sub webservice_user_suggest {
1112+
my ($self, $args) = @_;
1113+
$self->webservice_user_get($args);
1114+
}
1115+
10671116
__PACKAGE__->NAME;

0 commit comments

Comments
 (0)