Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-9129: Adjust JSON serialization for RG ratings on release request. #470

Merged
merged 3 commits into from Mar 1, 2017

Conversation

Zastai
Copy link
Contributor

@Zastai Zastai commented Feb 17, 2017

The first commit is straightforward - a release has no ratings so should not try to serialize them.

The second part aims to replicate the XML serializer's behaviour - a request for ratings on a release is "forwarded" to the release's RG (if it's also requested).
However, the JSON serializer is made up of a bunch of disjoint sources, and the bit that handles ratings has no way of knowing it's handling a release group that is being serialized as part of a release request.
If I change MusicBrainz::Server::WebService::Serializer::JSON::2::Role::Rating to ignore the toplevel flag, all release groups (including those in (requested) relationships) in all requests will serialize their ratings; instead I (ab)use $inc to pass a special flag for it to pick up.

I'm not very happy with that, but the only other way I see is to change the basic serialize() signature and either add an extra parameter, or change the semantics of the current $toplevel flag (e.g. by calling it $flags, and changing tests of $toplevel to checks for $flags->{TOPLEVEL}). Other approaches/suggestions welcome.

@mwiencek
Copy link
Member

The better method would be to use local within a block to temporarily override a package-level variable.

I guess the only place to put the variable would be JSON/2/Role/Rating.pm. So you'd need something like this in JSON/2/Release.pm:

{
    local $MusicBrainz::Server::WebService::Serializer::JSON::2::Role::Rating::show_ratings = 0;
    # $show_ratings is only 0 within this block.
};

@Zastai
Copy link
Contributor Author

Zastai commented Feb 21, 2017

Good idea - will force-push a fixup commit using that approach.

@Zastai
Copy link
Contributor Author

Zastai commented Feb 21, 2017

That should do it. Tests don't seem to affected.

if $inc && $inc->release_groups;
if ($inc && $inc->release_groups)
{
# MBS-9129: If ratings are requested (even though a release doesn't have any), those of the release group should be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer always limiting comments to <80 chars per line, since it makes them much easier to read. (Usually code too, but I don't strictly follow that.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm used to 132 as 80 can get very restrictive (not so much for perl, but for C++ it is), so my emacs is set up for that.
I can reformat those lines, no problem.

@mwiencek
Copy link
Member

BTW, is adding a test something you'd be willing to look into?

@Zastai
Copy link
Contributor Author

Zastai commented Feb 24, 2017

Sure, I can look at making a test, depending a little on what it all entails.
Will have a look at the .t files and see where I get.

@Zastai
Copy link
Contributor Author

Zastai commented Feb 26, 2017

Tests added.
Once everything else is fine, I'll squash 53e8036 into 5cee0a9 and force push.

@mwiencek
Copy link
Member

LGTM.

Without inc=release-groups, it should be a no-op. Otherwise, the linked RG's ratings are returned.
Also tests for an "unauthorised" response when user ratings are requested without proper credentials.
@Zastai
Copy link
Contributor Author

Zastai commented Mar 1, 2017

Comment fixup squashed. Probably ready for merge now.

@mwiencek mwiencek merged commit cf6e279 into metabrainz:master Mar 1, 2017
@Zastai Zastai deleted the mbs-9129 branch March 1, 2017 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants