[Rt-commit] rt branch, 5.0-trunk, updated. rt-5.0.0-159-gfd89077092

Jim Brandt jbrandt at bestpractical.com
Fri Dec 18 16:26:49 EST 2020


The branch, 5.0-trunk has been updated
       via  fd89077092bcdfed3312c6015831b92b07e9b224 (commit)
       via  3662b73a3a5bcb15f3a0e49f984544b59a52f4ab (commit)
       via  c577f70e29c85a355ef612fecd729dfcf967acec (commit)
       via  06556b74d8d8efdc0e23ce45dee494073e100aab (commit)
       via  9887285f3cc8bfd158fbdbe4c7caa82124f01a9e (commit)
       via  b64c6548aacaf4228a004c0533b26abb79d27709 (commit)
       via  cf5e299975a55d9d65f165e58aa71c8a83b77024 (commit)
       via  c2d09d7b10ee9f2b739f8dfc1dc6a56f1a005e69 (commit)
      from  34492a705f832023bdc4c7524d0c60ddd9f9504c (commit)

Summary of changes:
 docs/UPGRADING-5.0                   | 12 +++++++++
 lib/RT/Interface/Web.pm              | 13 +++-------
 share/html/Admin/Global/MyRT.html    |  1 -
 share/html/Dashboards/Queries.html   | 30 ++++++----------------
 share/html/Elements/ShowSelectSearch |  4 +--
 share/html/Prefs/MyRT.html           |  1 -
 t/mail/dashboard-empty.t             |  2 +-
 t/web/custom_frontpage.t             | 45 +++++++++++++++++++++++++++++++++
 t/web/dashboards-basics.t            | 48 +++++++++++++++++++++++++++++++-----
 9 files changed, 113 insertions(+), 43 deletions(-)

- Log -----------------------------------------------------------------
commit c2d09d7b10ee9f2b739f8dfc1dc6a56f1a005e69
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 31 01:21:40 2020 +0800

    Fix system txn/asset/chart saved searches in dashboards
    
    Previously they were not handled correctly in the new UI. If you try to
    add them, we would get errors like:
    
        Unable to find search Saved Search: ...
    
    As system also supports various search types, it makes sense to add
    corresponding prefix there, just like user/group level
    ticket/txn/asset/chart searches.

diff --git a/share/html/Dashboards/Queries.html b/share/html/Dashboards/Queries.html
index 25bf19a03d..f1e8bff0cb 100644
--- a/share/html/Dashboards/Queries.html
+++ b/share/html/Dashboards/Queries.html
@@ -128,8 +128,8 @@ for my $object (@objs) {
         }
 
         my $item;
-        if ($object eq $sys && $SearchType eq 'Ticket') {
-            $item = { type => 'system', name => $desc, label => $loc_desc, search_id => $search->id };
+        if ($object eq $sys) {
+            $item = { type => 'system', name => $desc, label => $loc_desc, search_type => $SearchType, search_id => $search->id };
 
             # make system searches more easily accessible since dashboards
             # historically used a human-readable description rather than
diff --git a/share/html/Elements/ShowSelectSearch b/share/html/Elements/ShowSelectSearch
index 8317394e9f..a696e36b7f 100644
--- a/share/html/Elements/ShowSelectSearch
+++ b/share/html/Elements/ShowSelectSearch
@@ -66,8 +66,8 @@ $possibly_hidden => 0
 <%INIT>
 my $prefix;
 
-if ($type eq 'saved' || $type eq 'search') {
-    $prefix = loc(ucfirst($search_type || 'ticket'));
+if ($search_type) {
+    $prefix = loc(ucfirst($search_type));
 }
 elsif ($type eq 'dashboard') {
     $prefix = loc('Dashboard');

commit cf5e299975a55d9d65f165e58aa71c8a83b77024
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 31 03:08:40 2020 +0800

    No need to specially treat system-level saved searches for dashboards
    
    Unlike MyRT, system saved searches are stored with attribute ids in
    dashboard content from the beginning, so we can treat them like all the
    other saved searches consistently.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index faee16d5d7..86c94bd88a 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -4745,7 +4745,7 @@ sub UpdateDashboard {
                     $path = "/Elements/$path" if substr( $path, 0, 1 ) ne '/';
 
                     $saved{path} = $path;
-                } elsif ( $item->{type} eq 'system' || $item->{type} eq 'saved' ) {
+                } elsif ( $item->{type} eq 'saved' ) {
                     $saved{portlet_type} = 'search';
 
                     $item->{searchType} = $available_items->{ $item->{type} }{ $item->{name} }{search_type}
@@ -4758,14 +4758,9 @@ sub UpdateDashboard {
                     $item->{searchId} = $available_items->{ $item->{type} }{ $item->{name} }{search_id}
                                         if exists $available_items->{ $item->{type} }{ $item->{name} }{search_id};
 
-                    if ( $item->{type} eq 'system' ) {
-                        $saved{privacy} = 'RT::System-1';
-                        $saved{id}      = $item->{searchId};
-                    } else {
-                        my ( $obj_type, $obj_id, undef, $search_id ) = split '-', $item->{name};
-                        $saved{privacy} = "$obj_type-$obj_id";
-                        $saved{id}      = $search_id;
-                    }
+                    my ( $obj_type, $obj_id, undef, $search_id ) = split '-', $item->{name};
+                    $saved{privacy} = "$obj_type-$obj_id";
+                    $saved{id}      = $search_id;
                 } elsif ( $item->{type} eq 'dashboard' ) {
                     my ( undef, $dashboard_id, $obj_type, $obj_id ) = split '-', $item->{name};
                     $saved{privacy}     = "$obj_type-$obj_id";
diff --git a/share/html/Dashboards/Queries.html b/share/html/Dashboards/Queries.html
index f1e8bff0cb..bce8fcc111 100644
--- a/share/html/Dashboards/Queries.html
+++ b/share/html/Dashboards/Queries.html
@@ -112,7 +112,6 @@ push @objs, RT::SavedSearch->new( $session{CurrentUser} )->ObjectsForLoading
 for my $object (@objs) {
     my @items;
     my $object_id = ref($object) . '-' . $object->Id;
-    $object_id = 'system' if $object eq $sys;
 
     # saved searches and charts
     for ($m->comp("/Search/Elements/SearchesForObject", Object => $object)) {
@@ -128,23 +127,13 @@ for my $object (@objs) {
         }
 
         my $item;
-        if ($object eq $sys) {
-            $item = { type => 'system', name => $desc, label => $loc_desc, search_type => $SearchType, search_id => $search->id };
+        my $oid = $object_id.'-SavedSearch-'.$search->Id;
+        $item = { type => 'saved', name => $oid, search_type => $SearchType, label => $loc_desc };
 
-            # make system searches more easily accessible since dashboards
-            # historically used a human-readable description rather than
-            # something we can comfortably use as a hash key
-            $item_for{ $item->{type} }{ $search->id } = $item;
-        }
-        else {
-            my $oid = $object_id.'-SavedSearch-'.$search->Id;
-            $item = { type => 'saved', name => $oid, search_type => $SearchType, label => $loc_desc };
+        my $setting = RT::SavedSearch->new($session{CurrentUser});
+        $setting->Load($object, $search->Id);
 
-            my $setting = RT::SavedSearch->new($session{CurrentUser});
-            $setting->Load($object, $search->Id);
-
-            $item->{possibly_hidden} = !$setting->IsVisibleTo($Dashboard->Privacy);
-        }
+        $item->{possibly_hidden} = !$setting->IsVisibleTo($Dashboard->Privacy);
 
         $item_for{ $item->{type} }{ $item->{name} } = $item;
         push @items, $item;
@@ -191,13 +180,8 @@ do {
                 $item = $item_for{ $saved->{portlet_type} }{ $saved->{component} };
             }
             elsif ($saved->{portlet_type} eq 'search') {
-                if ($saved->{privacy} =~ /^RT::System-/) {
-                    $item = $item_for{system}{$saved->{id}};
-                }
-                else {
-                    my $name = join '-', $saved->{privacy}, 'SavedSearch', $saved->{id};
-                    $item = $item_for{saved}{$name};
-                }
+                my $name = join '-', $saved->{privacy}, 'SavedSearch', $saved->{id};
+                $item = $item_for{saved}{$name};
             }
             else {
                 my $type = $saved->{portlet_type};

commit b64c6548aacaf4228a004c0533b26abb79d27709
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 31 03:46:47 2020 +0800

    Update dashboard tests for the format change of system saved searches

diff --git a/t/mail/dashboard-empty.t b/t/mail/dashboard-empty.t
index 5b36b7d871..cd8d5a3d19 100644
--- a/t/mail/dashboard-empty.t
+++ b/t/mail/dashboard-empty.t
@@ -28,7 +28,7 @@ sub create_dashboard {
         my $arg;
 
         if ( $component_name eq 'My Tickets' ) {
-            $arg = 'system-My Tickets';
+            $arg = 'saved-' . $m->dom->find('[data-description="My Tickets"]')->first->attr('data-name'),
         }
         else {  # component_name is 'My Assets'
             $arg = 'component-MyAssets';
diff --git a/t/web/dashboards-basics.t b/t/web/dashboards-basics.t
index 3367ba6935..5c555604a9 100644
--- a/t/web/dashboards-basics.t
+++ b/t/web/dashboards-basics.t
@@ -99,7 +99,7 @@ ok( $id, "got a dashboard ID, $id" );  # 8
 
 my $args = {
     UpdateSearches => "Save",
-    body           => ["system-Unowned Tickets"],
+    body           => ["saved-" . $m->dom->find('[data-description="Unowned Tickets"]')->first->attr('data-name')],
     sidebar        => [],
 };
 
@@ -125,7 +125,7 @@ like($searches[0]->Name, qr/newest unowned tickets/, "correct search name");
 
 push(
     @{$args->{body}},
-    ( "system-My Tickets", )
+    "saved-" . $m->dom->find('[data-description="My Tickets"]')->first->attr('data-name'),
 );
 
 $res = $m->post(

commit 9887285f3cc8bfd158fbdbe4c7caa82124f01a9e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 31 03:21:36 2020 +0800

    Fix system txn/asset/chart saved searches in MyRT
    
    System ticket saved searches and other saved searches are saved
    differently in MyRT because of historical reasons:
    
    System ticket saved searches are like "system-Unowned Tickets";
    Other saved searches are like like "RT::User-14-SavedSearch-27" and
    "RT::System-1-SavedSearch-34"
    
    The format of "system-SavedSearch-34" is never supported. If you added
    system txn/asset/chart saved searches to homepage, you would get errors
    like:
    
        Either you have no rights to view saved search system-SavedSearch-34
        or identifier is incorrect
    
    This commit corrects it to "RT::System-1-SavedSearch-34".

diff --git a/share/html/Admin/Global/MyRT.html b/share/html/Admin/Global/MyRT.html
index 2ad2fd1f3d..3b7d17df52 100644
--- a/share/html/Admin/Global/MyRT.html
+++ b/share/html/Admin/Global/MyRT.html
@@ -92,7 +92,6 @@ push @objs, RT::SavedSearch->new( $session{CurrentUser} )->ObjectsForLoading
 for my $object (@objs) {
     my @items;
     my $object_id = ref($object) . '-' . $object->Id;
-    $object_id = 'system' if $object eq $sys;
 
     for ($m->comp("/Search/Elements/SearchesForObject", Object => $object)) {
         my ($desc, $loc_desc, $search) = @$_;
diff --git a/share/html/Prefs/MyRT.html b/share/html/Prefs/MyRT.html
index d29c8c8084..79fb7a7619 100644
--- a/share/html/Prefs/MyRT.html
+++ b/share/html/Prefs/MyRT.html
@@ -138,7 +138,6 @@ push @objs, RT::SavedSearch->new( $session{CurrentUser} )->ObjectsForLoading
 for my $object (@objs) {
     my @items;
     my $object_id = ref($object) . '-' . $object->Id;
-    $object_id = 'system' if $object eq $sys;
 
     for ($m->comp("/Search/Elements/SearchesForObject", Object => $object)) {
         my ($desc, $loc_desc, $search) = @$_;

commit 06556b74d8d8efdc0e23ce45dee494073e100aab
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Aug 1 00:27:23 2020 +0800

    Add tests for system non-ticket saved searches in dashboards

diff --git a/t/web/dashboards-basics.t b/t/web/dashboards-basics.t
index 5c555604a9..aac674df06 100644
--- a/t/web/dashboards-basics.t
+++ b/t/web/dashboards-basics.t
@@ -27,13 +27,43 @@ my $queue = RT::Queue->new(RT->SystemUser);
 $queue->Create(Name => 'SearchQueue'.$$);
 
 for my $user ($user_obj, $onlooker) {
-    $user->PrincipalObj->GrantRight(Right => 'ModifySelf');
+    for my $right (qw/ModifySelf ShowSavedSearches/) {
+        $user->PrincipalObj->GrantRight(Right => $right);
+    }
     for my $right (qw/SeeQueue ShowTicket OwnTicket/) {
         $user->PrincipalObj->GrantRight(Right => $right, Object => $queue);
     }
 }
 
-ok $m->login(customer => 'customer'), "logged in";
+# Add some system non-ticket searches
+ok $m->login('root'), "logged in as root";
+$m->get_ok( $url . "/Search/Chart.html?Query=" . 'id=1' );
+
+$m->submit_form(
+    form_name => 'SaveSearch',
+    fields    => {
+        SavedSearchDescription => 'first chart',
+        SavedSearchOwner       => 'RT::System-1',
+    },
+    button => 'SavedSearchSave',
+);
+$m->content_contains("Chart first chart saved", 'saved first chart' );
+
+$m->get_ok( $url . "/Search/Build.html?Class=RT::Transactions&Query=" . 'TicketId=1' );
+
+$m->submit_form(
+    form_name => 'BuildQuery',
+    fields    => {
+        SavedSearchDescription => 'first txn search',
+        SavedSearchOwner       => 'RT::System-1',
+    },
+    button => 'SavedSearchSave',
+);
+# We don't show saved message on page :/
+$m->content_contains("Save as New", 'saved first txn search' );
+
+
+ok $m->login(customer => 'customer', logout => 1), "logged in";
 
 $m->get_ok($url."Dashboards/index.html");
 $m->content_lacks('<a href="/Dashboards/Modify.html?Create=1">New</a>', 
@@ -126,6 +156,8 @@ like($searches[0]->Name, qr/newest unowned tickets/, "correct search name");
 push(
     @{$args->{body}},
     "saved-" . $m->dom->find('[data-description="My Tickets"]')->first->attr('data-name'),
+    "saved-" . $m->dom->find('[data-description="first chart"]')->first->attr('data-name'),
+    "saved-" . $m->dom->find('[data-description="first txn search"]')->first->attr('data-name'),
 );
 
 $res = $m->post(
@@ -133,16 +165,18 @@ $res = $m->post(
     $args,
 );
 
-is( $res->code, 200, "add 'My Tickets' to body" );
+is( $res->code, 200, "add more searches to body" );
 like( $m->uri, qr/results=[A-Za-z0-9]{32}/, 'URL redirected for results' );
 $m->content_contains( 'Dashboard updated' );
 
 $dashboard->LoadById($id);
 @searches = $dashboard->Searches;
 
-is(@searches, 2, "two saved searches in the dashboard");
+is(@searches, 4, "4 saved searches in the dashboard");
 like($searches[0]->Name, qr/newest unowned tickets/, "correct existing search name");
 like($searches[1]->Name, qr/highest priority tickets I own/, "correct new search name");
+is($searches[2]->Name, 'first chart',      "correct existing search name");
+is($searches[3]->Name, 'first txn search', "correct new search name");
 
 my $ticket = RT::Ticket->new(RT->SystemUser);
 $ticket->Create(
@@ -157,6 +191,8 @@ $m->follow_link_ok({text => "different dashboard"});
 $m->follow_link_ok({id => 'page-show'});
 $m->content_contains("50 highest priority tickets I own");
 $m->content_contains("50 newest unowned tickets");
+$m->content_contains("first chart");
+$m->content_contains("first txn search");
 $m->content_unlike( qr/Bookmarked Tickets.*Bookmarked Tickets/s,
     'only dashboard queries show up' );
 $m->content_contains("dashboard test", "ticket subject");

commit c577f70e29c85a355ef612fecd729dfcf967acec
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Aug 1 00:37:16 2020 +0800

    Add tests for system non-ticket saved searches in MyRT

diff --git a/t/web/custom_frontpage.t b/t/web/custom_frontpage.t
index d997f56a8e..cbfcde0c55 100644
--- a/t/web/custom_frontpage.t
+++ b/t/web/custom_frontpage.t
@@ -135,4 +135,49 @@ $m->content_like( qr/special chars \[test\] \d+ \[_1\]/,
     $m->content_contains($desc . " [more]", "found description: $desc");
 }
 
+# Add some system non-ticket searches
+$m->get_ok( $url . "/Search/Chart.html?Query=" . 'id=1' );
+
+$m->submit_form(
+    form_name => 'SaveSearch',
+    fields    => {
+        SavedSearchDescription => 'first chart',
+        SavedSearchOwner       => 'RT::System-1',
+    },
+    button => 'SavedSearchSave',
+);
+$m->content_contains("Chart first chart saved", 'saved first chart' );
+
+$m->get_ok( $url . "/Search/Build.html?Class=RT::Transactions&Query=" . 'TicketId=1' );
+
+$m->submit_form(
+    form_name => 'BuildQuery',
+    fields    => {
+        SavedSearchDescription => 'first txn search',
+        SavedSearchOwner       => 'RT::System-1',
+    },
+    button => 'SavedSearchSave',
+);
+# We don't show saved message on page :/
+$m->content_contains("Save as New", 'saved first txn search' );
+
+$m->get_ok( $url . 'Prefs/MyRT.html' );
+push(
+    @{$args->{body}},
+    "saved-" . $m->dom->find('[data-description="first chart"]')->first->attr('data-name'),
+    "saved-" . $m->dom->find('[data-description="first txn search"]')->first->attr('data-name'),
+);
+
+$res = $m->post(
+    $url . 'Prefs/MyRT.html',
+    $args,
+);
+
+is( $res->code, 200, 'add system saved searches to body' );
+$m->text_contains( 'Preferences saved' );
+
+$m->get_ok($url);
+$m->text_contains('first chart');
+$m->text_contains('first txn search');
+
 done_testing;

commit 3662b73a3a5bcb15f3a0e49f984544b59a52f4ab
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 18 15:06:48 2020 -0500

    Document steps to fix home pages with saved search errors

diff --git a/docs/UPGRADING-5.0 b/docs/UPGRADING-5.0
index f2e84f2c3a..22b60cfc53 100644
--- a/docs/UPGRADING-5.0
+++ b/docs/UPGRADING-5.0
@@ -230,6 +230,18 @@ controlled by a new configuration option C<$SelfServiceShowArticleSearch>. This
 option defaults to off, so if you currently allow self service users to use article search,
 enable this option to keep the article search box available.
 
+=item *
+
+System-level saved searches can now be displayed on the RT at a glance page.
+Previously some users saw errors like:
+
+    Either you have no rights to view saved search system-SavedSearch-34
+    or identifier is incorrect
+
+If you are still seeing that error after updating to RT 5.0.1, edit the page, remove
+the saved search, save, then add it back again. After saving again, it should appear
+as expected.
+
 =back
 
 =cut

commit fd89077092bcdfed3312c6015831b92b07e9b224
Merge: 34492a705f 3662b73a3a
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 18 16:14:51 2020 -0500

    Merge branch '5.0/fix-system-saved-searches-in-dashboard' into 5.0-trunk


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


More information about the rt-commit mailing list