From f527518bcc87a21522a3ac2f8b1a98c9f36fba59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Thu, 4 Nov 2021 12:31:53 +0200 Subject: [PATCH 1/2] MBS-12047: Support browsing artist RGs in /ws/2 as in website index This is useful to be able to easily get through the API the same list of release groups we show by default on the MusicBrainz site itself. I chose to use a new 'release-group-status' parameter rather than the existing 'status' parameter already in use for releases because 'status' can be used to filter the releases via inc=. I'm using "website-default" for the option matching the website since while we call it "official" on the site, is a wider concept than what we call official for releases (including also for example RGs with only no-status-set releases) and we might want to allow querying only RGs containing official releases in the future. --- .../Server/Controller/WS/2/ReleaseGroup.pm | 9 ++++++-- .../Server/WebService/Validator.pm | 23 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/MusicBrainz/Server/Controller/WS/2/ReleaseGroup.pm b/lib/MusicBrainz/Server/Controller/WS/2/ReleaseGroup.pm index 5c0cad7fff2..8a25ce539e1 100644 --- a/lib/MusicBrainz/Server/Controller/WS/2/ReleaseGroup.pm +++ b/lib/MusicBrainz/Server/Controller/WS/2/ReleaseGroup.pm @@ -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' => { @@ -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); diff --git a/lib/MusicBrainz/Server/WebService/Validator.pm b/lib/MusicBrainz/Server/WebService/Validator.pm index a8623fc579e..36e9a1aa683 100644 --- a/lib/MusicBrainz/Server/WebService/Validator.pm +++ b/lib/MusicBrainz/Server/WebService/Validator.pm @@ -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'; @@ -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) = @_; @@ -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. From fa48a4a19591ac56e4584db4717d2376f6b88bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Thu, 4 Nov 2021 12:33:24 +0200 Subject: [PATCH 2/2] MBS-12047: Support browsing artist RGs in /ws/2 as in website index (tests) Split into a separate commit for clarity - I thought the easiest way to change this would be to move an existing release to bootleg, which also makes it so we have bootlegs in more places on tests (we had no Bootleg in the WS tests at all). --- .../Server/Controller/WS/2/BrowseRelease.pm | 2 +- .../Controller/WS/2/BrowseReleaseGroup.pm | 29 ++++++++++++ .../WS/2/JSON/BrowseReleaseGroups.pm | 47 +++++++++++++++++++ .../Controller/WS/2/JSON/BrowseReleases.pm | 4 +- .../Controller/WS/2/JSON/LookupArtist.pm | 4 +- .../Controller/WS/2/JSON/LookupLabel.pm | 4 +- .../WS/2/JSON/LookupReleaseGroup.pm | 4 +- .../Server/Controller/WS/2/LookupArtist.pm | 2 +- .../Server/Controller/WS/2/LookupLabel.pm | 2 +- .../Controller/WS/2/LookupReleaseGroup.pm | 2 +- t/sql/webservice.sql | 2 +- 11 files changed, 89 insertions(+), 13 deletions(-) diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseRelease.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseRelease.pm index 4c99e99f0e7..5e1a7ef2ccd 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseRelease.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseRelease.pm @@ -108,7 +108,7 @@ ws_test 'browse releases via label', Repercussions - Official + Bootleg normal eng diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseReleaseGroup.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseReleaseGroup.pm index b46e924bfcc..cb670e4a6bb 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseReleaseGroup.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/BrowseReleaseGroup.pm @@ -101,6 +101,35 @@ ws_test 'browse singles via artist', '; +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' => + ' + + + + My Demons + 2007-01-29 + Album + + + + Distance + Distance + UK dubstep artist Greg Sanders + 5 + + + + + dubstep + electronic + grime + + 4 + + +'; + }; 1; diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleaseGroups.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleaseGroups.pm index 9980acb7c88..1ca4c71bb41 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleaseGroups.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleaseGroups.pm @@ -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; diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleases.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleases.pm index 222c6fea621..2d6f32605ba 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleases.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/BrowseReleases.pm @@ -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' => { diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupArtist.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupArtist.pm index bbf2aa992d2..4c212d56375 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupArtist.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupArtist.pm @@ -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', diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupLabel.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupLabel.pm index 88276d302a9..f9ed0219465 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupLabel.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupLabel.pm @@ -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', diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupReleaseGroup.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupReleaseGroup.pm index 7e8e9660d07..d53ce04de10 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupReleaseGroup.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/JSON/LookupReleaseGroup.pm @@ -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', diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupArtist.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupArtist.pm index 9984738b210..47887aa7d0c 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupArtist.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupArtist.pm @@ -231,7 +231,7 @@ ws_test 'artist lookup with releases and discids', Repercussions - Official + Bootleg normal eng diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupLabel.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupLabel.pm index e906cb4e6d6..025b1ac5e2e 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupLabel.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupLabel.pm @@ -135,7 +135,7 @@ ws_test 'label lookup with releases, inc=media', Repercussions - Official + Bootleg normal eng diff --git a/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupReleaseGroup.pm b/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupReleaseGroup.pm index ea1e49efded..714471ae697 100644 --- a/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupReleaseGroup.pm +++ b/t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupReleaseGroup.pm @@ -56,7 +56,7 @@ ws_test 'release group lookup with releases', Repercussions - Official + Bootleg normal eng diff --git a/t/sql/webservice.sql b/t/sql/webservice.sql index c7eb71e0d7b..91efb502abb 100644 --- a/t/sql/webservice.sql +++ b/t/sql/webservice.sql @@ -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');