diff options
author | Dave Arter <davea@mysociety.org> | 2015-02-05 15:09:49 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-10-06 09:09:22 +0100 |
commit | e9961ee495ab87cbe67cf37e53edbae0794541d2 (patch) | |
tree | 79596f3b3cad4325351fb2a92e617c401471d61e /perllib/FixMyStreet/App/Controller/Photo.pm | |
parent | a78bb3fc98dd1851e371c78d9743125d02baf04e (diff) |
[Zurich] 'photo required' functionality
- Save 'photo_required' value in Contact->extra from admin edit form
- Enforce per-category photo requirement on new reports
A new step has been added to the photo upload process that
ensures a photo is present if any of the categories chosen for
the report require it.
If the photo is missing an error is displayed to the user in the
same manner as if the photo upload was invalid.
- Add test of mandatory photo categories
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Photo.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 7cf78cb2f..57a65e8eb 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -143,6 +143,7 @@ sub process_photo : Private { return $c->forward('process_photo_upload_or_cache') + || $c->forward('process_photo_required') || 1; # always return true } @@ -167,6 +168,44 @@ sub process_photo_upload_or_cache : Private { return 1; } +=head2 process_photo_required + +Checks that a report has a photo attached if any of its Contacts +require it (by setting extra->photo_required == 1). Puts an error in +photo_error on the stash if it's required and missing, otherwise returns +true. + +(Note that as we have reached this action, we *know* that the photo +is missing, otherwise it would have already been handled.) + +=cut + +sub process_photo_required : Private { + my ( $self, $c ) = @_; + + # load the report + my $report = $c->stash->{report} or return 1; # don't check photo for updates + my $bodies = $c->stash->{bodies}; + + my @contacts = $c-> # + model('DB::Contact') # + ->not_deleted # + ->search( + { + body_id => [ keys %$bodies ], + category => $report->category + } + )->all; + foreach my $contact ( @contacts ) { + if ( $contact->get_extra_metadata('photo_required') ) { + $c->stash->{photo_error} = _("Photo is required."); + return; + } + } + + return 1; +} + =head1 AUTHOR |