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-9215: Add entity type to attribute editing form #471

Merged
merged 2 commits into from Mar 1, 2017

Conversation

yvanzo
Copy link
Contributor

@yvanzo yvanzo commented Feb 19, 2017

Collection and series types admin editing form missed entity type.

This adds support for entering entity type without specific check.

Collection and series types admin editing form missed entity type.

This adds support for entering entity type without specific check.
sub options_parent_id {
my ($self, $model) = @_;
return select_options_tree($self->ctx, $self->ctx->stash->{model}, accessor => 'name');
}

sub options_entity_type {
my ($self) = @_;
return map { $_ => $_ } sort { $a cmp $b } entities_with('collections');
Copy link
Member

Choose a reason for hiding this comment

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

Apparently this works with lists too (elsewhere we use array refs).

@mwiencek
Copy link
Member

Ideally, it would validate that the parent attribute has the same entity type, but hopefully admins won't make that mistake.

Copy link
Member

@mwiencek mwiencek left a comment

Choose a reason for hiding this comment

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

On second thought, it'd be dangerous if the entity type of an existing collection or series type was changed, so I think we should at least validate that (that the type isn't being used).

@yvanzo
Copy link
Contributor Author

yvanzo commented Feb 20, 2017

I would prefer to simply forbid modifying entity type field for any existing attribute type. This could be checked in Controller::Admin::Attributes.

On a side note, there are many other ways for admins to create flawed attribute types:

  • change an entity type into another one different from the one of its parent/children
  • create a new attribute type with an entity type different from its parent’s one
  • change a parent id to an attribute type with a different entity type
  • loop with parent ids

Hopefully they can be fixed by the same admins using the same form and, more importantly, they don’t corrupt existing entities (or maybe they do but hopefully admins won't make that mistake).

@mwiencek
Copy link
Member

Agreed on preventing modifying the entity type altogether, since that is most likely to cause issues, and doesn't really have a good use case. Good point about the others. I think the parent/child issues mentioned are probably not worth validating, since they wouldn't cause anything terrible if they happened.

@yvanzo
Copy link
Contributor Author

yvanzo commented Feb 22, 2017

Done in d7a3993


if ($old_entity_type ne $new_entity_type) {
$form->field('entity_type')->add_error(
l('Entity type \'{entity_type}\' cannot be changed; please delete and readd attribute instead.',
Copy link
Member

Choose a reason for hiding this comment

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

I think the <select> should be grayed/disabled on the editing form, and we should simply filter out entity_type from $form->edit_fields before calling update below. We're not worried about admins abusing the form, so no need to give translators a new message nobody will ever see. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About this, messages from admin interface should probably not be localized. Right?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think it's probably right for them to be localized. Even though all the admins know English, they might have a different language selected in the UI and it would be weird to make an exception here. But I'd avoid adding strings to the admin UI where not necessary, or I'd make them simple if required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 73daae6.
On a side note: I disabled the <select> element using JS because TT seems to ignore disabled attribute.

@@ -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 );
Copy link
Member

@mwiencek mwiencek Feb 28, 2017

Choose a reason for hiding this comment

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

There's a small problem: disabled fields aren't submitted by the browser, so if an error occurs in another field (try entering non-numeric characters in child order), the page will reload and the <select> will have no selection. To fix that, I think this should go above $form->process (edit: or maybe not).

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 removed it in cde0df9 (where field entity_type input is enabled just before form submission) since it is unnecessary anyway, unless we want proper validation which should then take place in a separate package for attributes with entity_type field.

Copy link
Member

Choose a reason for hiding this comment

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

I think it was fine to keep it, but that's good enough for me. :)

@@ -34,6 +34,17 @@
</p>

[% 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 ~%]
Copy link
Member

Choose a reason for hiding this comment

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

Also related to errors happening in other fields: this will disable the field even if you're on the "create" form. But that's a minor issue we can probably ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for having spotted this issue.
I replaced the faulty condition by a cleaner one on c.action.name in cde0df9.

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
until finer-grained fields validation is implemented, in particular
checking over related entities and parent/children attributes.
@yvanzo
Copy link
Contributor Author

yvanzo commented Mar 1, 2017

Failed tests are unrelated to this change.

@mwiencek mwiencek merged commit ca8720d into metabrainz:master Mar 1, 2017
@yvanzo yvanzo deleted the mbs-9215-fix-admin-attr branch April 2, 2017 21:58
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