Skip to content

Commit

Permalink
Merge pull request #2326 from reosarevok/MBS-12047
Browse files Browse the repository at this point in the history
MBS-12047: Support browsing artist RGs in /ws/2 as in "official" website index
  • Loading branch information
reosarevok authored Sep 18, 2023
2 parents 183e95f + fa48a4a commit 5f316eb
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 16 deletions.
9 changes: 7 additions & 2 deletions lib/MusicBrainz/Server/Controller/WS/2/ReleaseGroup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ my $ws_defs = Data::OptList::mkopt([
method => 'GET',
linked => [ qw(artist release collection) ],
inc => [ qw(aliases artist-credits annotation
_relations tags user-tags genres user-genres ratings user-ratings) ],
_relations release-group-status
tags user-tags genres user-genres
ratings user-ratings) ],
optional => [ qw(fmt limit offset) ],
},
'release-group' => {
Expand Down Expand Up @@ -106,7 +108,10 @@ sub release_group_browse : Private
my $artist = $c->model('Artist')->get_by_gid($id);
$c->detach('not_found') unless ($artist);

my $show_all = 1;
# Allows requesting only "official" releases with 'website-default'
my $show_all = $c->stash->{release_group_status} eq 'website-default'
? 0
: 1;
my @tmp = $c->model('ReleaseGroup')->find_by_artist(
$artist->id, $show_all, $limit, $offset, filter => { type => $c->stash->{type} });
$rgs = $self->make_list(@tmp, $offset);
Expand Down
23 changes: 22 additions & 1 deletion lib/MusicBrainz/Server/WebService/Validator.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package MusicBrainz::Server::WebService::Validator;
use List::AllUtils qw( uniq );
use List::AllUtils qw( any uniq );
use MooseX::Role::Parameterized;
use namespace::autoclean;
use aliased 'MusicBrainz::Server::WebService::WebServiceInc';
Expand Down Expand Up @@ -172,6 +172,26 @@ sub validate_status
return \@ret;
}

sub validate_release_group_status
{
my ($c, $resource, $release_group_status, $inc) = @_;

return unless $release_group_status;

unless ($resource eq 'release-group' && exists $c->req->params->{artist})
{
$c->stash->{error} = 'release-group-status is not a valid parameter unless release groups are browsed by artist.';
$c->detach('bad_req');
}

unless (any { $_ =~ /^$release_group_status$/ } qw/ website-default all /) {
$c->stash->{error} = "$release_group_status is not a valid value for the release-group-status parameter.";
$c->detach('bad_req');
}

return $release_group_status;
}

sub validate_linked
{
my ($c, $resource, $def) = @_;
Expand Down Expand Up @@ -341,6 +361,7 @@ role {
if ($inc && $version eq '2') {
$c->stash->{type} = validate_type($c, $resource, $c->req->params->{type}, $inc);
$c->stash->{status} = validate_status($c, $resource, $c->req->params->{status}, $inc);
$c->stash->{release_group_status} = validate_release_group_status($c, $resource, $c->req->params->{'release-group-status'}, $inc);
}
# Check if authorization is required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ ws_test 'browse releases via label',
</release>
<release id="3b3d130a-87a8-4a47-b9fb-920f2530d134">
<title>Repercussions</title>
<status id="4e304316-386d-3409-af2e-78857eec5cfe">Official</status>
<status id="1156806e-d06a-38bd-83f0-cf2284a808b9">Bootleg</status>
<quality>normal</quality>
<text-representation>
<language>eng</language>
Expand Down
29 changes: 29 additions & 0 deletions t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseReleaseGroup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,35 @@ ws_test 'browse singles via artist',
<release-group-list count="0" />
</metadata>';

ws_test 'browse official release groups via artist',
'/release-group?artist=472bc127-8861-45e8-bc9e-31e8dd32de7a&release-group-status=website-default&inc=artist-credits+tags+ratings' =>
'<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<release-group-list count="1">
<release-group type="Album" type-id="f529b476-6e62-324f-b0aa-1f3e33d313fc" id="22b54315-6e51-350b-bb34-e6e16f7688bd">
<title>My Demons</title>
<first-release-date>2007-01-29</first-release-date>
<primary-type id="f529b476-6e62-324f-b0aa-1f3e33d313fc">Album</primary-type>
<artist-credit>
<name-credit>
<artist id="472bc127-8861-45e8-bc9e-31e8dd32de7a" type="Person" type-id="b6e035f4-3ce9-331c-97df-83397230b0df">
<name>Distance</name>
<sort-name>Distance</sort-name>
<disambiguation>UK dubstep artist Greg Sanders</disambiguation>
<rating votes-count="1">5</rating>
</artist>
</name-credit>
</artist-credit>
<tag-list>
<tag count="2"><name>dubstep</name></tag>
<tag count="1"><name>electronic</name></tag>
<tag count="1"><name>grime</name></tag>
</tag-list>
<rating votes-count="1">4</rating>
</release-group>
</release-group-list>
</metadata>';

};

1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,52 @@ test 'browse singles via artist' => sub {
};
};

test 'browse official release groups via artist' => sub {

MusicBrainz::Server::Test->prepare_test_database(shift->c, '+webservice');

ws_test_json 'browse release group via artist',
'/release-group?artist=472bc127-8861-45e8-bc9e-31e8dd32de7a&release-group-status=website-default&inc=artist-credits+tags+genres+ratings' =>
{
'release-group-count' => 1,
'release-group-offset' => 0,
'release-groups' => [
{
id => '22b54315-6e51-350b-bb34-e6e16f7688bd',
title => 'My Demons',
'first-release-date' => '2007-01-29',
'primary-type' => 'Album',
'primary-type-id' => 'f529b476-6e62-324f-b0aa-1f3e33d313fc',
'secondary-types' => [],
'secondary-type-ids' => [],
'artist-credit' => [
{
name => 'Distance',
artist => {
id => '472bc127-8861-45e8-bc9e-31e8dd32de7a',
name => 'Distance',
'sort-name' => 'Distance',
disambiguation => 'UK dubstep artist Greg Sanders',
tags => [],
genres => [],
'type' => 'Person',
'type-id' => 'b6e035f4-3ce9-331c-97df-83397230b0df',
},
joinphrase => '',
}],
tags => [
{ count => 2, name => 'dubstep' },
{ count => 1, name => 'electronic' },
{ count => 1, name => 'grime' }],
genres => [
{ count => 2, disambiguation => '', id => '1b50083b-1afa-4778-82c8-548b309af783', name => 'dubstep' },
{ count => 1, disambiguation => '', id => '89255676-1f14-4dd8-bbad-fca839d6aff4', name => 'electronic' },
{ count => 1, disambiguation => 'stuff', id => '51cfaac4-6696-480b-8f1b-27cfc789109c', name => 'grime' }],
'rating' => { 'votes-count' => 1, 'value' => 4 },
disambiguation => '',
}]
};
};

1;

Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ test 'browse releases via label' => sub {
{
id => '3b3d130a-87a8-4a47-b9fb-920f2530d134',
title => 'Repercussions',
status => 'Official',
'status-id' => '4e304316-386d-3409-af2e-78857eec5cfe',
status => 'Bootleg',
'status-id' => '1156806e-d06a-38bd-83f0-cf2284a808b9',
quality => 'normal',
'text-representation' => { language => 'eng', script => 'Latn' },
'cover-art-archive' => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ test 'artist lookup with releases and discids' => sub {
{
id => '3b3d130a-87a8-4a47-b9fb-920f2530d134',
title => 'Repercussions',
status => 'Official',
'status-id' => '4e304316-386d-3409-af2e-78857eec5cfe',
status => 'Bootleg',
'status-id' => '1156806e-d06a-38bd-83f0-cf2284a808b9',
quality => 'normal',
'text-representation' => { language => 'eng', script => 'Latn' },
date => '2008-11-17',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ test 'label lookup with releases, inc=media' => sub {
{
id => '3b3d130a-87a8-4a47-b9fb-920f2530d134',
title => 'Repercussions',
status => 'Official',
'status-id' => '4e304316-386d-3409-af2e-78857eec5cfe',
status => 'Bootleg',
'status-id' => '1156806e-d06a-38bd-83f0-cf2284a808b9',
quality => 'normal',
'text-representation' => { language => 'eng', script => 'Latn' },
date => '2008-11-17',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ test 'release group lookup with releases' => sub {
{
id => '3b3d130a-87a8-4a47-b9fb-920f2530d134',
title => 'Repercussions',
status => 'Official',
'status-id' => '4e304316-386d-3409-af2e-78857eec5cfe',
status => 'Bootleg',
'status-id' => '1156806e-d06a-38bd-83f0-cf2284a808b9',
quality => 'normal',
'text-representation' => { language => 'eng', script => 'Latn' },
date => '2008-11-17',
Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupArtist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ ws_test 'artist lookup with releases and discids',
</release>
<release id="3b3d130a-87a8-4a47-b9fb-920f2530d134">
<title>Repercussions</title>
<status id="4e304316-386d-3409-af2e-78857eec5cfe">Official</status>
<status id="1156806e-d06a-38bd-83f0-cf2284a808b9">Bootleg</status>
<quality>normal</quality>
<text-representation>
<language>eng</language>
Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupLabel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ ws_test 'label lookup with releases, inc=media',
</release>
<release id="3b3d130a-87a8-4a47-b9fb-920f2530d134">
<title>Repercussions</title>
<status id="4e304316-386d-3409-af2e-78857eec5cfe">Official</status>
<status id="1156806e-d06a-38bd-83f0-cf2284a808b9">Bootleg</status>
<quality>normal</quality>
<text-representation>
<language>eng</language>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ws_test 'release group lookup with releases',
<release-list count="1">
<release id="3b3d130a-87a8-4a47-b9fb-920f2530d134">
<title>Repercussions</title>
<status id="4e304316-386d-3409-af2e-78857eec5cfe">Official</status>
<status id="1156806e-d06a-38bd-83f0-cf2284a808b9">Bootleg</status>
<quality>normal</quality>
<text-representation>
<language>eng</language>
Expand Down
2 changes: 1 addition & 1 deletion t/sql/webservice.sql
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ INSERT INTO release (status, release_group, edits_pending, packaging, id, qualit
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (1, 155364, 0, NULL, 243064, -1, '2010-02-22 02:01:29.413661+00', 28, 120, 'For Beginner Piano', 11545, NULL, '', 'fbe4eb72-0f24-3875-942e-f581589713d4');
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (1, 155364, 0, NULL, 654729, -1, '2010-02-22 02:01:29.413661+00', 28, 120, 'For Beginner Piano', 11545, '', '', 'dd66bfdd-6097-32e3-91b6-67f47ba25d4c');
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (1, 597897, 0, NULL, 246898, -1, '2010-06-02 13:52:58.277743+00', 28, 120, 'My Demons', 427385, '600116817020', '', 'adcf7b48-086e-48ee-b420-1001f88d672f');
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (1, 761939, 0, NULL, 446581, -1, '2010-06-02 13:25:54.789939+00', 28, 120, 'Repercussions', 427385, '600116822123', '', '3b3d130a-87a8-4a47-b9fb-920f2530d134');
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (3, 761939, 0, NULL, 446581, -1, '2010-06-02 13:25:54.789939+00', 28, 120, 'Repercussions', 427385, '600116822123', '', '3b3d130a-87a8-4a47-b9fb-920f2530d134');
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (1, 403214, 0, NULL, 59662, -1, '2009-08-17 08:23:42.424855+00', 28, 120, 'the Love Bug', 135345, '4988064451180', '', 'aff4a693-5970-4e2e-bd46-e2ee49c22de7');
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (4, 326504, 0, NULL, 4675, -1, NULL, 28, 198, 'LOVE & HONESTY', 9496, NULL, '', '757a1723-3769-4298-89cd-48d31177852a');
INSERT INTO release (status, release_group, edits_pending, packaging, id, quality, last_updated, script, language, name, artist_credit, barcode, comment, gid) VALUES (1, 326504, 0, NULL, 59312, -1, '2009-09-24 19:33:36.305407+00', 85, 198, 'LOVE & HONESTY', 9496, '4988064173907', '', 'cacc586f-c2f2-49db-8534-6f44b55196f2');
Expand Down

0 comments on commit 5f316eb

Please sign in to comment.