Skip to content

Commit

Permalink
Prevent modifying entity type of attributes
Browse files Browse the repository at this point in the history
There is no good reason to allow modifying entity type of
CollectionType and SeriesType attributes.  The only use case would
be to fix careless mistake before the edited attribute gets being
used.  This is safer and simpler to disallow changing it altogether
rather than check related entities and parent/children attributes.
  • Loading branch information
y-van-z committed Feb 27, 2017
1 parent 3db8403 commit 73daae6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/MusicBrainz/Server/Controller/Admin/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ sub edit : Chained('attribute_base') Args(1) RequireAuth(account_admin) {
my $form = $c->form( form => $form_name, init_object => $attr );

if ($c->form_posted && $form->process( params => $c->req->params )) {
$form->field("entity_type")->value( $attr->entity_type );

$c->model('MB')->with_transaction(sub {
$c->model($model)->update($id, { map { $_->name => $_->value } $form->edit_fields });
});
Expand Down
7 changes: 7 additions & 0 deletions root/admin/attributes/form.tt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
[% ELSE %]
[%~ IF model == "CollectionType" || model == "SeriesType" ~%]
[% form_row_select(r, 'entity_type', add_colon(l('Entity type'))) %]
[%~ IF r.form.field('entity_type').value.size ~%]
<script>//<![CDATA[
$(function () {
$('#id-attr\\.entity_type').prop('disabled', true);
});
//]]></script>
[%~ END ~%]
[%~ END ~%]

[% form_row_select(r, 'parent_id', add_colon(l('Parent'))) %]
Expand Down

0 comments on commit 73daae6

Please sign in to comment.