From bada68b27226eb2d0f119edf0fed866bd473b032 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 16 Jun 2017 16:16:49 +0100 Subject: Don't resend if category change subsets body. Instead of checking if the list of bodies has changed at all, mark the report for resending if there is a body in the new list not present in the old. --- perllib/FixMyStreet/App/Controller/Admin.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 1f3307710..d354e6929 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -8,7 +8,6 @@ use Path::Class; use POSIX qw(strftime strcoll); use Digest::SHA qw(sha1_hex); use mySociety::EmailUtil qw(is_valid_email is_valid_email_list); -use mySociety::ArrayUtils; use DateTime::Format::Strptime; use List::Util 'first'; @@ -844,8 +843,9 @@ sub report_edit_category : Private { $problem->category($category); my @contacts = grep { $_->category eq $problem->category } @{$c->stash->{contacts}}; my @new_body_ids = map { $_->body_id } @contacts; - # If the report has changed bodies we need to resend it - if (scalar @{mySociety::ArrayUtils::symmetric_diff($problem->bodies_str_ids, \@new_body_ids)}) { + # If the report has changed bodies (and not to a subset!) we need to resend it + my %old_map = map { $_ => 1 } @{$problem->bodies_str_ids}; + if (grep !$old_map{$_}, @new_body_ids) { $problem->whensent(undef); } $problem->bodies_str(join( ',', @new_body_ids )); -- cgit v1.2.3 From 466c5cac0f000bfa80ab49c88ec6e03c388ac328 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 8 Jul 2017 22:11:57 +0100 Subject: Add inactive state to categories. A new 'state' column replaces confirmed and deleted, allowing categories to be unconfirmed, confirmed, deleted or inactive. --- perllib/FixMyStreet/App/Controller/Admin.pm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d354e6929..fc21aeedb 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -96,11 +96,11 @@ sub index : Path : Args(0) { my $contacts = $c->model('DB::Contact')->summary_count(); my %contact_counts = - map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all; + map { $_->state => $_->get_column('state_count') } $contacts->all; - $contact_counts{0} ||= 0; - $contact_counts{1} ||= 0; - $contact_counts{total} = $contact_counts{0} + $contact_counts{1}; + $contact_counts{confirmed} ||= 0; + $contact_counts{unconfirmed} ||= 0; + $contact_counts{total} = $contact_counts{confirmed} + $contact_counts{unconfirmed}; $c->stash->{contacts} = \%contact_counts; @@ -264,8 +264,8 @@ sub bodies : Path('bodies') : Args(0) { my $contacts = $c->model('DB::Contact')->search( undef, { - select => [ 'body_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' }, - { count => \'case when confirmed then 1 else null end' } ], + select => [ 'body_id', { count => 'id' }, { count => \'case when state = \'deleted\' then 1 else null end' }, + { count => \'case when state = \'confirmed\' then 1 else null end' } ], as => [qw/body_id c deleted confirmed/], group_by => [ 'body_id' ], result_class => 'DBIx::Class::ResultClass::HashRefInflator' @@ -364,8 +364,7 @@ sub update_contacts : Private { } $contact->email( $email ); - $contact->confirmed( $c->get_param('confirmed') ? 1 : 0 ); - $contact->deleted( $c->get_param('deleted') ? 1 : 0 ); + $contact->state( $c->get_param('state') ); $contact->non_public( $c->get_param('non_public') ? 1 : 0 ); $contact->note( $c->get_param('note') ); $contact->whenedited( \'current_timestamp' ); @@ -420,7 +419,7 @@ sub update_contacts : Private { $contacts->update( { - confirmed => 1, + state => 'confirmed', whenedited => \'current_timestamp', note => 'Confirmed', editor => $editor, @@ -484,8 +483,8 @@ sub fetch_contacts : Private { my $contacts = $c->stash->{body}->contacts->search(undef, { order_by => [ 'category' ] } ); $c->stash->{contacts} = $contacts; - $c->stash->{live_contacts} = $contacts->search({ deleted => 0 }); - $c->stash->{any_not_confirmed} = $contacts->search({ confirmed => 0 })->count; + $c->stash->{live_contacts} = $contacts->search({ state => { '!=' => 'deleted' } }); + $c->stash->{any_not_confirmed} = $contacts->search({ state => 'unconfirmed' })->count; if ( $c->get_param('text') && $c->get_param('text') eq '1' ) { $c->stash->{template} = 'admin/council_contacts.txt'; -- cgit v1.2.3 From 4eda22305fec20749b540afa7f28174ffd46fad6 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Tue, 25 Jul 2017 16:50:03 +0100 Subject: Resend report if changing to category with different send_method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a report’s category is changed to one with a different send_method to the original category, the report needs to be resent. Fixes mysociety/fixmystreetforcouncils#209 --- perllib/FixMyStreet/App/Controller/Admin.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index fc21aeedb..d1ac5e76b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -10,6 +10,8 @@ use Digest::SHA qw(sha1_hex); use mySociety::EmailUtil qw(is_valid_email is_valid_email_list); use DateTime::Format::Strptime; use List::Util 'first'; +use List::MoreUtils 'uniq'; +use mySociety::ArrayUtils; use FixMyStreet::SendReport; @@ -847,6 +849,21 @@ sub report_edit_category : Private { if (grep !$old_map{$_}, @new_body_ids) { $problem->whensent(undef); } + # If the send methods of the old/new contacts differ we need to resend the report + my @old_contacts = grep { $_->category eq $category_old } @{$c->stash->{contacts}}; + my @new_send_methods = uniq map { + ( $_->body->can_be_devolved && $_->send_method ) ? + $_->send_method : $_->body->send_method; + } @contacts; + my @old_send_methods = map { + ( $_->body->can_be_devolved && $_->send_method ) ? + $_->send_method : $_->body->send_method; + } @old_contacts; + if ( scalar @{ mySociety::ArrayUtils::symmetric_diff(\@old_send_methods, \@new_send_methods) } ) { + $c->log->debug("Report changed, resending"); + $problem->whensent(undef); + } + $problem->bodies_str(join( ',', @new_body_ids )); $problem->add_to_comments({ text => '*' . sprintf(_('Category changed from ‘%s’ to ‘%s’'), $category_old, $category) . '*', -- cgit v1.2.3 From cc3e99fa9878bfb722e61d4a09d94839b152c5b7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sun, 16 Jul 2017 22:05:52 +0100 Subject: Set up translatable category columns. As category is used both for display and as a link between Problem and Contact tables, add `category_display` for use whenever a category is displayed. --- perllib/FixMyStreet/App/Controller/Admin.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d1ac5e76b..acbc62fb8 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -925,8 +925,8 @@ sub categories_for_point : Private { # Remove the "Pick a category" option shift @{$c->stash->{category_options}} if @{$c->stash->{category_options}}; - $c->stash->{categories} = $c->stash->{category_options}; - $c->stash->{categories_hash} = { map { $_ => 1 } @{$c->stash->{category_options}} }; + $c->stash->{category_options_copy} = $c->stash->{category_options}; + $c->stash->{categories_hash} = { map { $_->{name} => 1 } @{$c->stash->{category_options}} }; } sub templates : Path('templates') : Args(0) { -- cgit v1.2.3 From df1494f5a9de03c80764adf6108cbf699f547459 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 31 Jul 2017 15:15:02 +0100 Subject: Body/category translation admin interface. --- perllib/FixMyStreet/App/Controller/Admin.pm | 183 +++++++++++++++++++++++----- 1 file changed, 151 insertions(+), 32 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index acbc62fb8..0fa58eb9d 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -244,6 +244,9 @@ sub bodies : Path('bodies') : Args(0) { $c->stash->{edit_activity} = $edit_activity; + $c->forward( 'fetch_languages' ); + $c->forward( 'fetch_translations' ); + my $posted = $c->get_param('posted') || ''; if ( $posted eq 'body' ) { $c->forward('check_for_super_user'); @@ -257,6 +260,9 @@ sub bodies : Path('bodies') : Args(0) { $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); } + $c->stash->{object} = $body; + $c->stash->{translation_col} = 'name'; + $c->forward('update_translations'); $c->stash->{updated} = _('New body added'); } } @@ -300,30 +306,6 @@ sub body_form_dropdowns : Private { $c->stash->{send_methods} = \@methods; } -sub body : Path('body') : Args(1) { - my ( $self, $c, $body_id ) = @_; - - $c->stash->{body_id} = $body_id; - - unless ($c->user->has_permission_to('category_edit', $body_id)) { - $c->forward('check_for_super_user'); - } - - $c->forward( '/auth/get_csrf_token' ); - $c->forward( 'lookup_body' ); - $c->forward( 'fetch_all_bodies' ); - $c->forward( 'body_form_dropdowns' ); - - if ( $c->get_param('posted') ) { - $c->log->debug( 'posted' ); - $c->forward('update_contacts'); - } - - $c->forward('fetch_contacts'); - - return 1; -} - sub check_for_super_user : Private { my ( $self, $c ) = @_; @@ -407,6 +389,12 @@ sub update_contacts : Private { $contact->insert; } + unless ( %errors ) { + $c->stash->{translation_col} = 'category'; + $c->stash->{object} = $contact; + $c->forward('update_translations'); + } + } elsif ( $posted eq 'update' ) { $c->forward('/auth/check_csrf_token'); @@ -446,11 +434,45 @@ sub update_contacts : Private { # Remove any others $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete; + $c->stash->{translation_col} = 'name'; + $c->stash->{object} = $c->stash->{body}; + $c->forward('update_translations'); + $c->stash->{updated} = _('Values updated'); } } } +sub update_translations : Private { + my ( $self, $c ) = @_; + + foreach my $lang (keys(%{$c->stash->{languages}})) { + my $id = $c->get_param('translation_id_' . $lang); + my $text = $c->get_param('translation_' . $lang); + if ($id) { + my $translation = $c->model('DB::Translation')->find( + { + id => $id, + } + ); + + if ($text) { + $translation->msgstr($text); + $translation->update; + } else { + $translation->delete; + } + } elsif ($text) { + my $col = $c->stash->{translation_col}; + $c->stash->{object}->add_translation_for( + $col, $lang, $text + ); + } + } + + $c->stash->{updated} = _('Translations updated'); +} + sub body_params : Private { my ( $self, $c ) = @_; @@ -497,6 +519,44 @@ sub fetch_contacts : Private { return 1; } +sub fetch_languages : Private { + my ( $self, $c ) = @_; + + my $lang_map = {}; + foreach my $lang (sort @{$c->cobrand->languages}) { + my ($id, $name, $code) = split(',', $lang); + $lang_map->{$id} = { name => $name, code => $code }; + } + + $c->stash->{languages} = $lang_map; + + return 1; +} + +sub fetch_translations : Private { + my ( $self, $c ) = @_; + + my $translations = {}; + if ($c->get_param('posted')) { + foreach my $lang (keys %{$c->stash->{languages}}) { + if (my $msgstr = $c->get_param('translation_' . $lang)) { + $translations->{$lang} = { msgstr => $msgstr }; + } + if (my $id = $c->get_param('translation_id_' . $lang)) { + $translations->{$lang}->{id} = $id; + } + } + } elsif ($c->stash->{object}) { + my @translations = $c->stash->{object}->translation_for($c->stash->{translation_col})->all; + + foreach my $tx (@translations) { + $translations->{$tx->lang} = { id => $tx->id, msgstr => $tx->msgstr }; + } + } + + $c->stash->{translations} = $translations; +} + sub lookup_body : Private { my ( $self, $c ) = @_; @@ -516,35 +576,94 @@ sub lookup_body : Private { return 1; } +sub body_base : Chained('/') : PathPart('admin/body') : CaptureArgs(0) { } + # This is for if the category name contains a '/' -sub category_edit_all : Path('body') { +sub category_edit_all : Chained('body_base') : PathPart('') { my ( $self, $c, $body_id, @category ) = @_; my $category = join( '/', @category ); - $c->go( 'category_edit', [ $body_id, $category ] ); -} -sub category_edit : Path('body') : Args(2) { - my ( $self, $c, $body_id, $category ) = @_; + $c->stash->{body_id} = $body_id; + $c->forward( 'lookup_body' ); + my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first; + $c->stash->{contact} = $contact; + + $c->stash->{template} = 'admin/category_edit.html'; + $c->forward( 'category_edit' ); +} + +sub body : Chained('body_base') : PathPart('') : CaptureArgs(1) { + my ( $self, $c, $body_id ) = @_; $c->stash->{body_id} = $body_id; +} + +sub edit_body : Chained('body') : PathPart('') : Args(0) { + my ( $self, $c ) = @_; + + unless ($c->user->has_permission_to('category_edit', $c->stash->{body_id})) { + $c->forward('check_for_super_user'); + } + + $c->forward( '/auth/get_csrf_token' ); + $c->forward( 'lookup_body' ); + $c->forward( 'fetch_all_bodies' ); + $c->forward( 'body_form_dropdowns' ); + $c->forward('fetch_languages'); + + if ( $c->get_param('posted') ) { + $c->forward('update_contacts'); + } + + $c->stash->{object} = $c->stash->{body}; + $c->stash->{translation_col} = 'name'; + + # if there's a contact then it's because we're displaying error + # messages about adding a contact so grabbing translations will + # fetch the contact submitted translations. So grab them, stash + # them and then clear posted so we can fetch the body translations + if ($c->stash->{contact}) { + $c->forward('fetch_translations'); + $c->stash->{contact_translations} = $c->stash->{translations}; + } + $c->set_param('posted', ''); + + $c->forward('fetch_translations'); + $c->forward('fetch_contacts'); + + $c->stash->{template} = 'admin/body.html'; + return 1; +} + +sub category : Chained('body') : PathPart('') : CaptureArgs(1) { + my ( $self, $c, $category ) = @_; $c->forward( '/auth/get_csrf_token' ); $c->forward( 'lookup_body' ); my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first; $c->stash->{contact} = $contact; +} + +sub category_edit : Chained('category') : PathPart('') : Args(0) { + my ( $self, $c ) = @_; + + $c->stash->{translation_col} = 'category'; + $c->stash->{object} = $c->stash->{contact}; + + $c->forward('fetch_languages'); + $c->forward('fetch_translations'); my $history = $c->model('DB::ContactsHistory')->search( { - body_id => $body_id, - category => $category + body_id => $c->stash->{body_id}, + category => $c->stash->{contact}->category }, { order_by => ['contacts_history_id'] }, ); $c->stash->{history} = $history; - my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders }; $c->stash->{send_methods} = \@methods; -- cgit v1.2.3 From 8e320beadae7cbc65967fc851f2448bbb1c7b2e0 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 11 Aug 2017 10:44:10 +0100 Subject: Prevent unnecessary string translation. Calling the function 'translate' causes gettext-extract to add the string to the .po file. Also, we no longer need an admin 'updated' message as the main form has its own success message. --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 -- 1 file changed, 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 0fa58eb9d..87773a31b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -469,8 +469,6 @@ sub update_translations : Private { ); } } - - $c->stash->{updated} = _('Translations updated'); } sub body_params : Private { -- cgit v1.2.3 From 55ce7d174aa2638f9f8b0053ca823368149a9105 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 14 Aug 2017 15:56:20 +0100 Subject: translate report template category names in controller We can't translate them in the template as we're just passing in the category name and not the object. Fixes mysociety/fixmystreetforcouncils#216 --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 87773a31b..0b1720982 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1099,7 +1099,7 @@ sub template_edit : Path('templates') : Args(2) { my %active_contacts = map { $_->id => 1 } @contacts; my @all_contacts = map { { id => $_->id, - category => $_->category, + category => $_->category_display, active => $active_contacts{$_->id}, } } @live_contacts; $c->stash->{contacts} = \@all_contacts; -- cgit v1.2.3 From 5101c6fc13e4199ec8cb07fd0d405a6dcea68a60 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 15 Aug 2017 09:29:07 +0100 Subject: Add fn to fetch bodies plus the translated names. --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 0b1720982..aab114576 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1941,7 +1941,7 @@ sub check_page_allowed : Private { sub fetch_all_bodies : Private { my ($self, $c ) = @_; - my @bodies = $c->model('DB::Body')->all; + my @bodies = $c->model('DB::Body')->all_translated; if ( $c->cobrand->moniker eq 'zurich' ) { @bodies = $c->cobrand->admin_fetch_all_bodies( @bodies ); } else { -- cgit v1.2.3 From fb03c300258b5d1dc419d7d08ecb3afa12a2fa5b Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Mon, 24 Jul 2017 09:59:06 +0100 Subject: Add site-wide extra fields for reports, and admin UI to manage - Also provides an editor for the extra Open311 fields on contacts. - Adds .btn--small class for small buttons Fixes #1743. --- perllib/FixMyStreet/App/Controller/Admin.pm | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index aab114576..cd1246134 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -375,6 +375,8 @@ sub update_contacts : Private { $contact->set_extra_metadata( reputation_threshold => int($c->get_param('reputation_threshold')) ); } + $c->forward('update_extra_fields', [ $contact ]); + if ( %errors ) { $c->stash->{updated} = _('Please correct the errors below'); $c->stash->{contact} = $contact; @@ -1973,6 +1975,46 @@ sub fetch_body_areas : Private { $c->stash->{fetched_areas_body_id} = $body->id; } +sub update_extra_fields : Private { + my ($self, $c, $object) = @_; + + my @indices = grep { /^metadata\[\d+\]\.code/ } keys %{ $c->req->params }; + @indices = sort map { /(\d+)/ } @indices; + + my @extra_fields; + foreach my $i (@indices) { + my $meta = {}; + $meta->{code} = $c->get_param("metadata[$i].code"); + next unless $meta->{code}; + $meta->{order} = int $c->get_param("metadata[$i].order"); + $meta->{datatype} = $c->get_param("metadata[$i].datatype"); + my $required = $c->get_param("metadata[$i].required") && $c->get_param("metadata[$i].required") eq 'on'; + $meta->{required} = $required ? 'true' : 'false'; + my $notice = $c->get_param("metadata[$i].notice") && $c->get_param("metadata[$i].notice") eq 'on'; + $meta->{variable} = $notice ? 'false' : 'true'; + $meta->{description} = $c->get_param("metadata[$i].description"); + $meta->{datatype_description} = $c->get_param("metadata[$i].datatype_description"); + + if ( $meta->{datatype} eq "singlevaluelist" ) { + $meta->{values} = []; + my $re = qr{^metadata\[$i\]\.values\[\d+\]\.key}; + my @vindices = grep { /$re/ } keys %{ $c->req->params }; + @vindices = sort map { /values\[(\d+)\]/ } @vindices; + foreach my $j (@vindices) { + my $name = $c->get_param("metadata[$i].values[$j].name"); + my $key = $c->get_param("metadata[$i].values[$j].key"); + push(@{$meta->{values}}, { + name => $name, + key => $key, + }) if $name; + } + } + push @extra_fields, $meta; + } + @extra_fields = sort { $a->{order} <=> $b->{order} } @extra_fields; + $object->set_extra_fields(@extra_fields); +} + sub trim { my $self = shift; my $e = shift; -- cgit v1.2.3 From 7fb251eb773782e1b0faccc41b5e2aee8f3db18c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 25 Aug 2017 19:59:32 +0100 Subject: Sort languages in template. --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index cd1246134..f1508f0b1 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -523,7 +523,7 @@ sub fetch_languages : Private { my ( $self, $c ) = @_; my $lang_map = {}; - foreach my $lang (sort @{$c->cobrand->languages}) { + foreach my $lang (@{$c->cobrand->languages}) { my ($id, $name, $code) = split(',', $lang); $lang_map->{$id} = { name => $name, code => $code }; } -- cgit v1.2.3 From 137dcda8e489c5cbd2a777c83148d1e4a3bd1a60 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 8 Sep 2017 20:51:03 +0100 Subject: Fix bug if first page after restart is admin. If the first page looked at after server launch was an admin one, the User object was getting a different schema attached than the one used by everything else (so e.g. the cobrand was not then available to it, causing a crash on a body page). Using auto instead of begin prevents this from happening, as the setup_request auto always runs first. --- perllib/FixMyStreet/App/Controller/Admin.pm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index f1508f0b1..5bdcb5642 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -27,7 +27,7 @@ Admin pages =cut -sub begin : Private { +sub auto : Private { my ( $self, $c ) = @_; $c->uri_disposition('relative'); @@ -44,10 +44,6 @@ sub begin : Private { if ( $c->cobrand->moniker eq 'zurich' ) { $c->cobrand->admin_type(); } -} - -sub auto : Private { - my ( $self, $c ) = @_; $c->forward('check_page_allowed'); } -- cgit v1.2.3 From 59f419a4f2ea2a94ba30b43d2dadb6c6fcab3729 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 8 Sep 2017 21:26:52 +0100 Subject: Fix issue editing category with '/' in it. Simplify chaining of body/category admin URLs so that all categories are treated the same, with `/` or without, and the template will then always have its CSRF token. --- perllib/FixMyStreet/App/Controller/Admin.pm | 42 +++++------------------------ 1 file changed, 7 insertions(+), 35 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 5bdcb5642..ed40f4565 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -553,10 +553,10 @@ sub fetch_translations : Private { $c->stash->{translations} = $translations; } -sub lookup_body : Private { - my ( $self, $c ) = @_; +sub body : Chained('/') : PathPart('admin/body') : CaptureArgs(1) { + my ( $self, $c, $body_id ) = @_; - my $body_id = $c->stash->{body_id}; + $c->stash->{body_id} = $body_id; my $body = $c->model('DB::Body')->find($body_id); $c->detach( '/page_error_404_not_found', [] ) unless $body; @@ -568,30 +568,6 @@ sub lookup_body : Private { $c->stash->{example_pc} = $example_postcode; } } - - return 1; -} - -sub body_base : Chained('/') : PathPart('admin/body') : CaptureArgs(0) { } - -# This is for if the category name contains a '/' -sub category_edit_all : Chained('body_base') : PathPart('') { - my ( $self, $c, $body_id, @category ) = @_; - my $category = join( '/', @category ); - - $c->stash->{body_id} = $body_id; - $c->forward( 'lookup_body' ); - - my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first; - $c->stash->{contact} = $contact; - - $c->stash->{template} = 'admin/category_edit.html'; - $c->forward( 'category_edit' ); -} - -sub body : Chained('body_base') : PathPart('') : CaptureArgs(1) { - my ( $self, $c, $body_id ) = @_; - $c->stash->{body_id} = $body_id; } sub edit_body : Chained('body') : PathPart('') : Args(0) { @@ -602,7 +578,6 @@ sub edit_body : Chained('body') : PathPart('') : Args(0) { } $c->forward( '/auth/get_csrf_token' ); - $c->forward( 'lookup_body' ); $c->forward( 'fetch_all_bodies' ); $c->forward( 'body_form_dropdowns' ); $c->forward('fetch_languages'); @@ -631,18 +606,15 @@ sub edit_body : Chained('body') : PathPart('') : Args(0) { return 1; } -sub category : Chained('body') : PathPart('') : CaptureArgs(1) { - my ( $self, $c, $category ) = @_; +sub category : Chained('body') : PathPart('') { + my ( $self, $c, @category ) = @_; + my $category = join( '/', @category ); $c->forward( '/auth/get_csrf_token' ); - $c->forward( 'lookup_body' ); + $c->stash->{template} = 'admin/category_edit.html'; my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first; $c->stash->{contact} = $contact; -} - -sub category_edit : Chained('category') : PathPart('') : Args(0) { - my ( $self, $c ) = @_; $c->stash->{translation_col} = 'category'; $c->stash->{object} = $c->stash->{contact}; -- cgit v1.2.3