[Rt-commit] rt branch, 5.0-trunk, updated. rt-5.0.0-32-gc1c3de69ee
? sunnavy
sunnavy at bestpractical.com
Mon Oct 5 18:24:51 EDT 2020
The branch, 5.0-trunk has been updated
via c1c3de69ee8ab67194c601a2d89bcce0be411e9c (commit)
via 47c40241e33c13fcfd508cb76ec0c54d43833ad3 (commit)
from 0a8b1ee8ad02e2a1d0b21ed822b5f0af76adf58b (commit)
Summary of changes:
etc/RT_Config.pm.in | 26 +++++++
lib/RT/Attribute.pm | 2 +-
lib/RT/Config.pm | 3 +
.../OpenOnStarted.pm => Dashboard/SelfService.pm} | 53 +++++++++-----
lib/RT/Interface/Web.pm | 3 +-
lib/RT/Interface/Web/MenuBuilder.pm | 35 ++++++++-
.../Global/SelfServiceHomePage.html} | 85 ++++++++++------------
.../html/Dashboards/Elements/ShowPortlet/component | 9 ++-
share/html/Dashboards/Queries.html | 48 ++++++++++--
share/html/Dashboards/Render.html | 19 ++++-
share/html/SelfService/{index.html => Open.html} | 2 +-
share/html/SelfService/index.html | 44 ++++++-----
12 files changed, 230 insertions(+), 99 deletions(-)
copy lib/RT/{Action/OpenOnStarted.pm => Dashboard/SelfService.pm} (70%)
copy share/html/{Asset/ModifyDates.html => Admin/Global/SelfServiceHomePage.html} (57%)
copy share/html/SelfService/{index.html => Open.html} (98%)
- Log -----------------------------------------------------------------
commit 47c40241e33c13fcfd508cb76ec0c54d43833ad3
Author: Dianne Skoll <dianne at bestpractical.com>
Date: Fri Oct 2 11:06:15 2020 -0400
Add ability to serve a custom dashboard as the SelfService home page.
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index a7301b3436..1e573155dc 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2948,6 +2948,32 @@ on self service pages.
Set($SelfServiceShowGroupTickets, 0);
+=item C<$SelfServiceUseDashboard>
+
+C<$SelfServiceUseDashboard> is a flag indicating whether or not to use
+a dashboard for the Self Service home page. If it is set to false,
+then the normal Open Tickets / Closed Tickets menu is shown rather
+than a dashboard.
+
+=cut
+
+Set($SelfServiceUseDashboard, 0);
+
+=item C<$SelfServicePageComponents>
+
+C<$SelfServicePageComponents> is an arrayref of allowed components on
+the SelfService page, if you have set $SelfServiceUseDashboard to true.
+If this is not set at all, then $HomepageComponents is used instead.
+
+=cut
+
+Set(
+ $SelfServicePageComponents,
+ [
+ qw(QuickCreate QueueList MyAdminQueues MySupportQueues MyReminders RefreshHomepage Dashboards SavedSearches FindUser MyAssets FindAsset FindGroup) # loc_qw
+ ]
+);
+
=back
=head2 Articles
diff --git a/lib/RT/Attribute.pm b/lib/RT/Attribute.pm
index 7b609aa363..ac03f87b6b 100644
--- a/lib/RT/Attribute.pm
+++ b/lib/RT/Attribute.pm
@@ -672,7 +672,7 @@ sub FindDependencies {
}
}
# dashboards have dependencies on all the searches and dashboards they use
- elsif ($self->Name eq 'Dashboard') {
+ elsif ($self->Name eq 'Dashboard' || $self->Name eq 'SelfServiceDashboard') {
my $content = $self->Content;
for my $pane (values %{ $content->{Panes} || {} }) {
for my $component (@$pane) {
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 400dd5ac22..59ce078f1c 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1591,6 +1591,9 @@ our %META;
SearchResultsAutoRedirect => {
Widget => '/Widgets/Form/Boolean',
},
+ SelfServiceUseDashboard => {
+ Widget => '/Widgets/Form/Boolean',
+ },
ShowBccHeader => {
Widget => '/Widgets/Form/Boolean',
},
diff --git a/lib/RT/Dashboard/SelfService.pm b/lib/RT/Dashboard/SelfService.pm
new file mode 100644
index 0000000000..3aa677d0e8
--- /dev/null
+++ b/lib/RT/Dashboard/SelfService.pm
@@ -0,0 +1,104 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2020 Best Practical Solutions, LLC
+# <sales at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+=head1 NAME
+
+ RT::Dashboard::SelfService - dashboard for the Self-Service Home Page
+
+=head1 SYNOPSIS
+
+ See RT::Dashboard
+
+=cut
+
+package RT::Dashboard::SelfService;
+
+use strict;
+use warnings;
+
+use base qw/RT::Dashboard/;
+
+=head2 ObjectName
+
+An object of this class is called "selfservicedashboard"
+
+=cut
+
+sub ObjectName { "selfservicedashboard" } # loc
+
+=head2 PostLoadValidate
+
+Ensure that the ID corresponds to an actual dashboard object, since it's all
+attributes under the hood.
+
+=cut
+
+sub PostLoadValidate {
+ my $self = shift;
+ return (0, "Invalid object type") unless $self->{'Attribute'}->Name eq 'SelfServiceDashboard';
+ return 1;
+}
+
+sub SaveAttribute {
+ my $self = shift;
+ my $object = shift;
+ my $args = shift;
+
+ return $object->AddAttribute(
+ 'Name' => 'SelfServiceDashboard',
+ 'Description' => $args->{'Name'},
+ 'Content' => {Panes => $args->{'Panes'}},
+ );
+}
+
+# All users can use SelfServiceDashboard
+sub CurrentUserCanSee { return 1 }
+
+RT::Base->_ImportOverlays();
+
+1;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index ce7c78f679..de32934bbb 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -4718,7 +4718,8 @@ sub UpdateDashboard {
return ( $ok, $msg ) = $user->SetPreferences( 'HomepageSettings', $data->{panes} );
}
} else {
- my $Dashboard = RT::Dashboard->new( $session{'CurrentUser'} );
+ my $class = $args->{self_service_dashboard} ? 'RT::Dashboard::SelfService' : 'RT::Dashboard';
+ my $Dashboard = $class->new( $session{'CurrentUser'} );
( $ok, $msg ) = $Dashboard->LoadById($id);
# report error at the bottom
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 17eac59cb7..1d63dc177d 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -1229,6 +1229,19 @@ sub _BuildAdminMenu {
description => loc('Modify the default "RT at a glance" view'),
path => '/Admin/Global/MyRT.html',
);
+
+ if (RT->Config->Get('SelfServiceUseDashboard')) {
+ if ($current_user->HasRight( Right => 'ModifyDashboard', Object => RT->System ) ) {
+ my $self_service = $admin_global->child( selfservice_home =>
+ title => loc('Self-Service Home Page'),
+ description => loc('Edit self-service home page dashboard'),
+ path => '/Admin/Global/SelfServiceHomePage.html');
+ if ( $request_path =~ m{^/Admin/Global/SelfServiceHomePage} ) {
+ $page->child(content => title => loc('Content'), path => '/Admin/Global/SelfServiceHomePage.html');
+ $page->child(show => title => loc('Show'), path => '/SelfService');
+ }
+ }
+ }
$admin_global->child( 'dashboards-in-menu' =>
title => loc('Modify Reports menu'),
description => loc('Customize dashboards in menu'),
@@ -1581,6 +1594,19 @@ sub BuildSelfServiceNav {
my $current_user = $HTML::Mason::Commands::session{CurrentUser};
+ if ( RT->Config->Get('SelfServiceUseDashboard')
+ && $request_path =~ m{^/SelfService/(?:index\.html)?$}
+ && $current_user->HasRight(
+ Right => 'ShowConfigTab',
+ Object => RT->System
+ )
+ && $current_user->HasRight( Right => 'ModifyDashboard', Object => RT->System )
+ )
+ {
+ $page->child( content => title => loc('Content'), path => '/Admin/Global/SelfServiceHomePage.html' );
+ $page->child( show => title => loc('Show'), path => '/SelfService/' );
+ }
+
my $queues = RT::Queues->new( $current_user );
$queues->UnLimit;
@@ -1600,8 +1626,13 @@ sub BuildSelfServiceNav {
} elsif ( $queue_id ) {
$top->child( new => title => loc('New ticket'), path => '/SelfService/Create.html?Queue=' . $queue_id );
}
- my $tickets = $top->child( tickets => title => loc('Tickets'), path => '/SelfService/' );
- $tickets->child( open => title => loc('Open tickets'), path => '/SelfService/' );
+
+ my $menu_label = loc('Tickets');
+ if (RT->Config->Get('SelfServiceUseDashboard')) {
+ $menu_label = loc('Self-Service');
+ }
+ my $tickets = $top->child( tickets => title => $menu_label, path => '/SelfService/' );
+ $tickets->child( open => title => loc('Open tickets'), path => '/SelfService/Open.html' );
$tickets->child( closed => title => loc('Closed tickets'), path => '/SelfService/Closed.html' );
$top->child( "assets", title => loc("Assets"), path => "/SelfService/Asset/" )
diff --git a/share/html/SelfService/index.html b/share/html/Admin/Global/SelfServiceHomePage.html
similarity index 55%
copy from share/html/SelfService/index.html
copy to share/html/Admin/Global/SelfServiceHomePage.html
index 78d6b95a7b..3969dd4280 100644
--- a/share/html/SelfService/index.html
+++ b/share/html/Admin/Global/SelfServiceHomePage.html
@@ -45,30 +45,51 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<& /SelfService/Elements/Header, Title => loc('Open tickets') &>
+%#<& /Elements/Header, Title => $title &>
+%#<& /Elements/Tabs &>
+%#<& /Elements/ListActions, actions => \@results &>
-% $m->callback(CallbackName => 'BeforeMyRequests', ARGSRef => \%ARGS, Page => $Page);
+<%INIT>
+# If custom self-service page disabled, redirect to /Admin/Global
+if (!RT->Config->Get('SelfServiceUseDashboard')) {
+ RT::Interface::Web::Redirect(RT->Config->Get('WebURL') . 'Admin/Global');
+}
-<& /SelfService/Elements/MyRequests,
- %ARGS,
- status => '__Active__',
- title => loc('My open tickets'),
- BaseURL => RT->Config->Get('WebPath') ."/SelfService/?",
- Page => $Page,
-&>
+my $title = loc('Self-Service Home Page');
+my @results;
-% $m->callback(CallbackName => 'AfterMyRequests', ARGSRef => \%ARGS, Page => $Page);
+use RT::Dashboard::SelfService;
+my $Dashboard = RT::Dashboard::SelfService->new($session{'CurrentUser'});
-<& /SelfService/Elements/MyGroupRequests,
- %ARGS,
- status => '__Active__',
- title => loc('My group\'s tickets'),
- BaseURL => RT->Config->Get('WebPath') ."/SelfService/?",
- Page => $Page,
-&>
+my $dashboard_id;
-% $m->callback(CallbackName => 'AfterMyGroupRequests', ARGSRef => \%ARGS, Page => $Page);
+# The Self-Service Home Page dashboard is special; its attribute is
+# named "selfservicedashboard" instead of "dashboard". We just
+# need to get an ID to reuse the rest of the dashboard code.
+my $attr = RT::Attribute->new(RT->SystemUser);
+my ($ok, $msg) = $attr->LoadByNameAndObject(Object => $RT::System,
+ Name => 'SelfServiceDashboard');
+if (!$ok) {
+ my $blank_dashboard = {
+ Panes => {
+ body => [],
+ sidebar => [],
+ }
+ };
+ # Doesn't exist... try creating an empty one
+ ($ok, $msg) = $Dashboard->Save(
+ Privacy => $RT::System,
+ Description => 'Self-Service Home Page Dashboard',
+ Object => $RT::System,
+ Content => $blank_dashboard);
+ unless ($ok) {
+ RT::Logger->error("Unable to create self-service home page dashboard: $msg");
+ Abort(loc("Could not create self-service home page dashboard"));
+ }
+ $dashboard_id = $Dashboard->id;
+} else {
+ $dashboard_id = $attr->Id;
+}
+$m->comp('/Dashboards/Queries.html', id => $dashboard_id, self_service_dashboard => 1, %ARGS);
-<%ARGS>
-$Page => 1
-</%ARGS>
+</%INIT>
diff --git a/share/html/Dashboards/Elements/ShowPortlet/component b/share/html/Dashboards/Elements/ShowPortlet/component
index cead432fb2..8fb3526a54 100644
--- a/share/html/Dashboards/Elements/ShowPortlet/component
+++ b/share/html/Dashboards/Elements/ShowPortlet/component
@@ -56,7 +56,14 @@ $HasResults
my $full_path = $Portlet->{path};
(my $path = $full_path) =~ s{^/Elements/}{};
-my $allowed = grep { $_ eq $path } @{RT->Config->Get('HomepageComponents')};
+my $allowed;
+
+if ($m->request_path =~ m{/SelfService/}) {
+ $allowed = grep { $_ eq $path } @{RT->Config->Get('SelfServicePageComponents') || RT->Config->Get('HomepageComponents')};
+} else {
+ $allowed = grep { $_ eq $path } @{RT->Config->Get('HomepageComponents')};
+}
+
</%init>
% if (!$allowed) {
% $m->out( $m->interp->apply_escapes( loc("Invalid portlet [_1]", $path), "h" ) );
diff --git a/share/html/Dashboards/Queries.html b/share/html/Dashboards/Queries.html
index 379e7b1976..25bf19a03d 100644
--- a/share/html/Dashboards/Queries.html
+++ b/share/html/Dashboards/Queries.html
@@ -61,19 +61,38 @@
<%INIT>
my @results;
-use RT::Dashboard;
-my $Dashboard = RT::Dashboard->new($session{'CurrentUser'});
+# Don't permit someone to supply "self_service_dashboard=1" on the URL line
+if ($m->request_path ne '/Admin/Global/SelfServiceHomePage.html') {
+ $self_service_dashboard = 0;
+}
+
+my $class = $self_service_dashboard ? 'RT::Dashboard::SelfService' : 'RT::Dashboard';
+$class->require;
+my $Dashboard = $class->new($session{'CurrentUser'});
my ($ok, $msg) = $Dashboard->LoadById($id);
unless ($ok) {
RT::Logger->error("Unable to load dashboard with $id: $msg");
Abort(loc("Could not load dashboard [_1]", $id), Code => HTTP::Status::HTTP_NOT_FOUND);
}
-my $title = loc("Modify the content of dashboard [_1]", $Dashboard->Name);
+
+my $title;
+
+if ($self_service_dashboard) {
+ $title = loc("Modify the self-service home page");
+} else {
+ $title = loc("Modify the content of dashboard [_1]", $Dashboard->Name);
+}
my @sections;
my %item_for;
-my @components = map { type => "component", name => $_, label => loc($_) }, @{RT->Config->Get('HomepageComponents')};
+my @components;
+
+if ($self_service_dashboard) {
+ @components = map { type => "component", name => $_, label => loc($_) }, @{RT->Config->Get('SelfServicePageComponents') || RT->Config->Get('HomepageComponents')};
+} else {
+ @components = map { type => "component", name => $_, label => loc($_) }, @{RT->Config->Get('HomepageComponents')};
+}
$item_for{ $_->{type} }{ $_->{name} } = $_ for @components;
@@ -214,17 +233,32 @@ $m->callback(
if ( $ARGS{UpdateSearches} ) {
$ARGS{dashboard_id} = $id;
+ $ARGS{self_service_dashboard} = $self_service_dashboard;
my ($ok, $msg) = UpdateDashboard( \%ARGS, \%item_for );
- push @results, $ok ? loc('Dashboard updated') : $msg;
+ if ($self_service_dashboard) {
+ push @results, $ok ? loc('Self-Service home page updated') : $msg;
+ } else {
+ push @results, $ok ? loc('Dashboard updated') : $msg;
+ }
+ my $path;
+ my $args;
+ if ($self_service_dashboard) {
+ $path = '/Admin/Global/SelfServiceHomePage.html';
+ $args = { };
+ } else {
+ $path = '/Dashboards/Queries.html';
+ $args = { id => $id };
+ }
MaybeRedirectForResults(
Actions => \@results,
- Path => "/Dashboards/Queries.html",
- Arguments => { id => $id },
+ Path => $path,
+ Arguments => $args,
);
}
</%INIT>
<%ARGS>
$id => '' unless defined $id
+$self_service_dashboard => 0
</%ARGS>
diff --git a/share/html/Dashboards/Render.html b/share/html/Dashboards/Render.html
index 18aaec7572..4fb081cb09 100644
--- a/share/html/Dashboards/Render.html
+++ b/share/html/Dashboards/Render.html
@@ -110,13 +110,20 @@
my @results;
my $skip_create = 0;
+# Don't permit someone to supply "self_service_dashboard=1" directly
+# on the URL line
+if ($m->request_path !~ m{^/SelfService/}) {
+ $self_service_dashboard = 0;
+}
+
$m->callback(ARGSRef => \%ARGS,
results => \@results,
CallbackName => 'Initial',
skip_create => \$skip_create);
-use RT::Dashboard;
-my $Dashboard = RT::Dashboard->new($session{'CurrentUser'});
+my $class = $self_service_dashboard ? 'RT::Dashboard::SelfService' : 'RT::Dashboard';
+$class->require;
+my $Dashboard = $class->new($session{'CurrentUser'});
my ($ok, $msg) = $Dashboard->LoadById($id);
unless ($ok) {
RT::Logger->error("Unable to load dashboard with $id: $msg");
@@ -146,7 +153,12 @@ unless (defined($rows)) {
$rows = defined($prefs->{'RowsPerPage'}) ? $prefs->{'RowsPerPage'} : 50;
}
-my $title = loc '[_1] Dashboard', $Dashboard->Name;
+my $title;
+if ($self_service_dashboard) {
+ $title = loc('Self-Service Dashboard');
+} else {
+ $title = loc('[_1] Dashboard', $Dashboard->Name);
+}
my $show_cb = sub {
my $pane = shift;
@@ -171,5 +183,6 @@ my $Refresh = $Preview
$id => undef
$Preview => 1
$HasResults => undef
+$self_service_dashboard => 0
</%ARGS>
diff --git a/share/html/SelfService/index.html b/share/html/SelfService/Open.html
similarity index 98%
copy from share/html/SelfService/index.html
copy to share/html/SelfService/Open.html
index 78d6b95a7b..83e9f768a5 100644
--- a/share/html/SelfService/index.html
+++ b/share/html/SelfService/Open.html
@@ -46,7 +46,7 @@
%#
%# END BPS TAGGED BLOCK }}}
<& /SelfService/Elements/Header, Title => loc('Open tickets') &>
-
+<& /Elements/PageLayout, show_menu => 0 &>
% $m->callback(CallbackName => 'BeforeMyRequests', ARGSRef => \%ARGS, Page => $Page);
<& /SelfService/Elements/MyRequests,
diff --git a/share/html/SelfService/index.html b/share/html/SelfService/index.html
index 78d6b95a7b..0ddf61c486 100644
--- a/share/html/SelfService/index.html
+++ b/share/html/SelfService/index.html
@@ -45,30 +45,34 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<& /SelfService/Elements/Header, Title => loc('Open tickets') &>
+<%INIT>
+use RT::Dashboard::SelfService;
+if (RT->Config->Get('SelfServiceUseDashboard')) {
+ # Check if we have a self-service dashboard
+ my $Dashboard = RT::Dashboard::SelfService->new($session{'CurrentUser'});
-% $m->callback(CallbackName => 'BeforeMyRequests', ARGSRef => \%ARGS, Page => $Page);
+ my $dashboard_id;
-<& /SelfService/Elements/MyRequests,
- %ARGS,
- status => '__Active__',
- title => loc('My open tickets'),
- BaseURL => RT->Config->Get('WebPath') ."/SelfService/?",
- Page => $Page,
-&>
+ # The Self-Service Home Page dashboard is special; its attribute is
+ # named "selfservicedashboard" instead of "dashboard". We just
+ # need to get an ID to reuse the rest of the dashboard code.
+ my $attr = RT::Attribute->new(RT->SystemUser);
+ my ($ok, $msg) = $attr->LoadByNameAndObject(Object => $RT::System,
+ Name => 'SelfServiceDashboard');
+ if ($ok && $attr->Id) {
+ # Try to load the dashboard
+ my ($ok, $msg) = $Dashboard->LoadById($attr->Id);
+ if ($ok) {
+ $m->comp('/Dashboards/Render.html', id => $attr->Id, self_service_dashboard => 1);
+ return;
+ }
+ }
+}
-% $m->callback(CallbackName => 'AfterMyRequests', ARGSRef => \%ARGS, Page => $Page);
-
-<& /SelfService/Elements/MyGroupRequests,
- %ARGS,
- status => '__Active__',
- title => loc('My group\'s tickets'),
- BaseURL => RT->Config->Get('WebPath') ."/SelfService/?",
- Page => $Page,
-&>
-
-% $m->callback(CallbackName => 'AfterMyGroupRequests', ARGSRef => \%ARGS, Page => $Page);
+# Default to old-style "My Open Tickets"
+$m->comp('/SelfService/Open.html', Page => $Page);
+</%INIT>
<%ARGS>
$Page => 1
</%ARGS>
commit c1c3de69ee8ab67194c601a2d89bcce0be411e9c
Merge: 0a8b1ee8ad 47c40241e3
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 6 06:14:41 2020 +0800
Merge branch '5.0/self-service-homepage-dashboard' into 5.0-trunk
-----------------------------------------------------------------------
More information about the rt-commit
mailing list