[Rt-commit] rt branch, 4.4/dashboard-language, created. rt-4.4.0rc2-24-g01ec299

Shawn Moore shawn at bestpractical.com
Sun Dec 27 20:27:53 EST 2015


The branch, 4.4/dashboard-language has been created
        at  01ec29904b891bbaf5617921a1ce784cab40f6a4 (commit)

- Log -----------------------------------------------------------------
commit c7e56084ca8003c5d3f7eed6409c5b50ec9d6319
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Nov 10 18:00:53 2015 +0000

    Add language selector for dashboard subscriptions

diff --git a/share/html/Dashboards/Render.html b/share/html/Dashboards/Render.html
index 0306077..37ee4fc 100644
--- a/share/html/Dashboards/Render.html
+++ b/share/html/Dashboards/Render.html
@@ -55,6 +55,15 @@
 <& /Elements/Tabs &>
 % }
 
+% # honor the chosen language for just the dashboard content
+% my $original_handle;
+% if ($SubscriptionObj->id) {
+%     if (my $lang = $SubscriptionObj->SubValue('Language')) {
+%         $original_handle = $session{'CurrentUser'}->{'LangHandle'};
+%         $session{'CurrentUser'}->{'LangHandle'} = RT::I18N->get_handle($lang);
+%     }
+% }
+
 % $m->callback(CallbackName => 'BeforeTable', Dashboard => $Dashboard, show_cb => $show_cb);
 
 <table class="dashboard" id="dashboard-<%$id%>">
@@ -91,6 +100,10 @@
 </html>
 % }
 
+% # restore the original language for anything else on the page
+% if ($original_handle) {
+%     $session{'CurrentUser'}->{'LangHandle'} = $original_handle;
+% }
 <%INIT>
 
 
diff --git a/share/html/Dashboards/Subscription.html b/share/html/Dashboards/Subscription.html
index cb45f1b..73f2557 100644
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@ -165,6 +165,15 @@
 (<%$timezone%>)
 </td></tr>
 <tr><td class="label">
+<&|/l&>Language</&>:
+</td><td class="value">
+<& /Elements/SelectLang,
+    Name => 'Language',
+    Default => $fields{'Language'},
+    ShowNullOption => 1,
+ &>
+</td></tr>
+<tr><td class="label">
 <&|/l&>Rows</&>:
 </td><td class="value">
 <select name="Rows">
@@ -228,6 +237,7 @@ my %fields = (
     Recipients  => { Users => [], Groups => [] },
     Fow         => 1,
     Counter     => 0,
+    Language    => '',
 );
 
 # update any fields with the values from the subscription object
@@ -360,6 +370,8 @@ $Hour        => undef
 $Dow         => undef
 $Dom         => undef
 $Rows        => undef
+$Recipient   => undef
+$Language    => undef
 
 $UserField => undef
 $UserOp => undef
diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 3d004ae..3970324 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -91,6 +91,8 @@ my ($dashboard_id, $subscription_id) = get_dash_sub_ids();
 sub produces_dashboard_mail_ok { # {{{
     my %args = @_;
     my $subject = delete $args{Subject};
+    my $body_like = delete $args{BodyLike};
+    my $body_unlike = delete $args{BodyUnlike};
 
     local $Test::Builder::Level = $Test::Builder::Level + 1;
 
@@ -107,8 +109,20 @@ sub produces_dashboard_mail_ok { # {{{
     is($mail->head->get('X-RT-Dashboard-Subscription-Id'), "$subscription_id\n");
 
     my $body = $mail->bodyhandle->as_string;
-    like($body, qr{My dashboards});
+    like($body, qr{My dashboards}) if !$body_like && !$body_unlike;
     like($body, qr{<a href="http://[^/]+/Dashboards/\d+/Testing!">Testing!</a>});
+
+    if ($body_like) {
+        for my $re (ref($body_like) eq 'ARRAY' ? @$body_like : $body_like) {
+            ok($body =~ $re, "body should match $re");
+        }
+    }
+
+    if ($body_unlike) {
+        for my $re (ref($body_unlike) eq 'ARRAY' ? @$body_unlike : $body_unlike) {
+            ok($body !~ $re, "body should not match $re");
+        }
+    }
 } # }}}
 
 sub produces_no_dashboard_mail_ok { # {{{
@@ -318,6 +332,7 @@ create_dashboard($baseurl, $m);
 create_subscription($baseurl, $m,
     Frequency => 'monthly',
     Hour => '06:00',
+    Language => 'fr',
 );
 
 ($dashboard_id, $subscription_id) = get_dash_sub_ids();
@@ -326,8 +341,10 @@ $good_time = 1291201200;        # dec 1
 $bad_time = $good_time - 86400; # day before (i.e. different month)
 
 produces_dashboard_mail_ok(
-    Time    => $good_time,
-    Subject =>  "[example.com] a Monthly b Testing! c\n",
+    Time       => $good_time,
+    Subject    => "[example.com] a Monthly b Testing! c\n",
+    BodyLike   => qr/Mes tableaux de bord/,
+    BodyUnlike => qr/My dashboards/,
 );
 
 produces_no_dashboard_mail_ok(

commit 1c4e3cf6a10f8bcd82d7de1001cc1c53a01b8e26
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Dec 28 01:09:11 2015 +0000

    Use the recipient's language for email dashboards, not subscriber's

diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index 1786c06..ef60906 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -91,9 +91,6 @@ sub MailDashboards {
         $hour .= ':00';
         $RT::Logger->debug("Checking ".$user->Name."'s subscriptions: hour $hour, dow $dow, dom $dom");
 
-        my $currentuser = RT::CurrentUser->new;
-        $currentuser->LoadByName($user->Name);
-
         # look through this user's subscriptions, are any supposed to be generated
         # right now?
         for my $subscription ($user->Attributes->Named('Subscription')) {
@@ -134,6 +131,13 @@ sub MailDashboards {
             my $email_success = 0;
             for my $email (uniq @emails) {
                 eval {
+                    my $currentuser = RT::CurrentUser->new;
+                    $currentuser->LoadByEmail($email);
+
+                    if (my $lang = $subscription->SubValue('Language')) {
+                        $currentuser->{'LangHandle'} = RT::I18N->get_handle($lang);
+                    }
+
                     $self->SendDashboard(
                         %args,
                         CurrentUser  => $currentuser,
diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 3970324..6f803ed 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -342,7 +342,7 @@ $bad_time = $good_time - 86400; # day before (i.e. different month)
 
 produces_dashboard_mail_ok(
     Time       => $good_time,
-    Subject    => "[example.com] a Monthly b Testing! c\n",
+    Subject    => "[example.com] a Mensuel b Testing! c\n",
     BodyLike   => qr/Mes tableaux de bord/,
     BodyUnlike => qr/My dashboards/,
 );

commit 01ec29904b891bbaf5617921a1ce784cab40f6a4
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Mon Dec 28 01:25:53 2015 +0000

    Add config for EmailDashboardLanguage

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 35ac0a2..beb14bd 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -760,6 +760,17 @@ mailed dashboards.
 
 Set(@EmailDashboardRemove, ());
 
+=item C<$EmailDashboardLanguage>
+
+Lets you set the default language for dashboard emails. Individual
+subscriptions can override this value by explicitly selecting a language on the
+dashboard subscribe page. If this config has no value (the default), then each
+recipient's configured language will be used.
+
+=cut
+
+# Set($EmailDashboardLanguage, "fr");
+
 =back
 
 
diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index ef60906..3abf47d 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -128,13 +128,24 @@ sub MailDashboards {
                 }
             }
 
+            my $lang;
+            if ($lang = $subscription->SubValue('Language')) {
+                $RT::Logger->debug("Using subscription's preferred language $lang");
+            }
+            elsif ($lang = RT->Config->Get('EmailDashboardLanguage')) {
+                $RT::Logger->debug("Using RT's preferred language $lang");
+            }
+            else {
+                $RT::Logger->debug("Using each user's preferred language");
+            }
+
             my $email_success = 0;
             for my $email (uniq @emails) {
                 eval {
                     my $currentuser = RT::CurrentUser->new;
                     $currentuser->LoadByEmail($email);
 
-                    if (my $lang = $subscription->SubValue('Language')) {
+                    if ($lang) {
                         $currentuser->{'LangHandle'} = RT::I18N->get_handle($lang);
                     }
 
@@ -377,6 +388,8 @@ sub EmailDashboard {
         $currentuser->loc($frequency_display),
         $dashboard->Name;
 
+    $RT::Logger->debug("Localized subject: $subject");
+
     my $entity = $self->BuildEmail(
         %args,
         To      => $email,
diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 6f803ed..6bdb6e1 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -325,6 +325,7 @@ RT::Test->clean_caught_mails;
 RT::Test->stop_server;
 
 RT->Config->Set('EmailDashboardRemove' => ());
+RT->Config->Set('EmailDashboardLanguage' => 'fr');
 RT->Config->Set('DashboardAddress' => 'root');
 ($baseurl, $m) = RT::Test->started_ok;
 $m->login;
@@ -332,7 +333,47 @@ create_dashboard($baseurl, $m);
 create_subscription($baseurl, $m,
     Frequency => 'monthly',
     Hour => '06:00',
-    Language => 'fr',
+);
+
+($dashboard_id, $subscription_id) = get_dash_sub_ids();
+
+$good_time = 1291201200;        # dec 1
+
+produces_dashboard_mail_ok(
+    Time       => $good_time,
+    Subject    => "[example.com] a Mensuel b Testing! c\n",
+    BodyLike   => qr/Mes tableaux de bord/,
+    BodyUnlike => qr/My dashboards/,
+);
+
+
+
+ at mails = RT::Test->fetch_caught_mails;
+is(@mails, 0, "no mail leftover");
+
+$m->no_warnings_ok;
+RT::Test->stop_server;
+RT->Config->Set('DashboardSubject' => 'a %s b %s c');
+RT->Config->Set('DashboardAddress' => 'dashboard at example.com');
+RT->Config->Set('EmailDashboardRemove' => (qr/My dashboards/, "Testing!"));
+($baseurl, $m) = RT::Test->started_ok;
+
+delete_dashboard($dashboard_id);
+
+RT::Test->clean_caught_mails;
+
+RT::Test->stop_server;
+
+RT->Config->Set('EmailDashboardRemove' => ());
+RT->Config->Set('EmailDashboardLanguage' => 'ja');
+RT->Config->Set('DashboardAddress' => 'root');
+($baseurl, $m) = RT::Test->started_ok;
+$m->login;
+create_dashboard($baseurl, $m);
+create_subscription($baseurl, $m,
+    Frequency => 'monthly',
+    Hour => '06:00',
+    Language => 'fr', # overrides EmailDashboardLanguage
 );
 
 ($dashboard_id, $subscription_id) = get_dash_sub_ids();

-----------------------------------------------------------------------


More information about the rt-commit mailing list