aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm108
-rw-r--r--t/app/controller/report_display.t73
-rw-r--r--t/app/model/problem.t96
-rw-r--r--templates/web/default/report/display.html2
6 files changed, 211 insertions, 72 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 2f1d88d08..88b53494b 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -56,7 +56,7 @@ sub update_problem : Private {
my $problem = $c->stash->{problem} || $update->problem;
if ( $update->mark_fixed ) {
- $problem->state('fixed');
+ $problem->state('fixed - user');
if ( $update->user->id == $problem->user->id ) {
$problem->send_questionnaire(0);
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 47bee1e0a..c23d5d1fc 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -835,7 +835,7 @@ sub generate_problem_banner {
$banner->{id} = 'unknown';
$banner->{text} = _('This problem is old and of unknown status.');
}
- if ($problem->state eq 'fixed') {
+ if ($problem->is_fixed) {
$banner->{id} = 'fixed';
$banner->{text} = _('This problem has been fixed') . '.';
}
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 47dac1e8e..2d3a8bccb 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -119,6 +119,74 @@ use Utils;
with 'FixMyStreet::Roles::Abuser';
+=head2
+
+ @states = FixMyStreet::DB::Problem::open_states();
+
+Get a list or states that are regarded as open. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
+
+=cut
+
+sub open_states {
+ my $states = {
+ 'unconfirmed' => 1,
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'planned' => 1,
+ 'in progress' => 1,
+ };
+
+ return wantarray ? keys %{$states} : $states;
+}
+
+=head2
+
+ @states = FixMyStreet::DB::Problem::fixed_states();
+
+Get a list or states that should be regarded as fixed. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
+
+=cut
+
+sub fixed_states {
+ my $states = {
+ 'fixed' => 1,
+ 'fixed - user' => 1,
+ 'fixed - council' => 1,
+ };
+
+ return wantarray ? keys %{ $states } : $states;
+}
+
+=head2
+
+ @states = FixMyStreet::DB::Problem::visible_states();
+
+Get a list or states that should be visible on the site. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
+
+=cut
+
+sub visible_states {
+ my $states = {
+ 'confirmed' => 1,
+ 'planned' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'fixed' => 1,
+ 'fixed - council' => 1,
+ 'fixed - user' => 1,
+ 'will not fix' => 1,
+ };
+
+ return wantarray ? keys %{$states} : $states;
+}
+
+
my $tz = DateTime::TimeZone->new( name => "local" );
sub confirmed_local {
@@ -286,39 +354,39 @@ sub get_photo_params {
=head2 is_open
-Returns 1 if the problem is in a open state otherwise 0;
+Returns 1 if the problem is in a open state otherwise 0.
=cut
sub is_open {
my $self = shift;
- my %open_states = (
- unconfirmed => 1,
- partial => 1,
- confirmed => 1,
- 'planned' => 1,
- 'investigating' => 1,
- 'in progress' => 1,
- );
-
- return exists $open_states{ $self->state } ? 1 : 0;
+ return exists $self->open_states->{ $self->state } ? 1 : 0;
}
-=head2
- @states = FixMyStreet::DB::Problem::visible_states();
+=head2 is_fixed
-Returns a list of states that should be displayed on the site.
+Returns 1 if the problem is in a fixed state otherwise 0.
=cut
-sub visible_states {
- return (
- 'confirmed', 'planned', 'investigating',
- 'in progress', 'fixed', 'fixed - council',
- 'fixed - user', 'will not fix',
- );
+sub is_fixed {
+ my $self = shift;
+
+ return exists $self->fixed_states->{ $self->state } ? 1 : 0;
+}
+
+=head2 is_visible
+
+Returns 1 if the problem should be displayed on the site otherwise 0.
+
+=cut
+
+sub is_visible {
+ my $self = shift;
+
+ return exists $self->visible_states->{ $self->state } ? 1 : 0;
}
=head2 meta_line
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 746f68cf6..d20774560 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -119,55 +119,6 @@ subtest "test a good report" => sub {
is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields;
};
-for my $test (
- {
- state => 'confirmed',
- display => 1,
- },
- {
- state => 'investigating',
- display => 1,
- },
- {
- state => 'planned',
- display => 1,
- },
- {
- state => 'in progress',
- display => 1,
- },
- {
- state => 'fixed',
- display => 0,
- },
- {
- state => 'fixed - council',
- display => 0,
- },
- {
- state => 'fixed - user',
- display => 0,
- },
- {
- state => 'will not fix',
- display => 0,
- },
-) {
- subtest "check fixed checkbox display for state $test->{state}" => sub {
- $report->state( $test->{state} );
- $report->update;
- $mech->get_ok("/report/$report_id");
-
- my $update_form = $mech->form_name('updateForm');
-
- if ( $test->{display} ) {
- ok defined $update_form->find_input('#form_fixed', 'checkbox'), "fixed checkbox display";
- } else {
- is $update_form->find_input('#form_fixed', 'checkbox'), undef, "fixed checkbox display";
- }
- };
-}
-
foreach my $meta (
{
anonymous => 'f',
@@ -284,6 +235,30 @@ for my $test (
banner_text => 'This problem has been fixed.',
fixed => 1
},
+ {
+ description => 'user fixed report',
+ date => DateTime->now,
+ state => 'fixed - user',
+ banner_id => 'fixed',
+ banner_text => 'This problem has been fixed.',
+ fixed => 1
+ },
+ {
+ description => 'council fixed report',
+ date => DateTime->now,
+ state => 'fixed - council',
+ banner_id => 'fixed',
+ banner_text => 'This problem has been fixed.',
+ fixed => 1
+ },
+ {
+ description => 'closed report',
+ date => DateTime->now,
+ state => 'will not fix',
+ banner_id => '',
+ banner_text => '',
+ fixed => 0
+ },
) {
subtest "banner for $test->{description}" => sub {
$report->confirmed( $test->{date}->ymd . ' ' . $test->{date}->hms );
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 5a5eb2520..38ddc1857 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -196,4 +196,100 @@ for my $test (
};
}
+for my $test (
+ {
+ state => 'unconfirmed',
+ is_fixed => 0,
+ },
+ {
+ state => 'confirmed',
+ is_fixed => 0,
+ },
+ {
+ state => 'investigating',
+ is_fixed => 0,
+ },
+ {
+ state => 'planned',
+ is_fixed => 0,
+ },
+ {
+ state => 'in progress',
+ is_fixed => 0,
+ },
+ {
+ state => 'fixed',
+ is_fixed => 1,
+ },
+ {
+ state => 'fixed - council',
+ is_fixed => 1,
+ },
+ {
+ state => 'fixed - user',
+ is_fixed => 1,
+ },
+ {
+ state => 'will not fix',
+ is_fixed => 0,
+ },
+) {
+ subtest $test->{state} . ' is fixed/open' => sub {
+ $problem->state( $test->{state} );
+ is $problem->is_fixed, $test->{is_fixed}, 'is_fixed';
+ };
+}
+
+for my $test (
+ {
+ state => 'partial',
+ is_visible => 0,
+ },
+ {
+ state => 'hidden',
+ is_visible => 0,
+ },
+ {
+ state => 'unconfirmed',
+ is_visible => 0,
+ },
+ {
+ state => 'confirmed',
+ is_visible => 1,
+ },
+ {
+ state => 'investigating',
+ is_visible => 1,
+ },
+ {
+ state => 'planned',
+ is_visible => 1,
+ },
+ {
+ state => 'in progress',
+ is_visible => 1,
+ },
+ {
+ state => 'fixed',
+ is_visible => 1,
+ },
+ {
+ state => 'fixed - council',
+ is_visible => 1,
+ },
+ {
+ state => 'fixed - user',
+ is_visible => 1,
+ },
+ {
+ state => 'will not fix',
+ is_visible => 1,
+ },
+) {
+ subtest $test->{state} . ' is fixed/open' => sub {
+ $problem->state( $test->{state} );
+ is $problem->is_visible, $test->{is_visible}, 'is_visible';
+ };
+}
+
done_testing();
diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html
index 89e2b6df2..afeddf2c5 100644
--- a/templates/web/default/report/display.html
+++ b/templates/web/default/report/display.html
@@ -105,7 +105,7 @@
</div>
- [% IF problem.is_open %]
+ [% IF !problem.is_fixed %]
<div class="checkbox">
<input type="checkbox" name="fixed" id="form_fixed" value="1"[% fixed %]>
<label for="form_fixed">[% loc('This problem has been fixed') %]</label>