From 45c4b91b8e0208b36baef469bc60fb56a5bc17a3 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Wed, 18 Dec 2013 00:11:01 -0500 Subject: Bug 928989 - add a new method to ember which just returns current values --- extensions/Ember/lib/WebService.pm | 173 +++++++++++++++++++++++++++++++++++-- 1 file changed, 167 insertions(+), 6 deletions(-) (limited to 'extensions/Ember/lib') diff --git a/extensions/Ember/lib/WebService.pm b/extensions/Ember/lib/WebService.pm index 585079ac5..96c6a5646 100644 --- a/extensions/Ember/lib/WebService.pm +++ b/extensions/Ember/lib/WebService.pm @@ -252,6 +252,72 @@ sub search { return $result; } +sub bug { + my ($self, $params) = @_; + my $dbh = Bugzilla->dbh; + + my $bug_id = delete $params->{id}; + $bug_id || ThrowCodeError('param_required', + { function => 'Ember.bug', param => 'id' }); + + my ($comments, $attachments) = ([], []); + my $bug = $self->get({ ids => [ $bug_id ] }); + $bug = $bug->{bugs}->[0]; + + # Only return changes since last_updated if provided + my $last_updated = delete $params->{last_updated}; + if ($last_updated) { + trick_taint($last_updated); + my $updated_fields = $dbh->selectcol_arrayref('SELECT fielddefs.name + FROM fielddefs INNER JOIN bugs_activity + ON fielddefs.id = bugs_activity.fieldid + WHERE bugs_activity.bug_when > ? + AND bugs_activity.bug_id = ?', + undef, ($last_updated, $bug->{id})); + + my %field_map = reverse %{ Bugzilla::Bug::FIELD_MAP() }; + $field_map{'flagtypes.name'} = 'flags'; + + my $changed_bug = {}; + foreach my $field (@$updated_fields) { + my $field_name = $field_map{$field} || $field; + if ($bug->{$field_name}) { + $changed_bug->{$field_name} = $bug->{$field_name}; + } + } + $bug = $changed_bug; + + # Find any comments created since the last_updated date + $comments = $self->comments({ ids => $bug_id, new_since => $last_updated }); + + # Find any new attachments or modified attachments since the + # last_updated date + my $updated_attachments = + $dbh->selectcol_arrayref('SELECT attach_id FROM attachments + WHERE (creation_ts > ? OR modification_time > ?) + AND bug_id = ?', + undef, ($last_updated, $last_updated, $bug->{id})); + if ($updated_attachments) { + $attachments = $self->_get_attachments({ attachment_ids => $updated_attachments, + exclude_fields => ['data'] }); + } + } + else { + $comments = $self->comments({ ids => [ $bug_id ] }); + $attachments = $self->_get_attachments({ ids => [ $bug_id ], + exclude_fields => ['data'] }); + + } + + $comments = $comments->{bugs}->{$bug_id}->{comments}; + + return { + bug => $bug, + comments => $comments, + attachments => $attachments, + }; +} + sub get_attachments { my ($self, $params) = @_; my $attachments = $self->_get_attachments($params); @@ -686,12 +752,6 @@ sub rest_resources { } } }, - # show bug page - one or more bug ids - qr{^/ember/show$}, { - GET => { - method => 'show' - } - }, # search - wrapper around SUPER::search which also includes the total # number of bugs when using pagination qr{^/ember/search$}, { @@ -699,6 +759,15 @@ sub rest_resources { method => 'search', }, }, + # get current bug attributes without field information - single bug id + qr{^/ember/bug/(\d+)$}, { + GET => { + method => 'bug', + params => sub { + return { id => $_[0] }; + } + } + }, # attachments - wrapper around SUPER::attachments that also includes # can_edit attribute qr{^/ember/bug/(\d+)/attachments$}, { @@ -858,3 +927,95 @@ As per Bugzilla::WebService::Bug::search() =back =back + +=head2 bug + +B + +=over + +=item B + +This method returns just the current bug values, comments, and attachments without +all of the field information. + +=item B + +You pass a field called C that is a valid bug ids. + +=over + +=item C (integer) - A valid bug id + +=item C - (dateTime) An optional timestamp that includes only fields, +attachments, or comments that have been changed or added since. + +=back + +=item B + +=over + +=back + +=item B + +=over + +=back + +=item B + +=over + +=item Added in BMO Bugzilla B<4.2>. + +=back + +=back + +=head2 get_attachments + +B + +=over + +=item B + +This method returns the current attachment data and flag types for a given +bug id or attachment id. + +=item B + +You pass a field called C that is a valid bug id or an C which +is a valid attachment id. + +=over + +=item C (integer) - A valid bug id. + +=item C (integer) - A valid attachment id. + +=back + +=item B + +=over + +=back + +=item B + +=over + +=back + +=item B + +=over + +=item Added in BMO Bugzilla B<4.2>. + +=back + +=back -- cgit v1.2.3-24-g4f1b