diff options
author | dklawren <dklawren@users.noreply.github.com> | 2018-09-12 17:16:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 17:16:30 +0200 |
commit | 4945aec87af9752cc7a5d3ec178b4377bae644a3 (patch) | |
tree | 1b46fe99cbc942f13f571c58dc6a10f52ff4a866 | |
parent | 8a73abb9a369e840708dcb6a48be2e19a8e6a284 (diff) | |
download | bugzilla-4945aec87af9752cc7a5d3ec178b4377bae644a3.tar.gz bugzilla-4945aec87af9752cc7a5d3ec178b4377bae644a3.tar.xz |
Bug 1487422 - Remove Phabricator section from MyDashboard and related WebService API
-rw-r--r-- | extensions/MyDashboard/template/en/default/pages/mydashboard.html.tmpl | 37 | ||||
-rw-r--r-- | extensions/MyDashboard/web/js/flags.js | 101 | ||||
-rw-r--r-- | extensions/MyDashboard/web/js/query.js | 2 | ||||
-rw-r--r-- | extensions/PhabBugz/lib/Util.pm | 45 | ||||
-rw-r--r-- | extensions/PhabBugz/lib/WebService.pm | 105 |
5 files changed, 28 insertions, 262 deletions
diff --git a/extensions/MyDashboard/template/en/default/pages/mydashboard.html.tmpl b/extensions/MyDashboard/template/en/default/pages/mydashboard.html.tmpl index 5c372db3c..734be28df 100644 --- a/extensions/MyDashboard/template/en/default/pages/mydashboard.html.tmpl +++ b/extensions/MyDashboard/template/en/default/pages/mydashboard.html.tmpl @@ -45,7 +45,7 @@ <td class="field_data"> {{#if removed}} {{#unless added}} - Removed: + Removed: {{/unless}} {{removed}} {{/if}} @@ -127,30 +127,29 @@ %] </div> + [% IF Param('phabricator_enabled') %] + <div class="query_heading requests"> + <a href="[% Param('phabricator_base_uri') %]/differential">Phabricator Review Requests</a> + </div> + [% END %] + [% BLOCK requests_table %] <div id="[% name FILTER html %]_container" class="requests"> - <div class="query_heading">[% title FILTER html_light %]</div> - <span id="[% name FILTER html %]_loading" class="items_found">Loading...</span> - <span id="[% name FILTER html %]_count_refresh" class="bz_default_hidden"> - <span class="items_found" id="[% name FILTER html %]_flags_found">0 reviews found</span> - | <a class="refresh" href="javascript:void(0);" id="[% name FILTER html %]_refresh">Refresh</a> - | <a class="buglist" href="javascript:void(0);" id="[% name FILTER html %]_buglist">Buglist</a> - </span> - <div id="[% name FILTER html %]_table"></div> + <div class="query_heading">[% title FILTER html_light %]</div> + <span id="[% name FILTER html %]_loading" class="items_found">Loading...</span> + <span id="[% name FILTER html %]_count_refresh" class="bz_default_hidden"> + <span class="items_found" id="[% name FILTER html %]_flags_found">0 reviews found</span> + | <a class="refresh" href="javascript:void(0);" id="[% name FILTER html %]_refresh">Refresh</a> + | <a class="buglist" href="javascript:void(0);" id="[% name FILTER html %]_buglist">Buglist</a> + </span> + <div id="[% name FILTER html %]_table"></div> </div> [% END %] - [% ## no-008filter - # requires PhabBugz extension - IF Param('phabricator_enabled'); - title = '<a href="' _ Param('phabricator_base_uri') _ '">Phabricator</a> Reviews Requested of You'; - PROCESS requests_table name='reviews' title=title; - END; - - PROCESS requests_table name='requestee' title='Flags Requested of You'; - PROCESS requests_table name='requester' title='Flags You Have Requested'; - %] + [% PROCESS requests_table name='requestee' title='Flags Requested of You' %] + [% PROCESS requests_table name='requester' title='Flags You Have Requested' %] </div> + <div style="clear:both;"></div> [% IF user.showmybugslink OR user.queries.size OR user.queries_subscribed.size %] <hr> diff --git a/extensions/MyDashboard/web/js/flags.js b/extensions/MyDashboard/web/js/flags.js index 8931e277a..b340b4ee1 100644 --- a/extensions/MyDashboard/web/js/flags.js +++ b/extensions/MyDashboard/web/js/flags.js @@ -16,18 +16,15 @@ $(function () { // Common var counter = 0; var dataSource = { - reviews: null, requestee: null, requester: null }; var dataTable = { - reviews: null, requestee: null, requester: null }; - var hasReviews = !!document.getElementById('reviews_container'); - var updateRequestsTable = function(type) { + var updateFlagTable = function(type) { if (!type) return; counter = counter + 1; @@ -50,15 +47,14 @@ $(function () { if (o.error && o.error.message) { alert("Failed to load requests:\n\n" + o.error.message); } else { - alert("Failed to load requests."); + alert("Failed to load requests"); } } }; - var method = type === 'reviews' ? 'PhabBugz.needs_review' : 'MyDashboard.run_flag_query'; var json_object = { version: "1.1", - method: method, + method: "MyDashboard.run_flag_query", id: counter, params: { type : type, @@ -138,84 +134,6 @@ $(function () { } }; - var phabAuthorFormatter = function(o) { - return '<span title="' + Y.Escape.html(o.data.author_email) + '">' + - Y.Escape.html(o.data.author_name) + '</span>'; - }; - - var phabRowFormatter = function(o) { - var row = o.cell.ancestor(); - - // space in the 'flags' tables is tight - // render requests as two rows - diff title on first row, columns - // on second - - row.insert( - '<tr class="' + row.getAttribute('class') + '">' + - '<td class="yui3-datatable-cell" colspan="4">' + - '<a href="' + o.data.url + '" target="_blank">' + - Y.Escape.html(o.data.title) + '</a></td></tr>', - 'after'); - - o.cell.setHTML('<a href="' + o.data.url + '">D' + o.data.id + '</a>'); - - return false; - }; - - // Reviews - if (hasReviews) { - dataSource.reviews = new Y.DataSource.IO({ source: 'jsonrpc.cgi' }); - dataSource.reviews.on('error', function(e) { - console.log(e); - try { - var response = Y.JSON.parse(e.data.responseText); - if (response.error) - e.error.message = response.error.message; - } catch(ex) { - // ignore - } - }); - dataTable.reviews = new Y.DataTable({ - columns: [ - { key: 'author_email', label: 'Requester', sortable: true, - formatter: phabAuthorFormatter, allowHTML: true }, - { key: 'id', label: 'Revision', sortable: true, - nodeFormatter: phabRowFormatter, allowHTML: true }, - { key: 'bug_id', label: 'Bug', sortable: true, - formatter: bugLinkFormatter, allowHTML: true }, - { key: 'updated', label: 'Updated', sortable: true, - formatter: updatedFormatter, allowHTML: true } - ], - strings: { - emptyMessage: 'No review requests.', - } - }); - - dataTable.reviews.plug(Y.Plugin.DataTableSort); - - dataTable.reviews.plug(Y.Plugin.DataTableDataSource, { - datasource: dataSource.reviews - }); - - dataSource.reviews.plug(Y.Plugin.DataSourceJSONSchema, { - schema: { - resultListLocator: 'result.result', - resultFields: [ 'author_email', 'author_name', 'bug_id', - 'bug_status', 'bug_summary', 'id', 'status', 'title', - 'updated', 'updated_fancy', 'url' ] - } - }); - - dataTable.reviews.render("#reviews_table"); - - Y.one('#reviews_refresh').on('click', function(e) { - updateRequestsTable('reviews'); - }); - Y.one('#reviews_buglist').on('click', function(e) { - loadBugList('reviews'); - }); - } - // Requestee dataSource.requestee = new Y.DataSource.IO({ source: 'jsonrpc.cgi' }); dataSource.requestee.on('error', function(e) { @@ -259,7 +177,7 @@ $(function () { dataTable.requestee.render("#requestee_table"); Y.one('#requestee_refresh').on('click', function(e) { - updateRequestsTable('requestee'); + updateFlagTable('requestee'); }); Y.one('#requestee_buglist').on('click', function(e) { loadBugList('requestee'); @@ -307,23 +225,18 @@ $(function () { }); Y.one('#requester_refresh').on('click', function(e) { - updateRequestsTable('requester'); + updateFlagTable('requester'); }); Y.one('#requester_buglist').on('click', function(e) { loadBugList('requester'); }); // Initial load - if (hasReviews) { - Y.on("contentready", function (e) { - updateRequestsTable('reviews'); - }, "#reviews_table"); - } Y.on("contentready", function (e) { - updateRequestsTable("requestee"); + updateFlagTable("requestee"); }, "#requestee_table"); Y.on("contentready", function (e) { - updateRequestsTable("requester"); + updateFlagTable("requester"); }, "#requester_table"); }); }); diff --git a/extensions/MyDashboard/web/js/query.js b/extensions/MyDashboard/web/js/query.js index e5e0979a1..53139d27f 100644 --- a/extensions/MyDashboard/web/js/query.js +++ b/extensions/MyDashboard/web/js/query.js @@ -14,7 +14,7 @@ if (typeof(MyDashboard) == 'undefined') { $(function() { YUI({ base: 'js/yui3/', - combine: false, + combine: false, groups: { gallery: { combine: false, diff --git a/extensions/PhabBugz/lib/Util.pm b/extensions/PhabBugz/lib/Util.pm index a7ae98744..f2876366f 100644 --- a/extensions/PhabBugz/lib/Util.pm +++ b/extensions/PhabBugz/lib/Util.pm @@ -35,7 +35,6 @@ our @EXPORT = qw( create_revision_attachment get_attachment_revisions get_bug_role_phids - get_needs_review intersect is_attachment_phab_revision request @@ -206,48 +205,4 @@ sub set_phab_user { return Bugzilla->set_user($user, scope_guard => 1); } -sub get_needs_review { - my ($user) = @_; - $user //= Bugzilla->user; - return unless $user->id; - - my $phab_user = Bugzilla::Extension::PhabBugz::User->new_from_query( - { - ids => [ $user->id ] - } - ); - - return [] unless $phab_user; - - my $diffs = request( - 'differential.revision.search', - { - attachments => { - reviewers => 1, - }, - constraints => { - reviewerPHIDs => [$phab_user->phid], - statuses => ["open()"], - }, - order => 'newest', - } - ); - ThrowCodeError('phabricator_api_error', { reason => 'Malformed Response' }) - unless exists $diffs->{result}{data}; - - my @revisions; - foreach my $revision ( @{ $diffs->{result}{data} } ) { - foreach my $reviewer ( @{ $revision->{attachments}->{reviewers}->{reviewers} } ) { - if ( $reviewer->{reviewerPHID} eq $phab_user->phid - && $reviewer->{status} =~ /^(?:added|blocking)$/ ) - { - push @revisions, $revision; - last; - } - } - } - - return \@revisions; -} - 1; diff --git a/extensions/PhabBugz/lib/WebService.pm b/extensions/PhabBugz/lib/WebService.pm index fa9306667..19a758a70 100644 --- a/extensions/PhabBugz/lib/WebService.pm +++ b/extensions/PhabBugz/lib/WebService.pm @@ -16,29 +16,23 @@ use base qw(Bugzilla::WebService); use Bugzilla::Constants; use Bugzilla::Error; use Bugzilla::User; -use Bugzilla::Util qw(detaint_natural datetime_from time_ago trick_taint); +use Bugzilla::Util qw(detaint_natural trick_taint); use Bugzilla::WebService::Constants; use Bugzilla::Extension::PhabBugz::Constants; -use Bugzilla::Extension::PhabBugz::Util qw( - get_needs_review -); -use DateTime (); -use List::Util qw(first uniq); +use List::Util qw(first); use List::MoreUtils qw(any); use MIME::Base64 qw(decode_base64); use constant READ_ONLY => qw( check_user_enter_bug_permission check_user_permission_for_bug - needs_review ); use constant PUBLIC_METHODS => qw( check_user_enter_bug_permission check_user_permission_for_bug - needs_review set_build_target ); @@ -99,95 +93,6 @@ sub check_user_enter_bug_permission { }; } -sub needs_review { - my ($self, $params) = @_; - - $self->_check_phabricator(); - - my $user = Bugzilla->login(LOGIN_REQUIRED); - my $dbh = Bugzilla->dbh; - - my $reviews = get_needs_review(); - - my $authors = Bugzilla::Extension::PhabBugz::User->match({ - phids => [ - uniq - grep { defined } - map { $_->{fields}{authorPHID} } - @$reviews - ] - }); - - my %author_phab_to_id = map { $_->phid => $_->bugzilla_user->id } @$authors; - my %author_id_to_user = map { $_->bugzilla_user->id => $_->bugzilla_user } @$authors; - - # bug data - my $visible_bugs = $user->visible_bugs([ - uniq - grep { $_ } - map { $_->{fields}{'bugzilla.bug-id'} } - @$reviews - ]); - - # get all bug statuses and summaries in a single query to avoid creation of - # many bug objects - my %bugs; - if (@$visible_bugs) { - #<<< - my $bug_rows =$dbh->selectall_arrayref( - 'SELECT bug_id, bug_status, short_desc ' . - ' FROM bugs ' . - ' WHERE bug_id IN (' . join(',', ('?') x @$visible_bugs) . ')', - { Slice => {} }, - @$visible_bugs - ); - #>>> - %bugs = map { $_->{bug_id} => $_ } @$bug_rows; - } - - # build result - my $datetime_now = DateTime->now(time_zone => $user->timezone); - my @result; - foreach my $review (@$reviews) { - my $review_flat = { - id => $review->{id}, - title => $review->{fields}{title}, - url => Bugzilla->params->{phabricator_base_uri} . 'D' . $review->{id}, - }; - - # show date in user's timezone - my $datetime = DateTime->from_epoch( - epoch => $review->{fields}{dateModified}, - time_zone => 'UTC' - ); - $datetime->set_time_zone($user->timezone); - $review_flat->{updated} = $datetime->strftime('%Y-%m-%d %T %Z'); - $review_flat->{updated_fancy} = time_ago($datetime, $datetime_now); - - # review requester - if (my $author = $author_id_to_user{$author_phab_to_id{ $review->{fields}{authorPHID} }}) { - $review_flat->{author_name} = $author->name; - $review_flat->{author_email} = $author->email; - } - else { - $review_flat->{author_name} = 'anonymous'; - $review_flat->{author_email} = 'anonymous'; - } - - # referenced bug - if (my $bug_id = $review->{fields}{'bugzilla.bug-id'}) { - my $bug = $bugs{$bug_id}; - $review_flat->{bug_id} = $bug_id; - $review_flat->{bug_status} = $bug->{bug_status}; - $review_flat->{bug_summary} = $bug->{short_desc}; - } - - push @result, $review_flat; - } - - return { result => \@result }; -} - sub set_build_target { my ( $self, $params ) = @_; @@ -257,12 +162,6 @@ sub rest_resources { }, }, }, - # Review requests - qw{^/phabbugz/needs_review$}, { - GET => { - method => 'needs_review', - }, - } ]; } |