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
Conversation
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'); |
There was a problem hiding this comment.
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).
Ideally, it would validate that the parent attribute has the same entity type, but hopefully admins won't make that mistake. |
There was a problem hiding this 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).
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:
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). |
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. |
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.', |
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d7a3993
to
73daae6
Compare
@@ -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 ); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
root/admin/attributes/form.tt
Outdated
@@ -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 ~%] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
73daae6
to
cde0df9
Compare
Failed tests are unrelated to this change. |
Collection and series types admin editing form missed entity type.
This adds support for entering entity type without specific check.