[Rt-commit] rt branch, 4.4/dashboard-user-context, created. rt-4.4.3-52-g178384e3b
? sunnavy
sunnavy at bestpractical.com
Tue Oct 2 18:02:21 EDT 2018
The branch, 4.4/dashboard-user-context has been created
at 178384e3b0f89038b795a80ee4436f222369a8ac (commit)
- Log -----------------------------------------------------------------
commit 178384e3b0f89038b795a80ee4436f222369a8ac
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Oct 3 03:47:59 2018 +0800
Support to generate different dashboard content for each recipient
Previously, for a dashboard subscription, we send the same content to
all the recipients in behalf of the subscriber. This commit adds a new
option to generate content in behalf of each recipient instead, which is
convenient if the the content has searches containing __CurrentUser__ in
the query.
diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index 20e206626..68cfc8a20 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -176,11 +176,26 @@ sub MailDashboards {
$lang = 'en';
}
+ my $context_user;
+ if ( ( $subscription->SubValue( 'Context' ) // '' ) eq 'recipient' ) {
+ $context_user = RT::CurrentUser->new( RT->SystemUser );
+ my ( $ret, $msg ) = $context_user->LoadByEmail( $email );
+ unless ( $ret ) {
+ RT->Logger->error( "Failed to load user with email $email: $msg" );
+ next;
+ }
+ $context_user->{'LangHandle'} = RT::I18N->get_handle($lang);
+ }
+ else {
+ $context_user = $currentuser;
+ }
+
$currentuser->{'LangHandle'} = RT::I18N->get_handle($lang);
$self->SendDashboard(
%args,
CurrentUser => $currentuser,
+ ContextUser => $context_user,
Email => $email,
Subscription => $subscription,
From => $from,
@@ -278,6 +293,7 @@ sub SendDashboard {
my $self = shift;
my %args = (
CurrentUser => undef,
+ ContextUser => undef,
Email => undef,
Subscription => undef,
DryRun => 0,
@@ -285,6 +301,7 @@ sub SendDashboard {
);
my $currentuser = $args{CurrentUser};
+ my $context_user = $args{ContextUser} || $currentuser;
my $subscription = $args{Subscription};
my $rows = $subscription->SubValue('Rows');
@@ -303,17 +320,18 @@ sub SendDashboard {
);
}
- $RT::Logger->debug('Generating dashboard "'.$dashboard->Name.'" for user "'.$currentuser->Name.'":');
+ $RT::Logger->debug('Generating dashboard "'.$dashboard->Name.'" for user "'.$context_user->Name.'":');
if ($args{DryRun}) {
print << "SUMMARY";
Dashboard: @{[ $dashboard->Name ]}
- User: @{[ $currentuser->Name ]} <$args{Email}>
+ User: @{[ $context_user->Name ]} <$args{Email}>
SUMMARY
return;
}
local $HTML::Mason::Commands::session{CurrentUser} = $currentuser;
+ local $HTML::Mason::Commands::session{ContextUser} = $context_user;
local $HTML::Mason::Commands::r = RT::Dashboard::FakeRequest->new;
my $HasResults = undef;
diff --git a/share/html/Dashboards/Elements/ShowPortlet/dashboard b/share/html/Dashboards/Elements/ShowPortlet/dashboard
index d0f3d74f1..fd7e0cefe 100644
--- a/share/html/Dashboards/Elements/ShowPortlet/dashboard
+++ b/share/html/Dashboards/Elements/ShowPortlet/dashboard
@@ -75,6 +75,7 @@ Abort("Possible recursive dashboard detected.") if $Depth > 8;
</%init>
<%perl>
+local $session{CurrentUser} = $session{ContextUser};
for my $portlet (@panes) {
$m->comp($portlet->{portlet_type},
Portlet => $portlet,
diff --git a/share/html/Dashboards/Render.html b/share/html/Dashboards/Render.html
index acaf6d6d6..8341199fc 100644
--- a/share/html/Dashboards/Render.html
+++ b/share/html/Dashboards/Render.html
@@ -91,6 +91,11 @@
% $m->callback(CallbackName => 'AfterTable', Dashboard => $Dashboard, show_cb => $show_cb);
% if (!$Preview) {
+
+% if ( $session{ContextUser}->id != $session{CurrentUser}->id ) {
+<p><&|/l, $Dashboard->Name, $session{CurrentUser}->Name &>This is generated from dashboard "[_1]" by the subscription of user "[_2]".</&></p>
+% }
+
% my $edit = RT->Config->Get('WebPath') . '/Dashboards/Modify.html?id='.$id;
% my $subscription = RT->Config->Get('WebPath') . '/Dashboards/Subscription.html?id='.$id;
<p><&|/l, $edit, $subscription &>You <a href="[_1]">may edit this dashboard</a> and <a href="[_2]">your subscription</a> to it in RT.</&></p>
@@ -136,10 +141,11 @@ for my $sub ($session{'CurrentUser'}->UserObj->Attributes->Named('Subscription')
last;
}
+$session{ContextUser} ||= $session{CurrentUser};
# otherwise honor their search preferences.. otherwise 50 rows
# $rows == 0 means unlimited, which we don't want to ignore from above
unless (defined($rows)) {
- my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
+ my $prefs = $session{'ContextUser'}->UserObj->Preferences("SearchDisplay") || {};
$rows = defined($prefs->{'RowsPerPage'}) ? $prefs->{'RowsPerPage'} : 50;
}
diff --git a/share/html/Dashboards/Subscription.html b/share/html/Dashboards/Subscription.html
index 0cb020c1a..7167c8058 100644
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@ -192,6 +192,25 @@
</table>
</&>
+<&| /Widgets/TitleBox, title => loc('Content Context') &>
+
+<p class="description">
+<&|/l&>For searches like "10 highest priority tickets I own" that contain __CurrentUser__ in the query, the results are various for differnet users. For dashboards containing such searches, you might want to generate different content for each recipient who is assumed to be __CurrentUser__ in the query. Tick "Each dashboard recipient" for cases like that.</&>
+</p>
+
+<table>
+ <tr><td class="label"><&|/l&>Run Dashboard Searches As</&>:</td>
+ <td>
+ <input type="radio" id="context-subscriber" name="Context" value="subscriber" <% $fields{'Context'} eq 'subscriber' ? 'checked="checked"' : "" |n %>></input>
+ <label for="context-subscriber"><&|/l&>Dashboard subscriber</&>(<% $session{CurrentUser}->Name %>)</label>
+ <br />
+ <input type="radio" id="context-recipient" name="Context" value="recipient" <% $fields{'Context'} eq 'recipient' ? 'checked="checked"' : "" |n %>></input>
+ <label for="context-recipient"><&|/l&>Each dashboard recipient</&></label>
+ </td>
+ </tr>
+</table>
+</&>
+
<&| /Widgets/TitleBox, title => loc('Recipients') &>
<& Elements/SubscriptionRecipients,
UserField => $UserField, UserString => $UserString, UserOp => $UserOp,
@@ -246,6 +265,7 @@ my %fields = (
Counter => 0,
Language => '',
SuppressIfEmpty => 0,
+ Context => 'subscriber',
);
$m->callback( %ARGS, CallbackName => 'SubscriptionFields', FieldsRef => \%fields,
-----------------------------------------------------------------------
More information about the rt-commit
mailing list