aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-questionnaires4
-rw-r--r--perllib/Cobrand.pm41
-rw-r--r--perllib/Page.pm18
-rwxr-xr-xt/Cobrand.t20
-rw-r--r--t/Cobrands/Mysite/Util.pm6
-rwxr-xr-xweb/alert.cgi4
-rwxr-xr-xweb/index.cgi6
7 files changed, 77 insertions, 22 deletions
diff --git a/bin/send-questionnaires b/bin/send-questionnaires
index 9390360d8..03511f8dd 100755
--- a/bin/send-questionnaires
+++ b/bin/send-questionnaires
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: send-questionnaires,v 1.16 2009-09-10 13:03:37 louise Exp $
+# $Id: send-questionnaires,v 1.17 2009-09-16 17:00:35 louise Exp $
use strict;
require 5.8.0;
@@ -78,7 +78,7 @@ foreach my $row (@$unsent) {
dbh()->do("update problem set send_questionnaire = 'f' where id=?", {}, $row->{id});
my $token = mySociety::AuthToken::store('questionnaire', $id);
- $h{url} = Cobrand::base_url($cobrand) . '/Q/' . $token;
+ $h{url} = Cobrand::base_url_for_emails($cobrand) . '/Q/' . $token;
my $sender = Cobrand::contact_email($cobrand);
$sender =~ s/team/fms-DO-NOT-REPLY/;
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
index 2441aff73..c780e28e8 100644
--- a/perllib/Cobrand.pm
+++ b/perllib/Cobrand.pm
@@ -7,7 +7,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: Cobrand.pm,v 1.16 2009-09-15 17:42:43 louise Exp $
+# $Id: Cobrand.pm,v 1.17 2009-09-16 17:00:35 louise Exp $
package Cobrand;
use strict;
@@ -18,7 +18,7 @@ use Carp;
Return an array reference of allowed cobrand subdomains
=cut
-sub get_allowed_cobrands{
+sub get_allowed_cobrands {
my $allowed_cobrand_string = mySociety::Config::get('ALLOWED_COBRANDS');
my @allowed_cobrands = split(/\|/, $allowed_cobrand_string);
return \@allowed_cobrands;
@@ -53,7 +53,7 @@ sub cobrand_handle {
Return a string containing the HTML to be rendered for a custom Cobranded page
=cut
-sub cobrand_page{
+sub cobrand_page {
my $q = shift;
my $cobrand = $q->{site};
my $handle = cobrand_handle($cobrand);
@@ -68,7 +68,7 @@ data. Q is the query object. Returns an empty string and site key 0 if the cobra
data.
=cut
-sub set_site_restriction{
+sub set_site_restriction {
my $q = shift;
my $site_restriction = '';
my $site_id = 0;
@@ -83,7 +83,7 @@ sub set_site_restriction{
Return the base url for the cobranded version of the site
=cut
-sub base_url{
+sub base_url {
my $cobrand = shift;
return mySociety::Config::get('BASE_URL') unless $cobrand;
my $handle = cobrand_handle($cobrand);
@@ -91,6 +91,26 @@ sub base_url{
return $handle->base_url();
}
+=item base_url_for_emails COBRAND
+
+Return the base url to use in links in emails for the cobranded
+version of the site
+
+=cut
+
+sub base_url_for_emails {
+ my ($cobrand) = @_;
+ my $handle;
+ if ($cobrand){
+ $handle = cobrand_handle($cobrand);
+ }
+ if ( !$cobrand || !$handle || ! $handle->can('base_url_for_emails')){
+ return base_url($cobrand);
+ }{
+ return $handle->base_url_for_emails();
+ }
+}
+
=item contact_email COBRAND
Return the contact email for the cobranded version of the site
@@ -104,11 +124,16 @@ sub contact_email {
sub get_cobrand_conf {
my ($cobrand, $key) = @_;
my $value;
- $cobrand = uc($cobrand);
if ($cobrand){
- $value = mySociety::Config::get($key . "_" . $cobrand, undef);
+ (my $dir = __FILE__) =~ s{/[^/]*?$}{};
+ if (-e "$dir/../conf/cobrands/$cobrand/general"){
+ mySociety::Config::set_file("$dir/../conf/cobrands/$cobrand/general");
+ $cobrand = uc($cobrand);
+ $value = mySociety::Config::get($key . "_" . $cobrand, undef);
+ mySociety::Config::set_file("$dir/../conf/general");
+ }
}
- if (!$value){
+ if (!defined($value)){
$value = mySociety::Config::get($key);
}
return $value;
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 1bb94bc58..b4610c3d4 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.pm,v 1.178 2009-09-15 17:42:43 louise Exp $
+# $Id: Page.pm,v 1.179 2009-09-16 17:00:35 louise Exp $
#
package Page;
@@ -125,9 +125,21 @@ sub get_cobrand {
return $cobrand;
}
+=item base_url_with_lang Q REVERSE EMAIL
+
+Return the base URL for the site. Reverse the language component if REVERSE is set to one. If EMAIL is set to
+one, return the base URL to use in emails.
+
+=cut
+
sub base_url_with_lang {
- my ($q, $reverse) = @_;
- my $base = Cobrand::base_url(get_cobrand($q));
+ my ($q, $reverse, $email) = @_;
+ my $base;
+ if ($email) {
+ $base = Cobrand::base_url_for_emails(get_cobrand($q));
+ } else {
+ $base = Cobrand::base_url(get_cobrand($q));
+ }
return $base unless $q->{site} eq 'emptyhomes';
my $lang = $mySociety::Locale::lang;
if ($reverse && $lang eq 'en-gb') {
diff --git a/t/Cobrand.t b/t/Cobrand.t
index fe6d46f51..79153e690 100755
--- a/t/Cobrand.t
+++ b/t/Cobrand.t
@@ -6,12 +6,12 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Cobrand.t,v 1.7 2009-09-15 17:42:43 louise Exp $
+# $Id: Cobrand.t,v 1.8 2009-09-16 17:00:35 louise Exp $
#
use strict;
use warnings;
-use Test::More tests => 20;
+use Test::More tests => 23;
use Test::Exception;
use FindBin;
@@ -56,7 +56,6 @@ sub test_disambiguate_location {
}
-
sub test_cobrand_handle {
my $cobrand = 'mysite';
my $handle = Cobrand::cobrand_handle($cobrand);
@@ -95,9 +94,24 @@ sub test_base_url {
}
+sub test_base_url_for_emails {
+ my $cobrand = 'mysite';
+
+ # should get the results of the base_url_for_emails function in the cobrand module if one exists
+ my $base_url = Cobrand::base_url_for_emails($cobrand);
+ is('http://mysite.foremails.example.com', $base_url, 'base_url_for_emails returns output from cobrand module');
+
+ # should return the result of Cobrand::base_url otherwise
+ $cobrand = 'nosite';
+ $base_url = Cobrand::base_url_for_emails($cobrand);
+ is(mySociety::Config::get('BASE_URL'), $base_url, 'base_url_for_emails returns config base url if no cobrand module');
+
+}
+
ok(test_cobrand_handle() == 1, 'Ran all tests for the cobrand_handle function');
ok(test_cobrand_page() == 1, 'Ran all tests for the cobrand_page function');
ok(test_site_restriction() == 1, 'Ran all tests for the site_restriction function');
ok(test_base_url() == 1, 'Ran all tests for the base url');
ok(test_disambiguate_location() == 1, 'Ran all tests for disambiguate location');
ok(test_form_elements() == 1, 'Ran all tests for form_elements');
+ok(test_base_url_for_emails() == 1, 'Ran all tests for base_url_for_emails');
diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm
index 6e7098b43..ae9202d6f 100644
--- a/t/Cobrands/Mysite/Util.pm
+++ b/t/Cobrands/Mysite/Util.pm
@@ -7,7 +7,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: Util.pm,v 1.6 2009-09-15 17:42:43 louise Exp $
+# $Id: Util.pm,v 1.7 2009-09-16 17:00:36 louise Exp $
package Cobrands::Mysite::Util;
use Page;
@@ -37,6 +37,10 @@ sub base_url {
return 'http://mysite.example.com';
}
+sub base_url_for_emails {
+ return 'http://mysite.foremails.example.com';
+}
+
sub disambiguate_location {
return 'Specific Location';
}
diff --git a/web/alert.cgi b/web/alert.cgi
index 3ba199ca5..effe0ced2 100755
--- a/web/alert.cgi
+++ b/web/alert.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: alert.cgi,v 1.46 2009-09-15 17:42:43 louise Exp $
+# $Id: alert.cgi,v 1.47 2009-09-16 17:00:36 louise Exp $
use strict;
use Standard;
@@ -407,7 +407,7 @@ sub alert_do_subscribe {
}
my %h = ();
- $h{url} = Page::base_url_with_lang($q) . '/A/'
+ $h{url} = Page::base_url_with_lang($q, undef, 1) . '/A/'
. mySociety::AuthToken::store('alert', { id => $alert_id, type => 'subscribe', email => $email } );
dbh()->commit();
return Page::send_email($q, $email, undef, 'alert', %h);
diff --git a/web/index.cgi b/web/index.cgi
index b320f6bdb..d94ec7ea9 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.282 2009-09-15 17:42:43 louise Exp $
+# $Id: index.cgi,v 1.283 2009-09-16 17:00:36 louise Exp $
use strict;
use Standard;
@@ -231,7 +231,7 @@ sub submit_update {
my %h = ();
$h{update} = $input{update};
$h{name} = $input{name} ? $input{name} : _("Anonymous");
- my $base = Page::base_url_with_lang($q);
+ my $base = Page::base_url_with_lang($q, undef, 1);
$base =~ s/matthew/scambs.matthew/ if $q->{site} eq 'scambs'; # XXX Temp
$h{url} = $base . '/C/' . mySociety::AuthToken::store('update', { id => $id, add_alert => $input{add_alert} } );
dbh()->commit();
@@ -399,7 +399,7 @@ Please <a href="/contact">let us know what went on</a> and we\'ll look into it.'
$h{title} = $input{title};
$h{detail} = $input{detail};
$h{name} = $input{name};
- my $base = Page::base_url_with_lang($q);
+ my $base = Page::base_url_with_lang($q, undef, 1);
$h{url} = $base . '/P/' . mySociety::AuthToken::store('problem', $id);
dbh()->commit();