aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-12 13:14:23 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-12 13:14:23 +0100
commita9b2134ef5c94a74f840315aee987bfc57680c69 (patch)
treedc7d36af4c6c1c5e2751d59a3c8930e99d2a9ab7
parent105291154c3dfaa905202ff576c51097759094df (diff)
problem update alert subscription
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm54
-rw-r--r--t/app/controller/alert_new.t18
-rw-r--r--templates/web/default/alert/updates.html22
3 files changed, 79 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index 56464dd64..6cf0ecc09 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -195,23 +195,17 @@ sub subscribe_email : Private {
if $type && $type eq 'local' && !$c->req->param('feed');
if (@errors) {
$c->stash->{errors} = \@errors;
- $c->go('list');
-
- # return alert_updates_form($q, @errors) if $type && $type eq 'updates';
- # return alert_list($q, @errors) if $type && $type eq 'local';
- # return alert_front_page($q, @errors);
+ $c->go('updates') if $type && $type eq 'updates';
+ $c->go('list') if $type && $type eq 'local';
+ $c->go('index');
}
my $email = $c->req->param('rznvy');
$c->stash->{email} = $email;
$c->forward('process_user');
- my $alert;
-
- # my $cobrand = Page::get_cobrand($q);
- # my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q);
if ( $type eq 'updates' ) {
-
+ $c->forward('create_update_alert');
# my $id = $q->param('id');
# $alert_id = FixMyStreet::Alert::create($email, 'new_updates', $cobrand, $cobrand_data, $id);
}
@@ -229,6 +223,14 @@ sub subscribe_email : Private {
$c->forward('send_confirmation_email');
}
+sub updates : Path('updates') : Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{email} = $c->req->param('rznvy');
+ $c->stash->{problem_id} = $c->req->param('id');
+ $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts');
+}
+
=head2 confirm
Confirm signup to an alert. Forwarded here from Tokens.
@@ -251,6 +253,38 @@ sub confirm : Private {
}
}
+=head2 create_update_alert
+
+Create an update alert
+
+=cut
+
+sub create_update_alert : Private {
+ my ( $self, $c ) = @_;
+
+ my $report_id = $c->req->param('id');
+
+ my $options = {
+ user => $c->stash->{alert_user},
+ alert_type => 'new_updates',
+ parameter => $report_id,
+ };
+
+ my $alert = $c->model('DB::Alert')->find($options);
+
+ unless ($alert) {
+ $options->{cobrand} = $c->cobrand->moniker();
+ $options->{cobrand_data} = $c->cobrand->extra_update_data();
+
+ $alert = $c->model('DB::Alert')->new($options);
+ $alert->insert();
+ }
+
+ $c->stash->{alert} = $alert;
+
+ $c->log->debug( 'created alert ' . $alert->id );
+}
+
=head2 create_local_alert
Create a local alert
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index c44d14a30..7cbf6188a 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -9,7 +9,7 @@ my $mech = FixMyStreet::TestMech->new;
foreach my $test (
{
email => 'test@example.com',
- type => 'area',
+ type => 'area_problems',
content => 'your alert will not be activated',
email_text => 'confirm the alert',
uri =>
@@ -18,7 +18,7 @@ foreach my $test (
},
{
email => 'test@example.com',
- type => 'council',
+ type => 'council_problems',
content => 'your alert will not be activated',
email_text => 'confirm the alert',
uri =>
@@ -28,7 +28,7 @@ foreach my $test (
},
{
email => 'test@example.com',
- type => 'ward',
+ type => 'ward_problems',
content => 'your alert will not be activated',
email_text => 'confirm the alert',
uri =>
@@ -38,20 +38,28 @@ foreach my $test (
},
{
email => 'test@example.com',
- type => 'local',
+ type => 'local_problems',
content => 'your alert will not be activated',
email_text => 'confirm the alert',
uri =>
'/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1',
param1 => 10.2,
param2 => 20.1,
+ },
+ {
+ email => 'test@example.com',
+ type => 'new_updates',
+ content => 'your alert will not be activated',
+ email_text => 'confirm the alert',
+ uri => '/alert/subscribe?type=updates&rznvy=test@example.com&id=1',
+ param1 => 1,
}
)
{
subtest "$test->{type} alert correctly created" => sub {
$mech->clear_emails_ok;
- my $type = $test->{type} . '_problems';
+ my $type = $test->{type};
my $user =
FixMyStreet::App->model('DB::User')
diff --git a/templates/web/default/alert/updates.html b/templates/web/default/alert/updates.html
new file mode 100644
index 000000000..88b014ff6
--- /dev/null
+++ b/templates/web/default/alert/updates.html
@@ -0,0 +1,22 @@
+[% title = loc('Local RSS feeds and email alerts') %]
+
+[% INCLUDE 'header.html', title => title %]
+
+
+[% INCLUDE 'errors.html' %]
+
+<p>
+[% loc('Receive email when updates are left on this problem.') %]
+</p>
+
+<form action="/alert/subscribe" method="post">
+<label class="n" for="alert_rznvy">[% loc('Email:') %]</label>
+<input type="text" name="rznvy" id="alert_rznvy" value="[% email | html %]" size="30">
+<input type="hidden" name="id" value="[% problem_id | html %]">
+<input type="hidden" name="type" value="updates">
+<input type="submit" value="[% loc('Subscribe') %]">
+[% cobrand_form_elements %]
+</form>
+
+
+[% INCLUDE 'footer.html' %]