Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a22b712
Bug 2094122 - Migrate the InvalidBugHelper REST resource to native Mo…
Xzzz Nov 17, 2026
01f3262
Bug 2094122 - Migrate the Bitly REST resource to native Mojo API
Xzzz Nov 17, 2026
1dfb750
Bug 2094122 - Migrate the ProdCompSearch REST resource to native Mojo…
Xzzz Nov 17, 2026
d8b9ef1
Bug 2094122 - Migrate the EditComments REST resource to native Mojo API
Xzzz Nov 17, 2026
7d7e6fd
Bug 2094122 - Migrate the ComponentWatching REST resource to native M…
Xzzz Nov 18, 2026
639f232
Bug 2094122 - Migrate the MyDashboard REST resource to native Mojo API
Xzzz Nov 18, 2026
3686a95
Bug 2094122 - Fix - Refuse an unknown type in MyDashboard run_flag_query
Xzzz Nov 18, 2026
45a6fab
Bug 2094122 - Migrate the PhabBugz REST resource to native Mojo API
Xzzz Nov 18, 2026
4af97f4
Bug 2094122 - Migrate the Review REST resource to native Mojo API
Xzzz Nov 18, 2026
bab1d8b
Bug 2094122 - Migrate the BugModal REST resource to native Mojo API
Xzzz Nov 18, 2026
e3b983a
Bug 2094122 - Fix - Keep the path id on BugModal GET routes
Xzzz Nov 18, 2026
7c98353
Bug 2094122 - Fix - Answer an empty ProdCompSearch search with param_…
Xzzz Nov 18, 2026
250add2
Bug 2094122 - Fix - Accept an empty value in Review flag_activity paths
Xzzz Nov 18, 2026
904f10f
Bug 2094122 - Fix - Read the EditComments comment ID from the path only
Xzzz Nov 19, 2026
c2fc050
Bug 2094122 - Test - Refuse PhabBugz bug_revisions on a bug the user …
Xzzz Nov 19, 2026
923ab55
Bug 2094122 - Test - Cover private comments and hidden bugs in the Ed…
Xzzz Nov 19, 2026
e30e77d
Bug 2094122 - Test - Cover hidden bugs and non-taggers in the BugModa…
Xzzz Nov 19, 2026
6d0c336
Bug 2094122 - Test - Cover private comments and hidden bugs in MyDash…
Xzzz Nov 19, 2026
ac8a508
Bug 2094122 - Test - Refuse InvalidBugHelper close for non-editbugs c…
Xzzz Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions extensions/Bitly/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ our $VERSION = '1';

use Bugzilla;

sub webservice {
my ($self, $args) = @_;
$args->{dispatch}->{Bitly} = "Bugzilla::Extension::Bitly::WebService";
}

sub config_modify_panels {
my ($self, $args) = @_;
push @{$args->{panels}->{advanced}->{params}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,59 @@
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::Bitly::WebService;
package Bugzilla::Extension::Bitly::API::V1::Bitly;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::WebService);
use Mojo::Base qw( Mojolicious::Controller );

use Bugzilla;
use Bugzilla::CGI;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Search;
use Bugzilla::Search::Quicksearch;
use Bugzilla::Util qw(mojo_user_agent);
use Bugzilla::API::V1::Util qw(validate);
use JSON;
use LWP::UserAgent;
use URI;
use URI::Escape;
use URI::QueryParam;

use constant PUBLIC_METHODS => qw(
list
shorten
);

sub _validate_uri {
my ($self, $params) = @_;

# extract URL from params
if (!defined $params->{url}) {
ThrowCodeError('param_required', {function => 'Bitly.shorten', param => 'url'});
}
my $url = ref($params->{url}) ? $params->{url}->[0] : $params->{url};

# only allow buglist queries for this Bugzilla install
my $uri = URI->new($url);
$uri->query(undef);
$uri->fragment(undef);
if ($uri->as_string ne Bugzilla->localconfig->urlbase . 'buglist.cgi') {
ThrowUserError('bitly_unsupported');
}

return URI->new($url);
sub setup_routes {
my ($class, $r) = @_;
$r->get('/bitly/shorten')->to('Bitly::API::V1::Bitly#shorten');
$r->get('/bitly/list')->to('Bitly::API::V1::Bitly#list');
}

# GET /bitly/shorten?url=<buglist.cgi URL>
#
# Shortens a buglist URL of this Bugzilla, without its user-specific list_id.
# Returns {url}.
sub shorten {
my ($self) = shift;
my $uri = $self->_validate_uri(@_);
my ($self) = @_;
Bugzilla->usage_mode(USAGE_MODE_MOJO_REST);
$self->bugzilla->login;

# the list_id is user-specific, remove it
my $uri = $self->_validate_uri;
$uri->query_param_delete('list_id');

return $self->_bitly($uri);
return $self->render(json => $self->_bitly($uri));
}

# GET /bitly/list?url=<buglist.cgi URL>
#
# Runs the search and shortens a buglist URL of the matching bug IDs, so the
# link shows the same bugs whoever opens it. Returns {url}.
sub list {
my ($self) = shift;
my $uri = $self->_validate_uri(@_);
my ($self) = @_;
Bugzilla->usage_mode(USAGE_MODE_MOJO_REST);
$self->bugzilla->login;

my $uri = $self->_validate_uri;

# map params to cgi vars, converting quicksearch if required
my $params
= $uri->query_param('quicksearch')
? Bugzilla::CGI->new(quicksearch($uri->query_param('quicksearch')))->Vars
: Bugzilla::CGI->new($uri->query)->Vars;

# execute the search
my $search = Bugzilla::Search->new(
params => $params,
fields => ['bug_id'],
Expand All @@ -89,32 +75,42 @@ sub list {
{message => "Too many bugs returned by search"});
}

# shorten
return $self->_bitly($uri);
return $self->render(json => $self->_bitly($uri));
}

# Only buglist queries of this Bugzilla can be shortened.
sub _validate_uri {
my ($self) = @_;

my $url = $self->every_param('url')->[0];
defined $url
|| ThrowCodeError('param_required',
{function => 'Bitly.shorten', param => 'url'});

my $uri = URI->new($url);
$uri->query(undef);
$uri->fragment(undef);
if ($uri->as_string ne Bugzilla->localconfig->urlbase . 'buglist.cgi') {
ThrowUserError('bitly_unsupported');
}

return URI->new($url);
}

sub _bitly {
my ($self, $uri) = @_;

# Make the request
my $ua = mojo_user_agent();
my $response
= $ua->post('https://api-ssl.bitly.com/v4/shorten' =>
= mojo_user_agent()
->post('https://api-ssl.bitly.com/v4/shorten' =>
{'Authorization' => 'Bearer ' . Bugzilla->params->{bitly_token}} => json =>
{long_url => $uri->as_string})->result;
{long_url => $uri->as_string})
->result;
if (!$response->is_success) {
ThrowUserError('bitly_failure', {message => $response->message});
}

# return just the short URL
return {url => $response->json->{link}};
}

sub rest_resources {
return [
qr{^/bitly/shorten$}, {GET => {method => 'shorten',},},
qr{^/bitly/list$}, {GET => {method => 'list',},},
];
}

1;
81 changes: 81 additions & 0 deletions extensions/Bitly/t/bmo/bitly.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env perl
# 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.

use strict;
use warnings;
use 5.10.1;
use lib qw( . lib local/lib/perl5 );

BEGIN {
$ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf';
$ENV{BUGZILLA_DISABLE_HOSTAGE} = 1;
}

use Test::More;
use Test::Mojo;
use Mojo::UserAgent;
use Mojolicious;

use Bugzilla;
BEGIN { Bugzilla->extensions }
use Bugzilla::Extension::Bitly::API::V1::Bitly;

# Stand-in for the Bitly API: echoes the long URL back as the short link.
my @sent;
my $bitly = Mojolicious->new;
$bitly->routes->post(
'/v4/shorten' => sub {
my $c = shift;
push @sent, $c->req->json->{long_url};
$c->render(json => {link => 'https://bit.ly/' . scalar @sent});
}
);
{
no warnings 'redefine';
*Bugzilla::Extension::Bitly::API::V1::Bitly::mojo_user_agent = sub {
my $ua = Mojo::UserAgent->new;
$ua->server->app($bitly);
$ua->on(
start => sub {
my $url = $_[1]->req->url;
$url->scheme('http')->host('127.0.0.1')->port($ua->server->url->port);
}
);
return $ua;
};
}

my $urlbase = Bugzilla->localconfig->urlbase;
my $t = Test::Mojo->new('Bugzilla::App');

$t->get_ok('/rest/bitly/shorten')
->status_is(400)
->json_like('/message' => qr/url/, 'url is required');

$t->get_ok('/rest/bitly/shorten' => form =>
{url => 'https://example.com/buglist.cgi?bug_id=1'})
->status_is(400)
->json_like('/message' => qr/not supported/, 'other sites are refused');

$t->get_ok('/rest/bitly/shorten' => form =>
{url => "${urlbase}buglist.cgi?bug_status=NEW&list_id=42"})
->status_is(200)
->json_is('/url' => 'https://bit.ly/1');
is($sent[-1], "${urlbase}buglist.cgi?bug_status=NEW", 'list_id is dropped');

$t->get_ok(
'/rest/bitly/list' => form => {url => "${urlbase}buglist.cgi?bug_id=1,2"})
->status_is(200)
->json_is('/url' => 'https://bit.ly/2');
like(
$sent[-1],
qr{^\Q${urlbase}\Ebuglist\.cgi\?bug_id=[\d,]*$},
'list shortens a bug_id only URL'
);

done_testing;
6 changes: 0 additions & 6 deletions extensions/BugModal/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ sub bug_start_of_set_all {
}
}

sub webservice {
my ($self, $args) = @_;
my $dispatch = $args->{dispatch};
$dispatch->{bug_modal} = 'Bugzilla::Extension::BugModal::WebService';
}

sub install_before_final_checks {
my ($self, $args) = @_;
remove_setting('ui_experiments');
Expand Down
Loading