[Rt-commit] rt branch 5.0/add-selecteduser-portlet created. rt-5.0.4-66-g94e864fa12

BPS Git Server git at git.bestpractical.com
Wed Jul 26 21:16:14 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/add-selecteduser-portlet has been created
        at  94e864fa12e3aaab23ce91bc82d3f4116de55aa2 (commit)

- Log -----------------------------------------------------------------
commit 94e864fa12e3aaab23ce91bc82d3f4116de55aa2
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Jul 20 09:49:00 2023 -0400

    Document the new __SelectedUser__ search placeholder

diff --git a/docs/query_builder.pod b/docs/query_builder.pod
index 2c49545a24..b0ce1c4678 100644
--- a/docs/query_builder.pod
+++ b/docs/query_builder.pod
@@ -13,7 +13,7 @@ L<Dashboard and Reports|docs/dashboards_reporting.pod> document.
 
 =head1 Basic Ticket Searches
 
-Let's look for tickets in the "RT" queue (RT's bugtracker for itself) that have
+Let's look for tickets in the "RT" queue (RT's bug tracker for itself) that have
 been resolved in the last year. (These examples assume it's currently mid June,
 2015). To do that, we specify the search criteria (Queue is RT, Status is
 resolved, and Resolved after 2014-06-15) in the upper left hand section of the
@@ -262,7 +262,7 @@ directly into the Advanced search box.
 Once you add a queue to your search using one of the options above, you'll see
 any custom fields applied to those queues at the bottom of the list of values in
 the Add Criteria section. To search for all tickets with a custom field that
-has some value, pick the comparision ("matches", "is", etc.), add a value,
+has some value, pick the comparison ("matches", "is", etc.), add a value,
 and click "Add these terms" to build the search.
 
 If you have a custom field named "Transport Type", for example, that has
@@ -388,7 +388,7 @@ changes made to a ticket through its life. Each of the entries displayed in the
 ticket history at the bottom of the ticket display page is a transaction.
 
 In some cases, RT users looking for a particular reply on a ticket will
-search in their email client rather than in RT because they will remenber
+search in their email client rather than in RT because they will remember
 getting the email with the information they need. On a busy ticket, it
 can be a challenge to find the reply from Jane some time this week. The
 Transaction Query Builder now makes that sort of search easy.
@@ -433,6 +433,49 @@ you can type the following query directly in the Query box:
 and then click "Apply" to let RT validate it. RT will display any syntax errors
 if you make any mistakes so you can fix them.
 
+=head2 Dynamic Search Values (Placeholders)
+
+RT supports some dynamic search values, or placeholders, that change based on
+some condition in RT. One placeholder is "__CurrentUser__", which is replaced
+by the id of the currently logged in user when the search is run. For example,
+you could create a search like this:
+
+    Owner = '__CurrentUser__' AND Status = '__Active__'
+
+You can then put this on a shared dashboard and each logged-in user will see
+a listing of tickets they own, without having to create a separate saved
+search for each user. Note in the example above we also use the "__Active__"
+placeholder, which automatically finds all active statuses for a given
+lifecycle. If you look at the default RT homepage, you'll see the search
+"10 highest priority tickets I own" is created with exactly this
+search.
+
+If you need the username of the current user rather than the id, you
+can use "__CurrentUserName__".
+
+The value "__SelectedUser__" is similar and it defaults to the current
+user if run with a search by itself. However, if you create a dashboard,
+add the component "SavedSearchSelectUser", and also add your saved search,
+you can select a different user with the user search box on the page.
+Once you select a new user, all searches on that dashboard will have
+"__SelectedUser__" replaced by the user you selected. This makes it
+easy to see tickets for other people, which can be useful for a project
+manager or help desk supervisor to check on their team's tickets.
+
+The default "Bookmarked Tickets" uses another placeholder, in this
+case as a value for "id":
+
+    id = '__Bookmarked__'
+
+That finds all tickets bookmarked by the current user. Bookmarks are
+added using the bookmark icon in the menu on each ticket.
+
+These search terms can be used with additional search terms like any
+other search. So you could create a new saved search to show only your
+new or open bookmarked tickets like this:
+
+    id = '__Bookmarked__' AND ( Status = "new" OR Status = "open" )
+
 =head2 Valid Search Values
 
 In the above example, search values like C<'resolved'>, C<'2019-04-01'>,

commit fb72ab5440550f86bb7f2b48162071c521e40431
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Jul 20 08:59:59 2023 -0400

    Add a __SelectedUser__ search placeholder and portlet to set it
    
    The new SavedSearchSelectUser portlet can be placed on a dashboard
    and any searches on that dashboard with a __SelectedUser__
    placeholder will get the value of the user submitted via the
    user search box.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index adcd78594c..df9e7e7bd5 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2283,7 +2283,7 @@ user's customized homepage ("RT at a glance").
 Set(
     $HomepageComponents,
     [
-        qw(QuickCreate QueueList QueueListAllStatuses MyAdminQueues MySupportQueues MyReminders RefreshHomepage Dashboards SavedSearches FindUser MyAssets FindAsset FindGroup) # loc_qw
+        qw(QuickCreate QueueList QueueListAllStatuses MyAdminQueues MySupportQueues MyReminders RefreshHomepage Dashboards SavedSearches FindUser MyAssets FindAsset FindGroup SavedSearchSelectUser) # loc_qw
     ]
 );
 
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index fbaa2d602a..25fa290293 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -3402,6 +3402,15 @@ sub _parser {
             # replace __CurrentUserName__ with the username
             $value = $self->CurrentUser->Name if $value eq '__CurrentUserName__';
 
+            # Replace __SelectedUser__ with noted SavedSearchSelectedUser, if available
+            # Default to CurrentUser if not
+            if ( $value eq '__SelectedUser__' ) {
+                $value = $HTML::Mason::Commands::m->notes->{SavedSearchSelectedUserId} || $self->CurrentUser->Id;
+            }
+            elsif ( $value eq '__SelectedUserName__' ) {
+                $value = $HTML::Mason::Commands::m->notes->{SavedSearchSelectedUserName} || $self->CurrentUser->Name;
+            }
+
             my $sub = $dispatch{ $class }
                 or die "No dispatch method for class '$class'";
 
diff --git a/share/html/Dashboards/Render.html b/share/html/Dashboards/Render.html
index 89f3ec9215..76f2b72dc0 100644
--- a/share/html/Dashboards/Render.html
+++ b/share/html/Dashboards/Render.html
@@ -126,6 +126,21 @@ $m->callback(ARGSRef => \%ARGS,
              CallbackName => 'Initial',
              skip_create => \$skip_create);
 
+# Add selected user to notes if it was submitted
+my $SavedSearchSelectedUserName;
+if ( $SavedSearchSelectedUserName = $m->request_args->{'SavedSearchSelectedUserName'} ) {
+    my $user = RT::User->new( $session{CurrentUser} );
+    my ($ret, $msg) = $user->Load($SavedSearchSelectedUserName);
+
+    if ( $ret and $user->Id ) {
+        $m->notes->{SavedSearchSelectedUserName} = $user->Name;
+        $m->notes->{SavedSearchSelectedUserId} = $user->Id;
+    }
+    else {
+        RT->Logger->error("Unable to load user in dashboard for SelectedUserName " . $SavedSearchSelectedUserName . " : $msg");
+    }
+}
+
 my $class = $self_service_dashboard ? 'RT::Dashboard::SelfService' : 'RT::Dashboard';
 RT::StaticUtil::RequireModule($class);
 my $Dashboard = $class->new($session{'CurrentUser'});
diff --git a/share/html/Elements/SavedSearchSelectUser b/share/html/Elements/SavedSearchSelectUser
new file mode 100644
index 0000000000..80a1bac266
--- /dev/null
+++ b/share/html/Elements/SavedSearchSelectUser
@@ -0,0 +1,75 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2023 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 }}}
+
+<&|/Widgets/TitleBox, title => loc('Select User')&>
+<form method="get" action="<% RT->Config->Get('WebPath') . $m->request_path %>" class="mx-auto max-width-sm">
+<div class="form-row text-center">
+  <div class="col-12">
+    <p><&|/l&>Find a user and submit to set the __SelectedUser__ placeholder in saved searches.</&></p>
+  </div>
+</div>
+<div class="form-row justify-content-center">
+  <div class="col-auto label">
+    <&|/l&>Find user</&>:
+  </div>
+  <div class="col-auto value">
+    <input class="form-control" type="text" name="SavedSearchSelectedUserName" value="" data-autocomplete="Users" data-autocomplete-return="Name" data-autocomplete-privileged=1 id="autocomplete-User" />
+  </div>
+  <div class="col-auto">
+    <& /Elements/Submit,  Label => loc('Submit') &>
+  </div>
+</div>
+</form>
+% if ( $m->notes->{SavedSearchSelectedUserName} ) {
+<div class="form-row text-center">
+  <div class="col-12">
+    <p><&|/l&>Setting __SelectedUser__ to</&> <% $m->notes->{SavedSearchSelectedUserName} %></p>
+  </div>
+</div>
+% }
+</&>

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list