aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2016-12-06 11:57:34 +0000
committerDave Arter <davea@mysociety.org>2016-12-06 12:16:22 +0000
commit102418842a833c29f855557bf4c410290b5a2020 (patch)
treed639ff3adbd2fecadfd5ac1266cccf65db093f47
parent7df5f6d00c34580987509a2ccb4520d2fde96866 (diff)
[Zurich] Fix 500 error when editing superusers
The Zurich::admin_type function was setting $c->stash->{body}, meaning that when trying to edit a superuser the 'fetch_contacts' function wasn't being called, causing an "Can't call method "all" on an undefined value" error as $c->stash->{live_contacts} wasn't ever being set. Fixed by changing the conditional to simply determine whether fetch_contacts needs to be called. Included a regression test that meant a small addition to the MapItZurich mock.
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--t/Mock/MapItZurich.pm6
-rw-r--r--t/cobrand/zurich.t15
3 files changed, 21 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 3782063d5..bbdf449aa 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1377,7 +1377,7 @@ sub user_edit : Path('user_edit') : Args(1) {
}
if ( $user->from_body ) {
- unless ( $c->stash->{body} && $user->from_body->id eq $c->stash->{body}->id ) {
+ unless ( $c->stash->{live_contacts} ) {
$c->stash->{body} = $user->from_body;
$c->forward('fetch_contacts');
}
diff --git a/t/Mock/MapItZurich.pm b/t/Mock/MapItZurich.pm
index ece9a9b22..9195749f6 100644
--- a/t/Mock/MapItZurich.pm
+++ b/t/Mock/MapItZurich.pm
@@ -38,6 +38,12 @@ sub dispatch_request {
my $json = $self->json->encode({});
return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
},
+
+ sub (GET + /area/*/children) {
+ my ($self, $area) = @_;
+ my $json = $self->json->encode({});
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
}
__PACKAGE__->run_if_script;
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index b59e546dd..ddaae1f90 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -102,8 +102,9 @@ sub get_export_rows_count {
my $EXISTING_REPORT_COUNT = 0;
+my $superuser;
subtest "set up superuser" => sub {
- my $superuser = $mech->log_in_ok( 'super@example.org' );
+ $superuser = $mech->log_in_ok( 'super@example.org' );
# a user from body $zurich is a superuser, as $zurich has no parent id!
$superuser->update({ from_body => $zurich->id });
$EXISTING_REPORT_COUNT = get_export_rows_count($mech);
@@ -968,6 +969,18 @@ subtest 'time_spent' => sub {
$mech->log_out_ok;
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ MAPIT_URL => 'http://mapit.zurich/',
+ MAPIT_TYPES => [ 'ZZZ' ],
+}, sub {
+ LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich');
+ subtest 'users at the top level can be edited' => sub {
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok('/admin/user_edit/' . $superuser->id );
+ };
+};
+
END {
$mech->delete_body($subdivision);
$mech->delete_body($division);
ld } /* Literal.Number.Integer.Long */
#!/bin/bash
# problem-creation-graph
# Plot graph of rate of problem creation
#
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org. WWW: http://www.mysociety.org/
# 
# $Id: problem-creation-graph,v 1.6 2008-11-12 18:06:34 matthew Exp $

GPLOT_OUTPUT="set terminal png font 'Vera.ttf' 9 size 1200,400"
EXTENSION=".png"
#GPLOT_OUTPUT="set terminal fig color big thickness 1"
#EXTENSION=".fig"
#GPLOT_OUTPUT="set terminal svg size 800 250"
#EXTENSION=".svg"

cd `dirname $0`
cd ../../
source fixmystreet/commonlib/shlib/deployfns

read_conf fixmystreet/conf/general.yml

if [ $OPTION_BASE_URL = "http://reportemptyhomes.com" ]; then
    DATE="2008-10-01"
else
    DATE="2007-02-01"
fi

SOURCEA=/tmp/bci-creation-rate-graph-data-$RANDOM$RANDOM
SOURCEB=/tmp/bci-creation-rate-graph-data-$RANDOM$RANDOM
SOURCEC=/tmp/bci-creation-rate-graph-data-$RANDOM$RANDOM
SOURCED=/tmp/bci-creation-rate-graph-data-$RANDOM$RANDOM
SOURCEE=/tmp/bci-creation-rate-graph-data-$RANDOM$RANDOM
GPSCRIPT=/tmp/bci-creation-rate-graph-script-$RANDOM$RANDOM

#    where status in ('draft') 

function grab_data {
    echo "select 
        date(created), count(*)
        from problem 
        $1
        group by date(created)
        order by date(created)
        ;" | psql --host $OPTION_FMS_DB_HOST --port $OPTION_FMS_DB_PORT -A -F " " $OPTION_FMS_DB_NAME $OPTION_FMS_DB_USER | egrep -v "date|rows" >$2
}

# rather nastily, work out the cumulative heights in reverse, so can plot impulses on top of each other
grab_data "" $SOURCEA
grab_data "where state not in ('unconfirmed')" $SOURCEB
grab_data "where state not in ('unconfirmed', 'confirmed')" $SOURCEC
grab_data "where state not in ('unconfirmed', 'confirmed', 'fixed')" $SOURCED
grab_data "where state not in ('unconfirmed', 'confirmed', 'fixed', 'hidden')" $SOURCEE


#state = 'unconfirmed'
#or state = 'confirmed'
#or state = 'fixed'
#or state = 'hidden'
#or state = 'partial'


cat >$GPSCRIPT <<END 
    unset border
    unset arrow
    set key left
    set tics out
    $GPLOT_OUTPUT

    set xdata time
    set timefmt "%Y-%m-%d"
    set xrange ["$DATE":]
    set format x "%d %b %Y"
    set xtics nomirror
    set xlabel "status of problems that were created on each calendar day"

    set ytics nomirror 
    set ylabel "number of problems created on the calendar day" 
    set y2tics tc lt 2
    set y2label "cumulative total number of problems" tc lt 2
    set format y2 "%.0f"

#    set arrow 1 from '2005-02-14', 0 to '2005-02-14', 900 lt 0 nohead
#    set label 1 'launch of beta' at '2005-02-17', 900

    n = 0
END
echo -n >>$GPSCRIPT "    plot \"$SOURCEA\" using 1:2 with impulses lt 3 lw 15 title \"unconfirmed\","
if [ -s $SOURCEB ]; then
echo -n >>$GPSCRIPT " \"$SOURCEB\" using 1:2 with impulses lt 4 lw 15 title \"confirmed\","
fi
if [ -s $SOURCEC ]; then
echo -n >>$GPSCRIPT " \"$SOURCEC\" using 1:2 with impulses lt 5 lw 15 title \"fixed\","
fi
if [ -s $SOURCED ]; then
echo -n >>$GPSCRIPT " \"$SOURCED\" using 1:2 with impulses lt 6 lw 15 title \"hidden\","
fi
if [ -s $SOURCEE ]; then
echo -n >>$GPSCRIPT " \"$SOURCEE\" using 1:2 with impulses lt 7 lw 15 title \"partial (and any other types)\","
fi
cat >>$GPSCRIPT <<END 
    "< awk 'BEGIN { n = 0 } { n += \$2; print \$1, \$2, n; }' $SOURCEA" using 1:3 axes x1y2 with lines lt 2 title "cumulative total number of problems"
END
#echo "gpscript $GPSCRIPT"

export GDFONTPATH=/usr/share/fonts/truetype/ttf-bitstream-vera
gnuplot < $GPSCRIPT > fixmystreet/web/bci-live-creation$EXTENSION