| 1 | package App::SD::Model::Attachment; | ||
| 2 | use Any::Moose; | ||
| 3 | extends 'App::SD::Record'; | ||
| 4 | use Params::Validate qw/validate/; | ||
| 5 | |||
| 6 | use constant collection_class => 'App::SD::Collection::Attachment'; | ||
| 7 | has '+type' => ( default => 'attachment'); | ||
| 8 | |||
| 9 | |||
| 10 | sub _default_summary_format { '%s,$luid | %s,name | %s,content_type'} | ||
| 11 | |||
| 12 | __PACKAGE__->register_reference( ticket => 'App::SD::Model::Ticket'); | ||
| 13 | |||
| 14 | sub create { | ||
| 15 | my $self = shift; | ||
| 16 | my %args = validate( @_, {props => 1}); | ||
| 17 | |||
| 18 | |||
| 19 | return (0,"You can't create an attachment without specifying a 'ticket' uuid") unless ($args{'props'}->{'ticket'}); | ||
| 20 | |||
| 21 | $args{'props'}->{'content_type'} ||= 'text/plain'; # XXX TODO use real mime typing; | ||
| 22 | |||
| 23 | |||
| 24 | $self->SUPER::create(%args); | ||
| 25 | } | ||
| 26 | |||
| 27 | __PACKAGE__->meta->make_immutable; | ||
| 28 | no Any::Moose; | ||
| 29 | |||
| 30 | 1; |