Mailing List Archive

rt branch, 5.0/fix-system-saved-searches-in-dashboard, created. rt-5.0.0-7-gf8ba915106
The branch, 5.0/fix-system-saved-searches-in-dashboard has been created
at f8ba91510669de8f55b8441670e753d0502cc726 (commit)

- Log -----------------------------------------------------------------
commit 817d113133c4ea3ca56393e6bb8d66bb126041a6
Author: sunnavy <sunnavy@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 379e7b1976..a6572dc061 100644
--- a/share/html/Dashboards/Queries.html
+++ b/share/html/Dashboards/Queries.html
@@ -109,8 +109,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 160b88b188c86c4bfd367f386a9d3c085ab4cc6b
Author: sunnavy <sunnavy@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 ce7c78f679..e625f1f6fe 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -4744,7 +4744,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}
@@ -4757,14 +4757,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 a6572dc061..0d6b4e3e3b 100644
--- a/share/html/Dashboards/Queries.html
+++ b/share/html/Dashboards/Queries.html
@@ -93,7 +93,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)) {
@@ -109,23 +108,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;
@@ -172,13 +161,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 b89e4123714ea43d02bc743308635e480ddbb396
Author: sunnavy <sunnavy@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 ad5942484279b29357eafbd8683a5d61abee6bb8
Author: sunnavy <sunnavy@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 89bce9b595f8d77655034f50ce20194158c69017
Author: sunnavy <sunnavy@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 f8ba91510669de8f55b8441670e753d0502cc726
Author: sunnavy <sunnavy@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;

-----------------------------------------------------------------------
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit