aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-11-18 14:05:56 +0000
committerMatthew Somerville <matthew@mysociety.org>2019-11-18 14:35:21 +0000
commit5b3731b263864722f26c4ab9ce28209b089a6942 (patch)
treea3c8066d786f19b684677af5685fd587bf193ab7
parent7b3c6513022a76409ae175187ecfb8064cff6e0d (diff)
Remove cached photos before updating db field.
If the photo field is updated first, then the cache removal doesn't think there are any photos to remove.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm2
-rw-r--r--t/app/controller/moderate.t47
4 files changed, 37 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d36a92d59..2b0492085 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -47,6 +47,7 @@
- Allow contact send method to be unset always.
- Fix z-index stacking bug that was causing unclickable RSS icons on /alert page. #2624
- Fix issue with inspector duplication workflow.
+ - Fix removal of cached photos on moderation. #2696
- Development improvements:
- Upgrade the underlying framework and a number of other packages. #2473
- Add feature cobrand helper function.
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 975fed02f..64cc9eaaf 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -472,8 +472,8 @@ sub _get_remove_photo_param : Private {
sub remove_photo : Private {
my ($self, $c, $object, $keys) = @_;
if ($keys eq 'ALL') {
- $object->photo(undef);
$object->get_photoset->delete_cached;
+ $object->photo(undef);
} else {
my $fileids = $object->get_photoset->remove_images($keys);
$object->photo($fileids);
diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index 8a9f3b5a2..f4143f0b4 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -263,8 +263,8 @@ sub moderate_boolean : Private {
if ($new != $old) {
if ($thing eq 'photo') {
- $object->$thing($new ? $original : undef);
$object->get_photoset->delete_cached;
+ $object->$thing($new ? $original : undef);
} else {
$object->$thing($new);
}
diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t
index fdbd0abb6..8e84bd392 100644
--- a/t/app/controller/moderate.t
+++ b/t/app/controller/moderate.t
@@ -12,6 +12,8 @@ sub moderate_permission_title { 0 }
package main;
+use Path::Tiny;
+use File::Temp 'tempdir';
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -172,23 +174,42 @@ subtest 'Problem moderation' => sub {
};
subtest 'Hide photo' => sub {
- $mech->content_contains('Photo of this report');
+ my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
- $mech->submit_form_ok({ with_fields => {
- %problem_prepopulated,
- problem_photo => 0,
- }});
- $mech->base_like( qr{\Q$REPORT_URL\E} );
+ FixMyStreet::override_config {
+ PHOTO_STORAGE_BACKEND => 'FileSystem',
+ PHOTO_STORAGE_OPTIONS => {
+ UPLOAD_DIR => $UPLOAD_DIR,
+ },
+ }, sub {
+ my $image_path = path('t/app/controller/sample.jpg');
+ $image_path->copy( path($UPLOAD_DIR, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg') );
- $mech->content_lacks('Photo of this report');
+ $mech->get_ok('/photo/' . $report->id . '.0.jpeg');
- $mech->submit_form_ok({ with_fields => {
- %problem_prepopulated,
- problem_photo => 1,
- }});
- $mech->base_like( qr{\Q$REPORT_URL\E} );
+ $mech->get_ok($REPORT_URL);
+ $mech->content_contains('Photo of this report');
- $mech->content_contains('Photo of this report');
+ $mech->submit_form_ok({ with_fields => {
+ %problem_prepopulated,
+ problem_photo => 0,
+ }});
+ $mech->base_like( qr{\Q$REPORT_URL\E} );
+
+ my $res = $mech->get('/photo/' . $report->id . '.0.jpeg');
+ is $res->code, 404, 'got 404';
+
+ $mech->get_ok($REPORT_URL);
+ $mech->content_lacks('Photo of this report');
+
+ $mech->submit_form_ok({ with_fields => {
+ %problem_prepopulated,
+ problem_photo => 1,
+ }});
+ $mech->base_like( qr{\Q$REPORT_URL\E} );
+
+ $mech->content_contains('Photo of this report');
+ };
};
subtest 'Hide report' => sub {