%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC %# %# %# (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 }}} <& /Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
<&| /Widgets/TitleBox, title => loc('Dashboard') &>
<&|/l&>Dashboard:
<% $Dashboard->Name %>
<&|/l&>Queries:
% my @portlets = grep { defined } $Dashboard->Portlets; % if (!@portlets) { (<&|/l&>none) % } else {
    % for my $portlet (@portlets) {
  1. <% loc( RT::SavedSearch->EscapeDescription($portlet->{description}), $fields{'Rows'}) %>
  2. % }
% }
<&| /Widgets/TitleBox, title => loc('Subscription') &>
<&|/l&>Frequency:
class="custom-control-input">
% for my $day ( qw/Monday Tuesday Wednesday Thursday Friday Saturday Sunday/ ) {
>
% }
class="custom-control-input">
<&|/l&>every
<&|/l&>weeks
class="custom-control-input">
class="custom-control-input">
<&|/l&>Hour:
(<%$timezone%>)
<&|/l&>Language:
<& /Elements/SelectLang, Name => 'Language', Default => $fields{'Language'}, ShowNullOption => 1, &>
<&|/l&>Rows:
>
% $m->callback( %ARGS, CallbackName => 'SubscriptionFormEnd', FieldsRef => \%fields, % SubscriptionObj => $SubscriptionObj, DashboardObj => $Dashboard ); <&| /Widgets/TitleBox, title => loc('Search Context') &>

<&|/l&>Most searches show the same results for all users and can be run as the user who owns the dashboard subscription (Subscription owner).

<&|/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".

<&|/l&>Run Dashboard Searches As:
>
>
<&| /Widgets/TitleBox, title => loc('Recipients') &> <& Elements/SubscriptionRecipients, UserField => $UserField, UserString => $UserString, UserOp => $UserOp, GroupString => $GroupString, GroupOp => $GroupOp, GroupField => $GroupField, Recipients => $fields{Recipients}, IsFirstSubscription => $SubscriptionObj ? 0 : 1 &>
% if ($SubscriptionObj) { <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &> % } else { <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &> % }
<%INIT> use List::MoreUtils 'uniq'; my ($title, @results); my $Loaded = 0; my $timezone = $session{'CurrentUser'}->UserObj->Timezone || RT->Config->Get('Timezone'); use RT::Dashboard; my $Dashboard = RT::Dashboard->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 $SubscriptionObj = $Dashboard->Subscription; $id = $SubscriptionObj ? $SubscriptionObj->SubValue('DashboardId') : $ARGS{'id'}; my %fields = ( DashboardId => $id, Frequency => 'daily', Monday => 1, Tuesday => 1, Wednesday => 1, Thursday => 1, Friday => 1, Saturday => 0, Sunday => 0, Hour => '06:00', Dow => 'Monday', Dom => 1, Rows => 20, Recipients => { Users => [], Groups => [] }, Fow => 1, Counter => 0, Language => '', SuppressIfEmpty => 0, Context => 'subscriber', ); $m->callback( %ARGS, CallbackName => 'SubscriptionFields', FieldsRef => \%fields, SubscriptionObj => $SubscriptionObj, DashboardObj => $Dashboard); # update any fields with the values from the subscription object if ($SubscriptionObj) { for my $field (keys %fields) { $fields{$field} = $SubscriptionObj->SubValue($field); } } # finally, update any fields with arguments passed in by the user for my $field (keys %fields) { next if $field eq 'DashboardId'; # but this one is immutable $fields{$field} = $ARGS{$field} if defined($ARGS{$field}) || $ARGS{$field.'-Magic'}; } $m->callback( %ARGS, CallbackName => 'MassageSubscriptionFields', FieldsRef => \%fields, SubscriptionObj => $SubscriptionObj, DashboardObj => $Dashboard); # this'll be defined on submit if (defined $ARGS{Save}) { # update recipients for my $key (keys %ARGS) { my $val = $ARGS{$key}; if ( $key =~ /^Dashboard-Subscription-Email-\d+$/ && $val ) { my @recipients = @{ $fields{Recipients}->{Users} }; for ( RT::EmailParser->ParseEmailAddress( $val ) ) { my $email = $_->address; my $user = RT::User->new(RT->SystemUser); ($ok, $msg) = $user->LoadOrCreateByEmail( EmailAddress => $email, Comments => 'Autocreated when added as a dashboard subscription recipient', ); unless ($ok) { push @results, loc("Could not add [_1] as a recipient: [_2]", $email, $msg); next; } my $is_prev_recipient = grep { $_ == $user->id } @recipients; next if $is_prev_recipient; push @recipients, $user->id; push @results, loc("[_1] added to dashboard subscription recipients", $email); } @{ $fields{Recipients}->{Users} } = uniq @recipients; } elsif ($key =~ /^Dashboard-Subscription-(Users|Groups)-(\d+)$/) { my ($mode, $type, $id) = ('', $1, $2); my @recipients = @{ $fields{Recipients}->{$type} }; # find out proper value for user/group checkbox my $add_keep_recipient = ref $ARGS{$key} eq 'ARRAY' ? grep { $_ } @{ $ARGS{$key} } : $ARGS{$key}; my $record; # hold user/group object if ($type eq 'Users') { my $user = RT::User->new($session{CurrentUser}); $user->Load( $id ); $record = $user; } elsif ($type eq 'Groups') { my $group = RT::Group->new($session{CurrentUser}); $group->Load( $id ); $record = $group; } my $is_prev_recipient = grep { $_ == $id } @recipients; if ($add_keep_recipient and not $is_prev_recipient) { # Add User/Group push @recipients, $id; push @results, loc("[_1] added to dashboard subscription recipients", $record->Name); } elsif (not $add_keep_recipient and $is_prev_recipient) { # Remove User/Group @recipients = grep { $_ != $id } @recipients; push @results, loc("[_1] removed from dashboard subscription recipients", $record->Name); } @{ $fields{Recipients}->{$type} } = uniq @recipients; } } # update if ($SubscriptionObj) { $id = delete $fields{'DashboardId'}; # immutable ($ok, $msg) = $SubscriptionObj->SetSubValues(%fields); $fields{'DashboardId'} = $id; $msg = loc("Subscription updated") if $ok; push @results, $msg; } # create else { Abort(loc("Unable to subscribe to dashboard [_1]: Permission Denied", $id)) unless $Dashboard->CurrentUserCanSubscribe; $SubscriptionObj = RT::Attribute->new($session{CurrentUser}); ($ok, $msg) = $SubscriptionObj->Create( Name => 'Subscription', Description => 'Subscription to dashboard ' . $id, ContentType => 'storable', Object => $session{'CurrentUser'}->UserObj, Content => \%fields, ); if ($ok) { push @results, loc("Subscribed to dashboard [_1]", $Dashboard->Name); } else { push @results, loc('Subscription could not be created: [_1]', $msg); } } push @results, loc("Warning: This dashboard has no recipients") unless @{ $fields{Recipients}->{Users} } || @{ $fields{Recipients}->{Groups} }; } elsif (defined $ARGS{OnlySearchForPeople}) { $GroupString = undef; $GroupField = undef; $GroupOp = undef; } elsif (defined $ARGS{OnlySearchForGroup}) { $UserString = undef; $UserField = undef; $UserOp = undef; } if ($SubscriptionObj) { $title = loc("Modify the subscription to dashboard [_1]", $Dashboard->Name); } else { $title = loc("Subscribe to dashboard [_1]", $Dashboard->Name); } <%ARGS> $id => undef $Frequency => undef $Hour => undef $Dow => undef $Dom => undef $Rows => undef $Recipient => undef $Language => undef $UserField => undef $UserOp => undef $UserString => undef $GroupField => undef $GroupOp => undef $GroupString => undef