[Rt-commit] rt branch, 4.4/dashboard-user-context, created. rt-4.4.3-61-gf10597b41
? sunnavy
sunnavy at bestpractical.com
Wed Oct 17 15:56:23 EDT 2018
The branch, 4.4/dashboard-user-context has been created
at f10597b4167a1e5a8e5a4ba2c28b27dd6ab70af6 (commit)
- Log -----------------------------------------------------------------
commit f10597b4167a1e5a8e5a4ba2c28b27dd6ab70af6
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 fb669745d..8a3c8f89b 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -172,11 +172,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,
@@ -274,6 +289,7 @@ sub SendDashboard {
my $self = shift;
my %args = (
CurrentUser => undef,
+ ContextUser => undef,
Email => undef,
Subscription => undef,
DryRun => 0,
@@ -281,6 +297,7 @@ sub SendDashboard {
);
my $currentuser = $args{CurrentUser};
+ my $context_user = $args{ContextUser} || $currentuser;
my $subscription = $args{Subscription};
my $rows = $subscription->SubValue('Rows');
@@ -299,7 +316,7 @@ 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";
@@ -311,6 +328,7 @@ SUMMARY
}
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..aec17869d 100644
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@ -192,6 +192,29 @@
</table>
</&>
+<&| /Widgets/TitleBox, title => loc('Search Context') &>
+
+<p class="description">
+<&|/l&>Most searches show the same results for all users and can be run as the user who owns the dashboard subscription (Subscription owner).</&>
+</p>
+
+<p class="description">
+<&|/l&>For searches like "10 highest priority tickets I own" that contain __CurrentUser__ in the query, the results are specific to each recipient. For dashboards with these searches, select "Each dashboard recipient" below to run each search with the recipient set as the "Current User".</&>
+</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'} // '') ne 'recipient' ? 'checked="checked"' : "" |n %>></input>
+ <label for="context-subscriber"><&|/l&>Subscription owner</&>(<% $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 +269,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