diff options
author | Struan Donald <struan@exo.org.uk> | 2011-08-04 12:42:21 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-08-04 12:42:21 +0100 |
commit | 8a253eeff63556c7bf3ed7cac5ecb82cbfacef27 (patch) | |
tree | 5cc29eb7f06ecaf6d50c598488b261a59de342d7 | |
parent | 3bb65a5debda34cdffd2a83f4747ea19412d0410 (diff) |
configure open311 endpoint etc in admin interface
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 32 | ||||
-rw-r--r-- | t/app/controller/admin.t | 53 | ||||
-rw-r--r-- | templates/web/default/admin/council_contacts.html | 34 |
3 files changed, 119 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index a0d3e8643..5c04bf2ad 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -323,6 +323,32 @@ sub update_contacts : Private { ); $c->stash->{updated} = _('Values updated'); + } elsif ( $posted eq 'open311' ) { + $c->forward('check_token'); + + my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id/; + + if ( $params{open311_id} ) { + my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); + + $conf->endpoint( $params{endpoint} ); + $conf->jurisdiction( $params{jurisdiction} ); + $conf->api_key( $params{api_key} ); + + $conf->update(); + + $c->stash->{updated} = _('Configuration updated'); + } else { + my $conf = $c->model('DB::Open311Conf')->find_or_new( { area_id => $params{area_id} } ); + + $conf->endpoint( $params{endpoint} ); + $conf->jurisdiction( $params{jurisdiction} ); + $conf->api_key( $params{api_key} ); + + $conf->insert(); + + $c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later'); + } } } @@ -340,6 +366,12 @@ sub display_contacts : Private { $c->stash->{contacts} = $contacts; + my $open311 = $c->model('DB::Open311Conf')->search( + { area_id => $area_id } + ); + + $c->stash->{open311} = $open311; + if ( $c->req->param('text') && $c->req->param('text') == 1 ) { $c->stash->{template} = 'admin/council_contacts.txt'; $c->res->content_type('text/plain; charset=utf-8'); diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 9f698c629..17e6f015e 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -202,6 +202,59 @@ subtest 'check contact updating' => sub { $mech->content_like(qr{test2\@example.com[^<]*</td>[^<]*<td><strong>Yes}s); }; +my $open311 = + FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } ); +$open311->delete if $open311; + +subtest 'check open311 configuring' => sub { + $mech->get_ok('/admin/council_contacts/2650/'); + $mech->content_lacks('Council contacts configured via Open311'); + + $mech->form_number(3); + $mech->submit_form_ok( + { + with_fields => { + api_key => 'api key', + endpoint => 'http://example.com/open311', + jurisdiction => 'mySociety', + } + } + ); + $mech->content_contains('Council contacts configured via Open311'); + $mech->content_contains('Configuration updated - contacts will be generated automatically later'); + + $open311 = + FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } ); + + is $open311->count, 1, 'only one configuration'; + my $conf = $open311->first; + is $conf->endpoint, 'http://example.com/open311', 'endpoint configured'; + is $conf->api_key, 'api key', 'api key configured'; + is $conf->jurisdiction, 'mySociety', 'jurisdiction configures'; + + $mech->form_number(3); + $mech->submit_form_ok( + { + with_fields => { + api_key => 'new api key', + endpoint => 'http://example.org/open311', + jurisdiction => 'open311', + } + } + ); + + $mech->content_contains('Configuration updated'); + + $open311 = + FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } ); + + is $open311->count, 1, 'only one configuration'; + $conf = $open311->first; + is $conf->endpoint, 'http://example.org/open311', 'endpoint updated'; + is $conf->api_key, 'new api key', 'api key updated'; + is $conf->jurisdiction, 'open311', 'jurisdiction configures'; +}; + subtest 'check text output' => sub { $mech->get_ok('/admin/council_contacts/2650?text=1'); is $mech->content_type, 'text/plain'; diff --git a/templates/web/default/admin/council_contacts.html b/templates/web/default/admin/council_contacts.html index 669f137f9..75d915a29 100644 --- a/templates/web/default/admin/council_contacts.html +++ b/templates/web/default/admin/council_contacts.html @@ -12,6 +12,13 @@ <a href="[% c.uri_for( 'council_contacts', area_id, { text => 1 } ) %]">[% loc('Text only version') %]</a> </p> +[% IF open311.count > 0 %] + <h2> + Council contacts configured via Open311 + </h2> + +[% END %] + <form method="post" action="[% c.uri_for('council_contacts', area_id ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> <table cellspacing="0" cellpadding="2" border="1"> @@ -86,4 +93,31 @@ </div> </form> + <h2>[% loc('Configure Open311 integration') %]</h2> + <form method="post" action="[% c.uri_for('council_contacts', area_id ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> + [% conf = open311.next %] + <p> + <label for="endpoint">Endpoint</label>: + <input type="text" name="endpoint" id="endpoint" value="[% conf.endpoint %]" size="50"> + </p> + + <p> + <label for="jurisdiction">Jurisdiction</label>: + <input type="text" name="jurisdiction" id="jurisdiction" value="[% conf.jurisdiction %]" size="50"> + </p> + + <p> + <label for="api_key">Api Key</label>: + <input type="text" name="api_key" id="api_key" value="[% conf.api_key %]" size="25"> + </p> + + <p> + <input type="hidden" name="open311_id" value="[% conf.id %]"> + <input type="hidden" name="area_id" value="[% area_id %]"> + <input type="hidden" name="posted" value="open311"> + <input type="hidden" name="token" value="[% token %]"> + <input type="submit" name="Configure Open311" value="[% loc('Configure Open311') %]"> + </p> + </form> + [% INCLUDE 'admin/footer.html' %] |