1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
package FixMyStreet::App::Controller::Admin::Triage;
use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
=head1 NAME
FixMyStreet::App::Controller::Admin::Triage - Catalyst Controller
=head1 DESCRIPTION
Admin pages for triaging reports.
This allows reports to be triaged before being sent to the council. It works
by having a set of categories with a send_method of Triage which sets the report
state to 'for_triage'. Any reports with the state are then show on '/admin/triage'
which is available to users with the 'triage' permission.
Clicking on reports on this list will then allow a user to change the category of
the report to one that has an alternative send method, which will trigger the report
to be resent.
In order for this to work additional work needs to be done to the cobrand to only
display triageable categories to the user.
=head1 METHODS
=cut
sub auto : Private {
my ( $self, $c ) = @_;
unless ( $c->user->has_body_permission_to('triage') ) {
$c->detach('/page_error_403_access_denied', []);
}
}
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
# default sort to oldest
unless ( $c->get_param('sort') ) {
$c->set_param('sort', 'created-asc');
}
$c->stash->{body} = $c->forward('/reports/body_find', [ $c->cobrand->council_area ]);
$c->forward( 'stash_report_filter_status' );
$c->forward('/reports/stash_report_sort', [ $c->cobrand->reports_ordering ]);
$c->forward( '/reports/load_and_group_problems' );
$c->stash->{page} = 'reports'; # So the map knows to make clickable pins
if ($c->get_param('ajax')) {
my $ajax_template = $c->stash->{ajax_template} || 'reports/_problem-list.html';
$c->detach('/reports/ajax', [ $ajax_template ]);
}
my @categories = $c->stash->{body}->contacts->not_deleted->search( undef, {
columns => [ 'id', 'category', 'extra' ],
distinct => 1,
} )->all_sorted;
$c->stash->{filter_categories} = \@categories;
$c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) };
my $pins = $c->stash->{pins} || [];
my %map_params = (
latitude => @$pins ? $pins->[0]{latitude} : 0,
longitude => @$pins ? $pins->[0]{longitude} : 0,
area => [ $c->stash->{wards} ? map { $_->{id} } @{$c->stash->{wards}} : keys %{$c->stash->{body}->areas} ],
any_zoom => 1,
);
FixMyStreet::Map::display_map(
$c, %map_params, pins => $pins,
);
}
sub stash_report_filter_status : Private {
my ( $self, $c ) = @_;
$c->stash->{filter_problem_states} = { 'for triage' => 1 };
return 1;
}
sub setup_categories : Private {
my ( $self, $c ) = @_;
if ( $c->stash->{problem}->state eq 'for triage' ) {
$c->stash->{holding_options} = [ grep { $_->send_method && $_->send_method eq 'Triage' } @{$c->stash->{category_options}} ];
$c->stash->{holding_categories} = { map { $_->category => 1 } @{$c->stash->{holding_options}} };
$c->stash->{end_options} = [ grep { !$_->send_method || $_->send_method ne 'Triage' } @{$c->stash->{category_options}} ];
$c->stash->{end_categories} = { map { $_->category => 1 } @{$c->stash->{end_options}} };
delete $c->stash->{categories_hash};
my %category_groups = ();
for my $category (@{$c->stash->{end_options}}) {
my $groups = $category->groups;
push( @{$category_groups{$_}}, $category ) for @$groups;
}
my @category_groups = ();
for my $group ( grep { $_ ne _('Other') } sort keys %category_groups ) {
push @category_groups, { name => $group, categories => $category_groups{$group} };
}
$c->stash->{end_groups} = \@category_groups;
}
return 1;
}
sub update : Private {
my ($self, $c) = @_;
my $problem = $c->stash->{problem};
my $current_category = $problem->category;
my $new_category = $c->get_param('category');
my $changed = $c->forward('/admin/reports/edit_category', [ $problem, 1 ] );
if ( $changed ) {
$c->stash->{problem}->update( { state => 'confirmed' } );
$c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'triage' ] );
my $extra;
$extra->{triage_report} = 1;
$extra->{holding_category} = $current_category;
$extra->{new_category} = $new_category;
my $comment = $problem->add_to_comments( {
text => "Report triaged from $current_category to $new_category",
user => $c->user->obj,
problem_state => $problem->state,
extra => $extra,
whensent => \'current_timestamp',
} );
my @alerts = FixMyStreet::DB->resultset('Alert')->search( {
alert_type => 'new_updates',
parameter => $problem->id,
confirmed => 1,
} );
for my $alert (@alerts) {
my $alerts_sent = FixMyStreet::DB->resultset('AlertSent')->find_or_create( {
alert_id => $alert->id,
parameter => $comment->id,
} );
}
}
}
1;
|