Skip to content

Commit

Permalink
MBS-12792: Hide ratings by spammer users
Browse files Browse the repository at this point in the history
To deal better with spammer tags and ratings will need a
schema change (MBS-12794), but for now we can at least hide links
to spammer profiles from the ratings page and make it clear to users
that the ratings might be dodgy.
  • Loading branch information
reosarevok committed Dec 5, 2023
1 parent 2f5511a commit cc1a116
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/MusicBrainz/Server/Controller/Role/Rating.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ sub ratings : Chained('load') PathPart('ratings')

my @public_ratings;
my $private_rating_count = 0;
my $spammer_rating_count = 0;

for my $rating (@ratings) {
# We don't want spammer ratings, but they're still
# part of the calculated rating.
# Once MBS-12794 is done we can just skip these silently
if ($rating->editor->is_spammer) {
$spammer_rating_count++;
next;
}

if ($rating->editor->preferences->public_ratings) {
push @public_ratings, $rating;
} else {
Expand All @@ -43,6 +52,7 @@ sub ratings : Chained('load') PathPart('ratings')
$entity_properties->{reviews} ? (mostRecentReview => to_json_object($entity->most_recent_review)) : (),
publicRatings => to_json_array(\@public_ratings),
privateRatingCount => $private_rating_count,
spammerRatingCount => $spammer_rating_count,
);

$c->stash(
Expand Down
28 changes: 24 additions & 4 deletions root/entity/Ratings.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Props = {
+mostRecentReview: CritiqueBrainzReviewT,
+privateRatingCount: number,
+publicRatings: $ReadOnlyArray<RatingT>,
+spammerRatingCount: number,
};

const Ratings = ({
Expand All @@ -33,11 +34,14 @@ const Ratings = ({
mostRecentReview,
privateRatingCount,
publicRatings,
spammerRatingCount,
}: Props): React$MixedElement => {
const entityType = entity.entityType;
const entityProperties = ENTITIES[entity.entityType];
const LayoutComponent = chooseLayoutComponent(entityType);
const hasRatings = publicRatings.length || privateRatingCount > 0;
const hasRatings = publicRatings.length ||
privateRatingCount > 0 ||
spammerRatingCount > 0;

return (
<LayoutComponent
Expand Down Expand Up @@ -72,9 +76,25 @@ const Ratings = ({
)}
</p>
) : null}
{l('Average rating:')}
{' '}
<StaticRatingStars rating={entity.rating} />
{/* Remove this once MBS-12794 skips spammers for averages */}
{spammerRatingCount > 0 ? (
<p>
{exp.ln(
'{count} hidden rating by a spammer user.',
'{count} hidden ratings by spammer users.',
spammerRatingCount,
{count: spammerRatingCount},
)}
</p>
) : null}
{publicRatings.length === 0 && privateRatingCount === 0
? null : (
<>
{l('Average rating:')}
{' '}
<StaticRatingStars rating={entity.rating} />
</>
)}
</>
) : (
<p>
Expand Down

0 comments on commit cc1a116

Please sign in to comment.