diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 38 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 15 |
3 files changed, 71 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index c4bd5c293..e91597bb0 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -841,6 +841,7 @@ sub report_edit_category : Private { my ($self, $c, $problem) = @_; if ((my $category = $c->get_param('category')) ne $problem->category) { + my $category_old = $problem->category; $problem->category($category); my @contacts = grep { $_->category eq $problem->category } @{$c->stash->{contacts}}; my @new_body_ids = map { $_->body_id } @contacts; @@ -849,6 +850,16 @@ sub report_edit_category : Private { $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) . '*', + created => \'current_timestamp', + confirmed => \'current_timestamp', + user_id => $c->user->id, + name => $c->user->from_body ? $c->user->from_body->name : $c->user->name, + state => 'confirmed', + mark_fixed => 0, + anonymous => 0, + }); } } @@ -1330,6 +1341,17 @@ sub user_edit : Path('user_edit') : Args(1) { } $c->stash->{field_errors} = {}; + + # Update the categories this user operates in + if ( $user->from_body ) { + $c->stash->{body} = $user->from_body; + $c->forward('fetch_contacts'); + my @live_contacts = $c->stash->{live_contacts}->all; + my @live_contact_ids = map { $_->id } @live_contacts; + my @new_contact_ids = grep { $c->get_param("contacts[$_]") } @live_contact_ids; + $user->set_extra_metadata('categories', \@new_contact_ids); + } + unless ($user->email) { $c->stash->{field_errors}->{email} = _('Please enter a valid email'); } @@ -1354,6 +1376,22 @@ sub user_edit : Path('user_edit') : Args(1) { '<p><em>' . _('Updated!') . '</em></p>'; } + if ( $user->from_body ) { + unless ( $c->stash->{body} && $user->from_body->id eq $c->stash->{body}->id ) { + $c->stash->{body} = $user->from_body; + $c->forward('fetch_contacts'); + } + my @contacts = @{$user->get_extra_metadata('categories') || []}; + my %active_contacts = map { $_ => 1 } @contacts; + my @live_contacts = $c->stash->{live_contacts}->all; + my @all_contacts = map { { + id => $_->id, + category => $_->category, + active => $active_contacts{$_->id}, + } } @live_contacts; + $c->stash->{contacts} = \@all_contacts; + } + return 1; } diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index ae06181c8..f0bcad0be 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -22,6 +22,7 @@ __PACKAGE__->config( FILTERS => { add_links => \&add_links, escape_js => \&escape_js, + markup => [ \&markup_factory, 1 ], }, COMPILE_EXT => '.ttc', STAT_TTL => FixMyStreet->config('STAGING_SITE') ? 1 : 86400, @@ -98,6 +99,23 @@ sub _space_slash { return $t; } +=head2 markup_factory + +This returns a function that will allow updates to have markdown-style italics. +Pass in the user that wrote the text, so we know whether it can be privileged. + +=cut + +sub markup_factory { + my ($c, $user) = @_; + return sub { + my $text = shift; + return $text unless $user && ($user->from_body || $user->is_superuser); + $text =~ s{\*(\S.*?\S)\*}{<i>$1</i>}; + $text; + } +} + =head2 escape_js Used to escape strings that are going to be put inside JavaScript. diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 7ec49b074..028394795 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -391,4 +391,19 @@ sub update_reputation { $self->update; } +has categories => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + return [] unless $self->get_extra_metadata('categories'); + my @categories = $self->result_source->schema->resultset("Contact")->search({ + id => $self->get_extra_metadata('categories'), + }, { + order_by => 'category', + })->get_column('category')->all; + return \@categories; + }, +); + 1; |