aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm87
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/JSON.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311.pm17
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm2
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm27
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm34
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm10
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm16
-rw-r--r--perllib/FixMyStreet/Cobrand/EmptyHomes.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm22
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm135
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm42
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm15
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm17
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm2
-rw-r--r--perllib/FixMyStreet/Map/OSM.pm2
20 files changed, 391 insertions, 60 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 405ee37ec..e5c0133cf 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -56,10 +56,12 @@ sub index : Path : Args(0) {
%prob_counts =
map { $_ => $prob_counts{$_} || 0 }
- qw(confirmed fixed unconfirmed hidden partial);
+ ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council',
+ 'fixed - user', 'fixed', 'unconfirmed', 'hidden',
+ 'partial', 'planned');
$c->stash->{problems} = \%prob_counts;
- $c->stash->{total_problems_live} =
- $prob_counts{confirmed} + $prob_counts{fixed};
+ $c->stash->{total_problems_live} += $prob_counts{$_}
+ for ( FixMyStreet::DB::Result::Problem->visible_states() );
$c->stash->{total_problems_users} = $c->cobrand->problems->unique_users;
my $comments = $c->model('DB::Comment')->summary_count( $site_restriction );
@@ -614,6 +616,36 @@ sub report_edit : Path('report_edit') : Args(1) {
return 1;
}
+sub search_users: Path('search_users') : Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->forward('check_page_allowed');
+
+ if (my $search = $c->req->param('search')) {
+ $c->stash->{searched} = 1;
+
+ my $search = $c->req->param('search');
+ my $isearch = '%' . $search . '%';
+
+ my $search_n = 0;
+ $search_n = int($search) if $search =~ /^\d+$/;
+
+ my $users = $c->model('DB::User')->search(
+ {
+ -or => [
+ email => { ilike => $isearch },
+ name => { ilike => $isearch },
+ from_council => $search_n,
+ ]
+ }
+ );
+
+ $c->stash->{users} = [ $users->all ];
+ }
+
+ return 1;
+}
+
sub update_edit : Path('update_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
@@ -737,6 +769,51 @@ sub search_abuse : Path('search_abuse') : Args(0) {
return 1;
}
+sub user_edit : Path('user_edit') : Args(1) {
+ my ( $self, $c, $id ) = @_;
+
+ $c->forward('check_page_allowed');
+ $c->forward('get_token');
+
+ my $user = $c->model('DB::User')->find( { id => $id } );
+ $c->stash->{user} = $user;
+
+ my @area_types = $c->cobrand->area_types;
+ my $areas = mySociety::MaPit::call('areas', \@area_types);
+
+ my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas;
+ @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids );
+
+ $c->stash->{council_ids} = \@councils_ids;
+ $c->stash->{council_details} = $areas;
+
+ if ( $c->req->param('submit') ) {
+ $c->forward('check_token');
+
+ my $edited = 0;
+
+ if ( $user->email ne $c->req->param('email') ||
+ $user->name ne $c->req->param('name' ) ||
+ $user->from_council != $c->req->param('council') ) {
+ $edited = 1;
+ }
+
+ $user->name( $c->req->param('name') );
+ $user->email( $c->req->param('email') );
+ $user->from_council( $c->req->param('council') || undef );
+ $user->update;
+
+ if ($edited) {
+ $c->forward( 'log_edit', [ $id, 'user', 'edit' ] );
+ }
+
+ $c->stash->{status_message} =
+ '<p><em>' . _('Updated!') . '</em></p>';
+ }
+
+ return 1;
+}
+
sub list_flagged : Path('list_flagged') : Args(0) {
my ( $self, $c ) = @_;
@@ -840,9 +917,11 @@ sub set_allowed_pages : Private {
'search_reports' => [_('Search Reports'), 2],
'timeline' => [_('Timeline'), 3],
'questionnaire' => [_('Survey Results'), 4],
+ 'search_users' => [_('Search Users'), 5],
'search_abuse' => [_('Search Abuse'), 5],
'list_flagged' => [_('List Flagged'), 6],
'stats' => [_('Stats'), 6],
+ 'user_edit' => [undef, undef],
'council_contacts' => [undef, undef],
'council_edit' => [undef, undef],
'report_edit' => [undef, undef],
@@ -890,7 +969,7 @@ not then display 404 page
sub check_token : Private {
my ( $self, $c ) = @_;
- if ( $c->req->param('token' ) ne $c->stash->{token} ) {
+ if ( !$c->req->param('token') || $c->req->param('token' ) ne $c->stash->{token} ) {
$c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] );
}
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 0f871508e..d3a4500c6 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -189,7 +189,7 @@ sub display_location : Private {
{
latitude => $p->latitude,
longitude => $p->longitude,
- colour => $p->state eq 'fixed' ? 'green' : 'red',
+ colour => $p->is_fixed ? 'green' : 'red',
id => $p->id,
title => $p->title,
}
diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm
index a89fb3e6c..f3607341a 100644
--- a/perllib/FixMyStreet/App/Controller/JSON.pm
+++ b/perllib/FixMyStreet/App/Controller/JSON.pm
@@ -71,12 +71,12 @@ sub problems : Local {
}
# query the database
- my ( $state, $date_col );
+ my ( @state, $date_col );
if ( $type eq 'new_problems' ) {
- $state = 'confirmed';
+ @state = FixMyStreet::DB::Result::Problem->open_states();
$date_col = 'confirmed';
} elsif ( $type eq 'fixed_problems' ) {
- $state = 'fixed';
+ @state = FixMyStreet::DB::Result::Problem->fixed_states();
$date_col = 'lastupdate';
}
@@ -86,7 +86,7 @@ sub problems : Local {
'>=' => $start_dt,
'<=' => $end_dt + $one_day,
},
- state => $state,
+ state => [ @state ],
};
$query->{category} = $category if $category;
my @problems = $c->cobrand->problems->search( $query, {
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 1021f7056..60e9dd09f 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -31,7 +31,7 @@ sub my : Path : Args(0) {
my $pins = [];
my $problems = {};
my $rs = $c->user->problems->search( {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
}, {
order_by => { -desc => 'confirmed' },
rows => 50
@@ -41,11 +41,12 @@ sub my : Path : Args(0) {
push @$pins, {
latitude => $problem->latitude,
longitude => $problem->longitude,
- colour => $problem->state eq 'fixed' ? 'green' : 'red',
+ colour => $problem->is_fixed ? 'green' : 'red',
id => $problem->id,
title => $problem->title,
};
- push @{ $problems->{$problem->state} }, $problem;
+ my $state = $problem->is_fixed ? 'fixed' : $problem->is_closed ? 'closed' : 'confirmed';
+ push @{ $problems->{$state} }, $problem;
}
$c->stash->{problems_pager} = $rs->pager;
$c->stash->{problems} = $problems;
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm
index 459ce12c9..46d7801f6 100644
--- a/perllib/FixMyStreet/App/Controller/Open311.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311.pm
@@ -216,8 +216,11 @@ sub output_requests : Private {
# Look up categories for this council or councils
my $problems = $c->cobrand->problems->search( $criteria, $attr );
- my %statusmap = ( 'fixed' => 'closed',
- 'confirmed' => 'open');
+ my %statusmap = (
+ map( { $_ => 'open' } FixMyStreet::DB::Result::Problem->open_states() ),
+ map( { $_ => 'closed' } FixMyStreet::DB::Result::Problem->fixed_states() ),
+ 'closed' => 'closed'
+ );
my @problemlist;
my @councils;
@@ -309,13 +312,13 @@ sub get_requests : Private {
# Only provide access to the published reports
my $criteria = {
- state => [ 'fixed', 'confirmed' ]
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
};
my %rules = (
service_request_id => [ '=', 'id' ],
service_code => [ '=', 'category' ],
- status => [ '=', 'state' ],
+ status => [ 'IN', 'state' ],
start_date => [ '>=', 'confirmed' ],
end_date => [ '<', 'confirmed' ],
agency_responsible => [ '~', 'council' ],
@@ -329,8 +332,8 @@ sub get_requests : Private {
my $key = $rules{$param}[1];
if ( 'status' eq $param ) {
$value = {
- 'open' => 'confirmed',
- 'closed' => 'fixed'
+ 'open' => [ FixMyStreet::DB::Result::Problem->open_states() ],
+ 'closed' => [ FixMyStreet::DB::Result::Problem->fixed_states(), 'closed' ],
}->{$value};
} elsif ( 'agency_responsible' eq $param ) {
my @valuelist;
@@ -403,7 +406,7 @@ sub get_request : Private {
}
my $criteria = {
- state => [ 'fixed', 'confirmed' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
id => $id,
};
$c->forward( 'output_requests', [ $criteria ] );
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index 17862aa0a..b4fa3a457 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -48,7 +48,7 @@ sub index :Path :Args(0) {
$c->detach( 'no_photo' ) if $id =~ /\D/;
@photo = $c->cobrand->problems->search( {
id => $id,
- state => [ 'confirmed', 'fixed', 'partial' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states(), 'partial' ],
photo => { '!=', undef },
} );
}
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index a87aff330..f0cb02115 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -41,7 +41,7 @@ sub check_questionnaire : Private {
$c->detach;
}
- unless ( $questionnaire->problem->state eq 'confirmed' || $questionnaire->problem->state eq 'fixed' ) {
+ unless ( $questionnaire->problem->is_visible ) {
$c->detach('missing_problem');
}
@@ -121,13 +121,19 @@ sub submit_creator_fixed : Private {
my $questionnaire = $c->model( 'DB::Questionnaire' )->find_or_new(
{
problem_id => $c->stash->{problem},
- old_state => 'confirmed',
- new_state => 'fixed',
+ # we want to look for any previous questionnaire here rather than one for
+ # this specific open state -> fixed transistion
+ old_state => [ FixMyStreet::DB::Result::Problem->open_states() ],
+ new_state => 'fixed - user',
}
);
unless ( $questionnaire->in_storage ) {
+ my $old_state = $c->flash->{old_state};
+ $old_state = 'confirmed' unless FixMyStreet::DB::Result::Problem->open_states->{$old_state};
+
$questionnaire->ever_reported( $c->stash->{reported} eq 'Yes' ? 1 : 0 );
+ $questionnaire->old_state( $old_state );
$questionnaire->whensent( \'ms_current_timestamp()' );
$questionnaire->whenanswered( \'ms_current_timestamp()' );
$questionnaire->insert;
@@ -149,8 +155,10 @@ sub submit_standard : Private {
my $problem = $c->stash->{problem};
my $old_state = $problem->state;
my $new_state = '';
- $new_state = 'fixed' if $c->stash->{been_fixed} eq 'Yes' && $old_state eq 'confirmed';
- $new_state = 'confirmed' if $c->stash->{been_fixed} eq 'No' && $old_state eq 'fixed';
+ $new_state = 'fixed - user' if $c->stash->{been_fixed} eq 'Yes' &&
+ FixMyStreet::DB::Result::Problem->open_states()->{$old_state};
+ $new_state = 'confirmed' if $c->stash->{been_fixed} eq 'No' &&
+ FixMyStreet::DB::Result::Problem->fixed_states()->{$old_state};
# Record state change, if there was one
if ( $new_state ) {
@@ -159,7 +167,8 @@ sub submit_standard : Private {
}
# If it's not fixed and they say it's still not been fixed, record time update
- if ( $c->stash->{been_fixed} eq 'No' && $old_state eq 'confirmed' ) {
+ if ( $c->stash->{been_fixed} eq 'No' &&
+ FixMyStreet::DB::Result::Problem->open_states->{$old_state} ) {
$problem->lastupdate( \'ms_current_timestamp()' );
}
@@ -186,7 +195,7 @@ sub submit_standard : Private {
user => $problem->user,
text => $update,
state => 'confirmed',
- mark_fixed => $new_state eq 'fixed' ? 1 : 0,
+ mark_fixed => $new_state eq 'fixed - user' ? 1 : 0,
mark_open => $new_state eq 'confirmed' ? 1 : 0,
lang => $c->stash->{lang_code},
cobrand => $c->cobrand->moniker,
@@ -236,7 +245,7 @@ sub process_questionnaire : Private {
if ($c->stash->{been_fixed} eq 'No' || $c->stash->{been_fixed} eq 'Unknown') && !$c->stash->{another};
push @errors, _('Please provide some explanation as to why you\'re reopening this report')
- if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->state eq 'fixed' && !$c->stash->{update};
+ if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->is_fixed() && !$c->stash->{update};
$c->forward('/report/new/process_photo');
push @errors, $c->stash->{photo_error}
@@ -288,7 +297,7 @@ sub display : Private {
pins => [ {
latitude => $problem->latitude,
longitude => $problem->longitude,
- colour => $problem->state eq 'fixed' ? 'green' : 'red',
+ colour => $problem->is_fixed() ? 'green' : 'red',
} ],
);
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 501dd2b41..add9d1371 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -51,8 +51,11 @@ sub update_problem : Private {
my $update = $c->stash->{update};
my $problem = $c->stash->{problem} || $update->problem;
+ # we may need this if we display the questionnaire
+ my $old_state = $problem->state;
+
if ( $update->mark_fixed ) {
- $problem->state('fixed');
+ $problem->state('fixed - user');
if ( $update->user->id == $problem->user->id ) {
$problem->send_questionnaire(0);
@@ -65,6 +68,10 @@ sub update_problem : Private {
}
}
+ if ( $update->problem_state ) {
+ $problem->state( $update->problem_state );
+ }
+
if ( $update->mark_open && $update->user->id == $problem->user->id ) {
$problem->state('confirmed');
}
@@ -75,6 +82,7 @@ sub update_problem : Private {
$c->stash->{problem_id} = $problem->id;
if ($display_questionnaire) {
+ $c->flash->{old_state} = $old_state;
$c->detach('/questionnaire/creator_fixed');
}
@@ -145,7 +153,7 @@ sub process_update : Private {
my ( $self, $c ) = @_;
my %params =
- map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'reopen' );
+ map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' );
$params{update} =
Utils::cleanup_text( $params{update}, { allow_multiline => 1 } );
@@ -170,6 +178,12 @@ sub process_update : Private {
}
);
+ if ( $params{state} ) {
+ $params{state} = 'fixed - council'
+ if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_council( $update->problem->council );
+ $update->problem_state( $params{state} );
+ }
+
$c->stash->{update} = $update;
$c->stash->{add_alert} = $c->req->param('add_alert');
@@ -187,6 +201,22 @@ return false.
sub check_for_errors : Private {
my ( $self, $c ) = @_;
+ # they have to be an authority user to update the state
+ if ( $c->req->param('state') ) {
+ my $error = 0;
+ $error = 1 unless $c->user && $c->user->belongs_to_council( $c->stash->{update}->problem->council );
+
+ my $state = $c->req->param('state');
+ $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) );
+
+ if ( $error ) {
+ $c->stash->{errors} ||= [];
+ push @{ $c->stash->{errors} }, _('There was a problem with your update. Please try again.');
+ return;
+ }
+
+ }
+
# let the model check for errors
$c->stash->{field_errors} ||= {};
my %field_errors = (
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index feafc4b77..f7fb5dec5 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -315,7 +315,7 @@ sub load_and_group_problems : Private {
my $page = $c->req->params->{p} || 1;
my $where = {
- state => [ 'confirmed', 'fixed' ]
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
};
if ($c->stash->{ward}) {
$where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' };
@@ -411,14 +411,16 @@ sub add_row {
? 'unknown'
: ($problem->{age} > $fourweeks ? 'older' : 'new');
# Fixed problems are either old or new
- push @{$fixed->{$council}{$duration_str}}, $problem if $problem->{state} eq 'fixed';
+ push @{$fixed->{$council}{$duration_str}}, $problem if
+ exists FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}};
# Open problems are either unknown, older, or new
- push @{$open->{$council}{$type}}, $problem if $problem->{state} eq 'confirmed';
+ push @{$open->{$council}{$type}}, $problem if
+ exists FixMyStreet::DB::Result::Problem->open_states->{$problem->{state}};
push @$pins, {
latitude => $problem->{latitude},
longitude => $problem->{longitude},
- colour => $problem->{state} eq 'fixed' ? 'green' : 'red',
+ colour => FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red',
id => $problem->{id},
title => $problem->{title},
};
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index 26a1a1459..10f994d9f 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -75,7 +75,7 @@ sub confirm_problem : Path('/P') {
$c->authenticate( { email => $problem->user->email }, 'no_password' );
$c->set_session_cookie_expire(0);
- if ( $old_state eq 'confirmed' || $old_state eq 'fixed' ) {
+ if ( FixMyStreet::DB::Result::Problem->visible_states()->{$old_state} ) {
my $report_uri = $c->uri_for( '/report', $problem->id );
$c->res->redirect($report_uri);
}
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 134111076..69718f613 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -894,14 +894,24 @@ sub generate_problem_banner {
my ( $self, $problem ) = @_;
my $banner = {};
- if ($problem->state eq 'confirmed' && time() - $problem->lastupdate_local->epoch > 8*7*24*60*60) {
- $banner->{id} = 'unknown';
+ if ( $problem->is_open && time() - $problem->lastupdate_local->epoch > 8 * 7 * 24 * 60 * 60 )
+ {
+ $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') . '.';
}
+ if ($problem->is_closed) {
+ $banner->{id} = 'closed';
+ $banner->{text} = _('This problem has been closed') . '.';
+ }
+
+ if ( grep { $problem->state eq $_ } ( 'investigating', 'in progress', 'planned' ) ) {
+ $banner->{id} = 'progress';
+ $banner->{text} = _('This problem is in progress') . '.';
+ }
return $banner;
}
diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
index eda0b2882..189daee0c 100644
--- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
+++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
@@ -112,7 +112,7 @@ sub generate_problem_banner {
my ( $self, $problem ) = @_;
my $banner = {};
- 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/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index ae152eb31..958194eb8 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -52,6 +52,8 @@ __PACKAGE__->add_columns(
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"anonymous",
{ data_type => "boolean", is_nullable => 0 },
+ "problem_state",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
@@ -68,8 +70,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TYFusbxkOkAewaiZYZVJUA
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:07:32
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ilLn3dlagg5COdpZDmzrVQ
use DateTime::TimeZone;
use Image::Size;
@@ -147,6 +149,22 @@ sub get_photo_params {
return $photo;
}
+=head2 meta_problem_state
+
+Returns a string suitable for display in the update meta section.
+Mostly removes the '- council/user' bit from fixed states
+
+=cut
+
+sub meta_problem_state {
+ my $self = shift;
+
+ my $state = $self->problem_state;
+ $state =~ s/ -.*$//;
+
+ return $state;
+}
+
# we need the inline_constructor bit as we don't inherit from Moose
__PACKAGE__->meta->make_immutable( inline_constructor => 0 );
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 6472b91db..987c92c64 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -121,6 +121,92 @@ 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 = {
+ '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::closed_states();
+
+Get a list or states that should be regarded as closed. If called in
+array context then returns an array of names, otherwise returns a
+HASHREF.
+
+=cut
+
+sub closed_states {
+ my $states = {
+ 'closed' => 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,
+ 'closed' => 1,
+ };
+
+ return wantarray ? keys %{$states} : $states;
+}
+
+
my $tz = DateTime::TimeZone->new( name => "local" );
sub confirmed_local {
@@ -286,6 +372,55 @@ sub get_photo_params {
return $photo;
}
+=head2 is_open
+
+Returns 1 if the problem is in a open state otherwise 0.
+
+=cut
+
+sub is_open {
+ my $self = shift;
+
+ return exists $self->open_states->{ $self->state } ? 1 : 0;
+}
+
+
+=head2 is_fixed
+
+Returns 1 if the problem is in a fixed state otherwise 0.
+
+=cut
+
+sub is_fixed {
+ my $self = shift;
+
+ return exists $self->fixed_states->{ $self->state } ? 1 : 0;
+}
+
+=head2 is_closed
+
+Returns 1 if the problem is in a closed state otherwise 0.
+
+=cut
+
+sub is_closed {
+ my $self = shift;
+
+ return exists $self->closed_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
Returns a string to be used on a problem report page, describing some of the
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index cf4fc56d5..56d726a8d 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -26,6 +26,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"password",
{ data_type => "text", default_value => "", is_nullable => 0 },
+ "from_council",
+ { data_type => "integer", is_nullable => 1 },
"flagged",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
);
@@ -51,8 +53,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:T2JK+KyfoE2hkCLgreq1XQ
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:25:21
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9IHuqRTcHZCqJeBAaiQxzw
__PACKAGE__->add_columns(
"password" => {
@@ -134,4 +136,40 @@ sub alert_for_problem {
} );
}
+sub council {
+ my $self = shift;
+
+ return '' unless $self->from_council;
+
+ my $key = 'council_name:' . $self->from_council;
+ my $result = Memcached::get($key);
+
+ unless ($result) {
+ my $area_info = mySociety::MaPit::call('area', $self->from_council);
+ $result = $area_info->{name};
+ Memcached::set($key, $result, 86400);
+ }
+
+ return $result;
+}
+
+=head2 belongs_to_council
+
+ $belongs_to_council = $user->belongs_to_council( $council_list );
+
+Returns true if the user belongs to the comma seperated list of council ids passed in
+
+=cut
+
+sub belongs_to_council {
+ my $self = shift;
+ my $council = shift;
+
+ my %councils = map { $_ => 1 } split ',', $council;
+
+ return 1 if $self->from_council && $councils{ $self->from_council };
+
+ return 0;
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index 46009cb85..bf085e32a 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -50,6 +50,7 @@ sub email_alerts ($) {
# XXX Ugh - needs work
$query =~ s/\?/alert.parameter/ if ($query =~ /\?/);
$query =~ s/\?/alert.parameter2/ if ($query =~ /\?/);
+
$query = dbh()->prepare($query);
$query->execute();
my $last_alert_id;
@@ -74,10 +75,13 @@ sub email_alerts ($) {
}
# create problem status message for the templates
- $data{state_message} =
- $row->{state} eq 'fixed'
- ? _("This report is currently marked as fixed.")
- : _("This report is currently marked as open.");
+ if ( FixMyStreet::DB::Result::Problem::fixed_states()->{$row->{state}} ) {
+ $data{state_message} = _("This report is currently marked as fixed.");
+ } elsif ( FixMyStreet::DB::Result::Problem::closed_states()->{$row->{state}} ) {
+ $data{state_message} = _("This report is currently marked as closed.")
+ } else {
+ $data{state_message} = _("This report is currently marked as open.");
+ }
my $url = $cobrand->base_url_for_emails( $row->{alert_cobrand_data} );
if ($row->{item_text}) {
@@ -130,11 +134,12 @@ sub email_alerts ($) {
$d = mySociety::Locale::in_gb_locale {
sprintf("%f", int($d*10+0.5)/10);
};
+ my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'";
my %data = ( template => $template, data => '', alert_id => $alert->id, alert_email => $alert->user->email, lang => $alert->lang, cobrand => $alert->cobrand, cobrand_data => $alert->cobrand_data );
my $q = "select problem.id, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users
where nearby.problem_id = problem.id
and problem.user_id = users.id
- and problem.state in ('confirmed', 'fixed')
+ and problem.state in ($states)
and problem.confirmed >= ? and problem.confirmed >= ms_current_timestamp() - '7 days'::interval
and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null
and users.email <> ?
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 3b3a3d90b..04089096e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -8,7 +8,7 @@ sub nearby {
my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval ) = @_;
my $params = {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem::visible_states() ],
};
$params->{'current_timestamp-lastupdate'} = { '<', \"'$interval'::interval" }
if $interval;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index ca329ab59..8c1f95bae 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -21,7 +21,7 @@ sub recent_fixed {
my $result = Memcached::get($key);
unless ($result) {
$result = $rs->search( {
- state => 'fixed',
+ state => [ FixMyStreet::DB::Result::Problem->fixed_states() ],
lastupdate => { '>', \"current_timestamp-'1 month'::interval" },
} )->count;
Memcached::set($key, $result, 3600);
@@ -50,7 +50,7 @@ sub recent_new {
my $result = Memcached::get($key);
unless ($result) {
$result = $rs->search( {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
confirmed => { '>', \"current_timestamp-'$interval'::interval" },
} )->count;
Memcached::set($key, $result, 3600);
@@ -66,7 +66,7 @@ sub recent {
my $result = Memcached::get($key);
unless ($result) {
$result = [ $rs->search( {
- state => [ 'confirmed', 'fixed' ]
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
}, {
columns => [ 'id', 'title' ],
order_by => { -desc => 'confirmed' },
@@ -81,7 +81,7 @@ sub recent_photos {
my ( $rs, $num, $lat, $lon, $dist ) = @_;
my $probs;
my $query = {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
photo => { '!=', undef },
};
my $attrs = {
@@ -125,7 +125,7 @@ sub around_map {
$attr->{rows} = $limit if $limit;
my $q = {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
latitude => { '>=', $min_lat, '<', $max_lat },
longitude => { '>=', $min_lon, '<', $max_lon },
};
@@ -177,7 +177,7 @@ sub unique_users {
my ( $rs ) = @_;
return $rs->search( {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
}, {
select => [ { count => { distinct => 'user_id' } } ],
as => [ 'count' ]
@@ -187,11 +187,12 @@ sub unique_users {
sub categories_summary {
my ( $rs ) = @_;
+ my $fixed_case = "case when state IN ( '" . join( "', '", FixMyStreet::DB::Result::Problem->fixed_states() ) . "' ) then 1 else null end";
my $categories = $rs->search( {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
whensent => { '<' => \"NOW() - INTERVAL '4 weeks'" },
}, {
- select => [ 'category', { count => 'id' }, { count => \"case when state='fixed' then 1 else null end" } ],
+ select => [ 'category', { count => 'id' }, { count => \$fixed_case } ],
as => [ 'category', 'c', 'fixed' ],
group_by => [ 'category' ],
result_class => 'DBIx::Class::ResultClass::HashRefInflator'
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index e490c77a6..665e0e3e0 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -19,7 +19,7 @@ sub send_questionnaires_period {
# Select all problems that need a questionnaire email sending
my $q_params = {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem::visible_states() ],
whensent => [
'-and',
{ '!=', undef },
diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm
index c848c9e5e..be185c35c 100644
--- a/perllib/FixMyStreet/Map/OSM.pm
+++ b/perllib/FixMyStreet/Map/OSM.pm
@@ -116,7 +116,7 @@ sub map_pins {
# id => $p->id,
# title => $p->title,
#}
- [ $p->latitude, $p->longitude, $p->state eq 'fixed' ? 'green' : 'red', $p->id, $p->title ]
+ [ $p->latitude, $p->longitude, $p->is_fixed ? 'green' : 'red', $p->id, $p->title ]
} @$around_map, @$nearby;
return (\@pins, $around_map_list, $nearby, $dist);