Skip to content

Commit

Permalink
MBS-12930: Validate relationship fields on Perl level
Browse files Browse the repository at this point in the history
We were showing an error for this on the JS level, but
(because the submit button is a buggy knockout mess and wasn't disabled)
it was still possible to try to submit a seeded relationship
without selecting a type, which would cause an ISE.
Now it properly detects that in fact something is missing and blocks
it from submitting.

I don't think the error here is currently being shown on the browser,
but since it's the same string as for the JS one, it should be fine.
  • Loading branch information
reosarevok committed Feb 20, 2023
1 parent fa1acb3 commit 8881436
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/MusicBrainz/Server/Form/Field/Relationship.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package MusicBrainz::Server::Form::Field::Relationship;
use strict;
use warnings;


use HTML::FormHandler::Moose;
use MusicBrainz::Server::Translation qw( l );
extends 'HTML::FormHandler::Field::Compound';

has_field 'relationship_id' => (
Expand Down Expand Up @@ -87,4 +87,15 @@ sub is_empty {
return 0;
}

after 'validate' => sub {
my $self = shift;
my $link_type = $self->field('link_type_id')->value;

if (!$link_type) {
return $self->add_error(l('You must select a relationship type and target entity for every relationship.'));
}

return 1;
};

1;

0 comments on commit 8881436

Please sign in to comment.