[Rt-commit] rt branch, 5.0/dashboards-to-report-menu-2, created. rt-5.0.0alpha1-219-g8cbb0cd8ee

Jim Brandt jbrandt at bestpractical.com
Mon May 4 17:41:10 EDT 2020


The branch, 5.0/dashboards-to-report-menu-2 has been created
        at  8cbb0cd8eec1b600444d463846cd7f525fa46765 (commit)

- Log -----------------------------------------------------------------
commit 71e7eb52aa79ce54cca6fdc02ad984697254bbc3
Author: michel <michel at bestpractical.com>
Date:   Wed Apr 15 15:16:57 2020 +0200

    Moved initial dashboards to the Reports menu.

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 613f4b903a..eb93ce42f2 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -95,58 +95,6 @@ sub BuildMainNav {
     $home->child( create_ticket => title => loc("Create Ticket"),
                   path => "/Ticket/Create.html" );
 
-    unless ($HTML::Mason::Commands::session{'dashboards_in_menu'}) {
-        my $dashboards_in_menu = $current_user->UserObj->Preferences(
-            'DashboardsInMenu',
-            {},
-        );
-
-        unless ($dashboards_in_menu->{dashboards}) {
-            my ($default_dashboards) =
-                RT::System->new( $current_user )
-                    ->Attributes
-                    ->Named('DashboardsInMenu');
-            if ($default_dashboards) {
-                $dashboards_in_menu = $default_dashboards->Content;
-            }
-        }
-
-        $HTML::Mason::Commands::session{'dashboards_in_menu'} = $dashboards_in_menu->{dashboards} || [];
-    }
-
-    my @dashboards;
-    for my $id ( @{$HTML::Mason::Commands::session{'dashboards_in_menu'}} ) {
-        my $dash = RT::Dashboard->new( $current_user );
-        my ( $status, $msg ) = $dash->LoadById($id);
-        if ( $status ) {
-            push @dashboards, $dash;
-        } else {
-            $RT::Logger->debug( "Failed to load dashboard $id: $msg, removing from menu" );
-            $home->RemoveDashboardMenuItem(
-                DashboardId => $id,
-                CurrentUser => $HTML::Mason::Commands::session{CurrentUser}->UserObj,
-            );
-            @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} } =
-              grep { $_ != $id } @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} };
-        }
-    }
-
-    my $dashes = $top->child('home');
-    if (@dashboards) {
-        for my $dash (@dashboards) {
-            $home->child( 'dashboard-' . $dash->id,
-                title => $dash->Name,
-                path  => '/Dashboards/' . $dash->id . '/' . $dash->Name
-            );
-        }
-    }
-    $dashes->child( edit => title => loc('Update This Menu'), path => 'Prefs/DashboardsInMenu.html' );
-    $dashes->child( more => title => loc('All Dashboards'),   path => 'Dashboards/index.html' );
-    my $dashboard = RT::Dashboard->new( $current_user );
-    if ( $dashboard->CurrentUserCanCreateAny ) {
-        $dashes->child('dashboard_create' => title => loc('New Dashboard'), path => "/Dashboards/Modify.html?Create=1" );
-    }
-
     my $search = $top->child( search => title => loc('Search'), path => '/Search/Simple.html' );
 
     my $tickets = $search->child( tickets => title => loc('Tickets'), path => '/Search/Build.html' );
@@ -185,7 +133,6 @@ sub BuildMainNav {
         $search_assets->child("assetsql", title => loc("New Search"), path => "/Search/Build.html?Class=RT::Assets;NewQuery=1");
     }
 
-
     my $txns = $search->child( transactions => title => loc('Transactions'), path => '/Search/Build.html?Class=RT::Transactions;ObjectType=RT::Ticket' );
     my $txns_tickets = $txns->child( tickets => title => loc('Tickets'), path => "/Search/Build.html?Class=RT::Transactions;ObjectType=RT::Ticket" );
     $txns_tickets->child( new => title => loc('New Search'), path => "/Search/Build.html?Class=RT::Transactions;ObjectType=RT::Ticket;NewQuery=1" );
@@ -195,6 +142,52 @@ sub BuildMainNav {
         description => loc('Reports summarizing ticket resolution and status'),
         path        => loc('/Reports'),
     );
+
+    unless ($HTML::Mason::Commands::session{'dashboards_in_menu'}) {
+        my $dashboards_in_menu = $current_user->UserObj->Preferences(
+            'DashboardsInMenu',
+            {},
+        );
+
+        unless ($dashboards_in_menu->{dashboards}) {
+            my ($default_dashboards) =
+                RT::System->new( $current_user )
+                    ->Attributes
+                    ->Named('DashboardsInMenu');
+            if ($default_dashboards) {
+                $dashboards_in_menu = $default_dashboards->Content;
+            }
+        }
+
+        $HTML::Mason::Commands::session{'dashboards_in_menu'} = $dashboards_in_menu->{dashboards} || [];
+    }
+
+    my @dashboards;
+    for my $id ( @{$HTML::Mason::Commands::session{'dashboards_in_menu'}} ) {
+        my $dash = RT::Dashboard->new( $current_user );
+        my ( $status, $msg ) = $dash->LoadById($id);
+        if ( $status ) {
+            push @dashboards, $dash;
+        } else {
+            $RT::Logger->debug( "Failed to load dashboard $id: $msg, removing from menu" );
+            $home->RemoveDashboardMenuItem(
+                DashboardId => $id,
+                CurrentUser => $HTML::Mason::Commands::session{CurrentUser}->UserObj,
+            );
+            @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} } =
+              grep { $_ != $id } @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} };
+        }
+    }
+
+    if (@dashboards) {
+        for my $dash (@dashboards) {
+            $reports->child( 'dashboard-' . $dash->id,
+                title => $dash->Name,
+                path  => '/Dashboards/' . $dash->id . '/' . $dash->Name
+            );
+        }
+    }
+
     $reports->child( resolvedbyowner =>
         title       => loc('Resolved by owner'),
         path        => '/Reports/ResolvedByOwner.html',
@@ -211,6 +204,14 @@ sub BuildMainNav {
         description => loc('Examine tickets created in a queue between two dates'),
     );
 
+    $reports->child( edit => title => loc('Update This Menu'), path => '/Prefs/DashboardsInMenu.html' );
+    $reports->child( more => title => loc('All Dashboards'),   path => '/Dashboards/index.html' );
+    my $dashboard = RT::Dashboard->new( $current_user );
+    if ( $dashboard->CurrentUserCanCreateAny ) {
+        $reports->child('dashboard_create' => title => loc('New Dashboard'), path => "/Dashboards/Modify.html?Create=1" );
+    }
+
+
     if ($current_user->HasRight( Right => 'ShowArticlesMenu', Object => RT->System )) {
         my $articles = $top->child( articles => title => loc('Articles'), path => "/Articles/index.html");
         $articles->child( articles => title => loc('Overview'), path => "/Articles/index.html" );

commit 9023b83ed141a901f4e12bd7d0a177ba9ae58beb
Author: michel <michel at bestpractical.com>
Date:   Thu Apr 16 13:21:19 2020 +0200

    Get the list of reports in the Reports menu from attribute
    
    The initial list is created from initialdata, in the ReportsInMenu attribute.
    It can be modified in the Pref-ReportsInMenu user preference,
    similar to dashboards.

diff --git a/etc/initialdata b/etc/initialdata
index 74951a5b85..a8ad15927c 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -923,6 +923,27 @@ Hour:         { $SubscriptionObj->SubValue('Hour') }
               ],
         },
     },
+# initial reports
+    { Name => 'ReportsInMenu',
+      Description => 'Content of the Reports menu', #loc
+      Content     => [
+          {
+              id          => 'resolvedbyowner',
+              title       => 'Resolved by owner', # loc
+              file        => 'ResolvedByOwner.html',
+          },
+          {
+              id          => 'resolvedindaterange',
+              title       => 'Resolved in date range', # loc
+              file        => 'ResolvedByDates.html',
+          },
+          {
+              id          => 'createdindaterange',
+              title       => 'Created in a date range', # loc
+              file        => 'CreatedByDates.html',
+          },
+      ],
+    },
 );
 
 @Classes = (
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index eb93ce42f2..1ac554f135 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -179,6 +179,7 @@ sub BuildMainNav {
         }
     }
 
+
     if (@dashboards) {
         for my $dash (@dashboards) {
             $reports->child( 'dashboard-' . $dash->id,
@@ -188,21 +189,37 @@ sub BuildMainNav {
         }
     }
 
-    $reports->child( resolvedbyowner =>
-        title       => loc('Resolved by owner'),
-        path        => '/Reports/ResolvedByOwner.html',
-        description => loc('Examine tickets resolved in a queue, grouped by owner'),
-    );
-    $reports->child( resolvedindaterange =>
-        title       => loc('Resolved in date range'),
-        path        => '/Reports/ResolvedByDates.html',
-        description => loc('Examine tickets resolved in a queue between two dates'),
-    );
-    $reports->child( createdindaterange =>
-        title       => loc('Created in a date range'),
-        path        => '/Reports/CreatedByDates.html',
-        description => loc('Examine tickets created in a queue between two dates'),
-    );
+    # Get the list of reports in the Reports menu
+    unless (   $HTML::Mason::Commands::session{'reports_in_menu'}
+            && ref( $HTML::Mason::Commands::session{'reports_in_menu'}) eq 'ARRAY'
+            && @{$HTML::Mason::Commands::session{'reports_in_menu'}}
+           ) {
+        my $reports_in_menu = $current_user->UserObj->Preferences(
+            'ReportsInMenu',
+            {},
+        );
+        unless ($reports_in_menu && ref( $reports_in_menu) eq 'ARRAY' ) {
+            my ($default_reports) =
+                RT::System->new( RT->SystemUser )
+                    ->Attributes
+                    ->Named('ReportsInMenu');
+            if ($default_reports) {
+                $reports_in_menu = $default_reports->Content;
+            }
+            else {
+                $reports_in_menu = [];
+            }
+        }
+
+        $HTML::Mason::Commands::session{'reports_in_menu'} = $reports_in_menu || [];
+    }
+
+    for my $report ( @{$HTML::Mason::Commands::session{'reports_in_menu'}} ) {
+        $reports->child(  $report->{id} =>
+            title       => $report->{title},
+            path        => '/Reports/' . $report->{file},
+        );
+    }
 
     $reports->child( edit => title => loc('Update This Menu'), path => '/Prefs/DashboardsInMenu.html' );
     $reports->child( more => title => loc('All Dashboards'),   path => '/Dashboards/index.html' );

commit f204daa147d8b7b48eb061985450f9b68a86df06
Author: michel <michel at bestpractical.com>
Date:   Tue Apr 28 18:08:44 2020 +0200

    Add upgrade step: create the ReportsInMenu attribute if needed.

diff --git a/etc/upgrade/4.5.5/content b/etc/upgrade/4.5.5/content
new file mode 100644
index 0000000000..71e092e71d
--- /dev/null
+++ b/etc/upgrade/4.5.5/content
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+our @Initial = (
+    # add default reports
+    sub {
+        my $reports_in_menu = 'ReportsInMenu';
+        my $attr = RT::Attribute->new( RT->System );
+        my( $ok, $msg) = $attr->LoadByNameAndObject( Object => RT->System, Name => $reports_in_menu );
+        # add attribute only if it does not already exist
+        if( ! $ok ) {
+            RT->Logger->debug( "Adding default reports in menu" );
+            my $content = [
+                {
+                    id          => 'resolvedbyowner',
+                    title       => 'Resolved by owner', # loc
+                    file        => 'ResolvedByOwner.html',
+                },
+                {
+                    id          => 'resolvedindaterange',
+                    title       => 'Resolved in date range', # loc
+                    file        => 'ResolvedByDates.html',
+                },
+                {
+                    id          => 'createdindaterange',
+                    title       => 'Created in a date range', # loc
+                    file        => 'CreatedByDates.html',
+                },
+            ];
+
+            RT->System->AddAttribute(
+                        Name => $reports_in_menu,
+                        Description => 'Content of the Reports menu',
+                        Content => $content,
+            );
+        }
+    }
+);

commit af63a1c0f27a8ddc55913c12278be9c472b9888d
Author: michel <michel at bestpractical.com>
Date:   Fri May 1 17:01:02 2020 +0200

    Fix tests to reflect changes in dashboard menu ids.

diff --git a/t/web/dashboards-basics.t b/t/web/dashboards-basics.t
index 567eb0635b..3367ba6935 100644
--- a/t/web/dashboards-basics.t
+++ b/t/web/dashboards-basics.t
@@ -66,7 +66,7 @@ $m->content_contains("Create");
 
 $m->get_ok($url."Dashboards/index.html");
 $m->content_contains("New", "'New' link because we now have ModifyOwnDashboard");
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 $m->field("Name" => 'different dashboard');
 $m->content_lacks('Delete', "Delete button hidden because we are creating");
diff --git a/t/web/dashboards-groups.t b/t/web/dashboards-groups.t
index 9f1c37debe..443ff06f23 100644
--- a/t/web/dashboards-groups.t
+++ b/t/web/dashboards-groups.t
@@ -54,14 +54,14 @@ ok($inner_group->HasMemberRecursively($user_obj->PrincipalId), "inner has user r
 ok $m->login(customer => 'customer'), "logged in";
 
 
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id], "the only selectable privacy is user");
 $m->content_lacks('Delete', "Delete button hidden because we are creating");
 
 $user_obj->PrincipalObj->GrantRight(Right => 'CreateGroupDashboard', Object => $inner_group);
 
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id, "RT::Group-" . $inner_group->Id], "the only selectable privacies are user and inner group (not outer group)");
 $m->field("Name" => 'broken dashboard');
@@ -74,7 +74,7 @@ $user_obj->PrincipalObj->GrantRight(
     Right  => 'SeeGroupDashboard',
     Object => $inner_group,
 );
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 $m->field("Name" => 'inner dashboard');
 $m->field("Privacy" => "RT::Group-" . $inner_group->Id);
diff --git a/t/web/dashboards-permissions.t b/t/web/dashboards-permissions.t
index 433fdd3731..a22c043d7f 100644
--- a/t/web/dashboards-permissions.t
+++ b/t/web/dashboards-permissions.t
@@ -28,7 +28,7 @@ $user_obj->PrincipalObj->GrantRight(Right => $_, Object => $RT::System)
 ok $m->login(customer => 'customer'), "logged in";
 
 
-$m->follow_link_ok( {id => 'home-dashboard_create'});
+$m->follow_link_ok( {id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id], "the only selectable privacy is user");
 $m->content_lacks('Delete', "Delete button hidden because we are creating");
diff --git a/t/web/dashboards-subscription.t b/t/web/dashboards-subscription.t
index 8a3473e919..1e493332cb 100644
--- a/t/web/dashboards-subscription.t
+++ b/t/web/dashboards-subscription.t
@@ -25,7 +25,7 @@ ok $m->login(customer => 'customer'), "logged in";
 $m->get_ok($url."Dashboards/Modify.html?Create=1");
 
 # Create Dashboard
-$m->follow_link_ok({ id => 'home-dashboard_create' });
+$m->follow_link_ok({ id => 'reports-dashboard_create' });
 $m->form_name('ModifyDashboard');
 $m->field("Name" => 'test dashboard');
 $m->click_button(value => 'Create');

commit 45745923fc24602c417d58c1dc41f1d7a40992fc
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri May 1 16:48:44 2020 -0400

    Update report menu description and remove link
    
    With dashboards added, linking to a reports page is no longer
    useful.

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 1ac554f135..7e4f2a5917 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -139,8 +139,7 @@ sub BuildMainNav {
 
     my $reports = $top->child( reports =>
         title       => loc('Reports'),
-        description => loc('Reports summarizing ticket resolution and status'),
-        path        => loc('/Reports'),
+        description => loc('Reports and Dashboards'),
     );
 
     unless ($HTML::Mason::Commands::session{'dashboards_in_menu'}) {

commit 663a3c7371234087cecf1f993ada50eeea906299
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 16:15:44 2020 -0400

    Add and remove reports from the Reports menu
    
    Add report processing to the "Update This Menu" functionality
    for the Reports (formerly Home/Dashboards) menu.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 987b4c890b..1eef292fdb 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -4742,6 +4742,38 @@ sub UpdateDashboard {
     }
 }
 
+=head2 ListOfReports
+
+Returns the list of reports registered with RT.
+
+=cut
+
+sub ListOfReports {
+
+    # TODO: Make this a dynamic list generated by loading files in the Reports
+    # directory
+
+    my $list_of_reports = [
+        {
+            id          => 'resolvedbyowner',
+            title       => 'Resolved by owner', # loc
+            file        => 'ResolvedByOwner.html',
+        },
+        {
+            id          => 'resolvedindaterange',
+            title       => 'Resolved in date range', # loc
+            file        => 'ResolvedByDates.html',
+        },
+        {
+            id          => 'createdindaterange',
+            title       => 'Created in a date range', # loc
+            file        => 'CreatedByDates.html',
+        },
+    ];
+
+    return $list_of_reports;
+}
+
 package RT::Interface::Web;
 RT::Base->_ImportOverlays();
 
diff --git a/share/html/Prefs/DashboardsInMenu.html b/share/html/Prefs/DashboardsInMenu.html
index db456df2b9..e1ab3c4090 100644
--- a/share/html/Prefs/DashboardsInMenu.html
+++ b/share/html/Prefs/DashboardsInMenu.html
@@ -91,6 +91,22 @@ my $current_dashboards = $dashboard_pref->{dashboards} || [];
 
 my @dashboards = map { [$_->id, $_->Name] } $m->comp("/Dashboards/Elements/ListOfDashboards", IncludeSuperuserGroups => 0 );
 
+# Process report links which live in the same menu, but are not dashboards
+my ($default_reports) =
+    RT::System->new($session{'CurrentUser'})->Attributes->Named('ReportsInMenu');
+
+my $report_pref =
+    $session{CurrentUser}->UserObj->Preferences( 'ReportsInMenu',
+        $default_reports ? $default_reports->Content : () );
+
+my $current_reports = $report_pref || [];
+
+# Add reports to the list of current dashboards in the menu
+push @$current_dashboards, map { $_->{id} } @$current_reports;
+
+# Add reports to the list of available items for the menu
+push @dashboards, map { [$_->{id}, $_->{title}] } @{ ListOfReports() };
+
 my @panes = $m->comp(
     '/Admin/Elements/ConfigureDashboardsInMenu',
     Action => 'DashboardsInMenu.html',
@@ -99,9 +115,29 @@ my @panes = $m->comp(
     current_portlets => $current_dashboards,
     OnSave => sub {
         my ( $conf ) = @_;
+
+        my $reports_ref = ListOfReports();
+        my $user_reports = [];
+        foreach my $id ( @{$conf->{dashboards}} ) {
+            if ( my ($report_ref) = grep { $_->{id} eq $id } @$reports_ref ) {
+                # Found a report
+                push @$user_reports, $report_ref;
+            }
+        }
+
+        # Clear out reports from the dashboard list, which expects dashboard ids only
+        # Make a copy because the web page uses $conf to show the current list
+        my $save_conf = Storable::dclone($conf);
+        @{$save_conf->{dashboards}} = grep { /^\d+$/ } @{$conf->{dashboards}};
+
         my ( $ok, $msg ) =
-          $user->SetPreferences( 'DashboardsInMenu', $conf );
+          $user->SetPreferences( 'ReportsInMenu', $user_reports );
+        push @results, $msg unless $ok;
+
+        ( $ok, $msg ) =
+          $user->SetPreferences( 'DashboardsInMenu', $save_conf );
         push @results, $ok ? loc('Preferences saved for dashboards in menu.') : $msg;
+        delete $session{'reports_in_menu'};
         delete $session{'dashboards_in_menu'};
     }
 );

commit f063bf4fb1bc2b76fb7236a0abf5030af6906fe5
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 17:08:19 2020 -0400

    Add reports to global reports menu editor

diff --git a/share/html/Admin/Global/DashboardsInMenu.html b/share/html/Admin/Global/DashboardsInMenu.html
index 21b12077ac..eb3a037d9f 100644
--- a/share/html/Admin/Global/DashboardsInMenu.html
+++ b/share/html/Admin/Global/DashboardsInMenu.html
@@ -76,6 +76,16 @@ while ( my $dashboard = $dashboards->Next ) {
     push @dashboards, [$dashboard->id, $dashboard->Name];
 }
 
+# Process report links which live in the same menu, but are not dashboards
+my ($reports_attr) =
+    RT::System->new(RT->SystemUser)->Attributes->Named('ReportsInMenu');
+
+# Add reports to the list of current dashboards in the menu
+push @$default_dashboards_in_menu, map { $_->{id} } @{ $reports_attr->Content || () };
+
+# Add reports to the list of available items for the menu
+push @dashboards, map { [$_->{id}, $_->{title}] } @{ ListOfReports() };
+
 my @panes = $m->comp(
     '/Admin/Elements/ConfigureDashboardsInMenu',
     Action => 'DashboardsInMenu.html',
@@ -90,15 +100,34 @@ my @panes = $m->comp(
         if (!$has_right) {
             push @actions, loc( 'Permission Denied' );
         }
-        elsif ( $dashboard_attr ) {
-            ($status, $msg) = $dashboard_attr->SetContent($conf);
+        elsif ( $dashboard_attr && $reports_attr ) {
+            my $reports_ref = ListOfReports();
+            my $system_reports = [];
+            foreach my $id ( @{$conf->{dashboards}} ) {
+                if ( my ($report_ref) = grep { $_->{id} eq $id } @$reports_ref ) {
+                    # Found a report
+                    push @$system_reports, $report_ref;
+                }
+            }
+
+            # Clear out reports from the dashboard list, which expects dashboard ids only
+            # Make a copy because the web page uses $conf to show the current list
+            my $save_conf = Storable::dclone($conf);
+            @{$save_conf->{dashboards}} = grep { /^\d+$/ } @{$conf->{dashboards}};
+
+            ( $status, $msg ) = $reports_attr->SetContent($system_reports);
+            push @actions, $msg unless $status;
+            ($status, $msg) = $dashboard_attr->SetContent($save_conf);
         }
         else {
+            my $save_conf = Storable::dclone($conf);
+            @{$save_conf->{dashboards}} = grep { /^\d+$/ } @{$conf->{dashboards}};
+
             $dashboard_attr = RT::Attribute->new($RT::SystemUser);
             ( $status, $msg ) = $dashboard_attr->Create(
                 Name    => 'DashboardsInMenu',
                 Object  => $sys,
-                Content => $conf,
+                Content => $save_conf,
             );
         }
         push @actions, $status ? loc('Global dashboards in menu saved.') : $msg;

commit 91fb000077e1cbc4576b4e391438ae82f10fd74b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 17:32:39 2020 -0400

    Add reports to user admin menu edit

diff --git a/share/html/Admin/Users/DashboardsInMenu.html b/share/html/Admin/Users/DashboardsInMenu.html
index 35efa9c9c9..d6c74bfca7 100644
--- a/share/html/Admin/Users/DashboardsInMenu.html
+++ b/share/html/Admin/Users/DashboardsInMenu.html
@@ -88,6 +88,15 @@ my @dashboards =
   map { [ $_->id, $_->Name ] }
   $m->comp( "/Dashboards/Elements/ListOfDashboards", User => $user, IncludeSuperuserGroups => 0 );
 
+# Process report links which live in the same menu, but are not dashboards
+my ($default_reports) =
+    RT::System->new($session{'CurrentUser'})->Attributes->Named('ReportsInMenu');
+
+my $report_pref =
+    $session{CurrentUser}->UserObj->Preferences( 'ReportsInMenu',
+        $default_reports ? $default_reports->Content : () );
+
+my $current_reports = $report_pref || [];
 
 my $current_pref =
   $UserObj->Preferences( 'DashboardsInMenu',
@@ -97,6 +106,12 @@ my $current_portlets =
   ? $current_pref->{dashboards}
   : [];
 
+# Add reports to the list of current dashboards in the menu
+push @$current_portlets, map { $_->{id} } @$current_reports;
+
+# Add reports to the list of available items for the menu
+push @dashboards, map { [$_->{id}, $_->{title}] } @{ ListOfReports() };
+
 my @panes = $m->comp(
     '/Admin/Elements/ConfigureDashboardsInMenu',
     Action           => "DashboardsInMenu.html?id=$id",
@@ -105,8 +120,27 @@ my @panes = $m->comp(
     current_portlets => $current_portlets,
     OnSave => sub {
         my ($conf) = @_;
+
+        my $reports_ref = ListOfReports();
+        my $user_reports = [];
+        foreach my $id ( @{$conf->{dashboards}} ) {
+            if ( my ($report_ref) = grep { $_->{id} eq $id } @$reports_ref ) {
+                # Found a report
+                push @$user_reports, $report_ref;
+            }
+        }
+
+        # Clear out reports from the dashboard list, which expects dashboard ids only
+        # Make a copy because the web page uses $conf to show the current list
+        my $save_conf = Storable::dclone($conf);
+        @{$save_conf->{dashboards}} = grep { /^\d+$/ } @{$conf->{dashboards}};
+
         my ( $ok, $msg ) =
-          $UserObj->SetPreferences( 'DashboardsInMenu', $conf );
+          $UserObj->SetPreferences( 'ReportsInMenu', $user_reports );
+        push @actions, $msg unless $ok;
+
+        ( $ok, $msg ) =
+          $UserObj->SetPreferences( 'DashboardsInMenu', $save_conf );
         push @actions,
           $ok ? loc('Preferences saved for dashboards in menu.') : $msg;
     }

commit 8cbb0cd8eec1b600444d463846cd7f525fa46765
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 17:15:07 2020 -0400

    Update label to reflect new Reports menu location

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 7e4f2a5917..09567efc95 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -298,7 +298,7 @@ sub BuildMainNav {
         $settings->child( search_options => title => loc('Search options'), path => '/Prefs/SearchOptions.html' );
         $settings->child( myrt           => title => loc('RT at a glance'), path => '/Prefs/MyRT.html' );
         $settings->child( dashboards_in_menu =>
-            title => loc('Dashboards in menu'),
+            title => loc('Modify Reports menu'),
             path  => '/Prefs/DashboardsInMenu.html',
         );
         $settings->child( queue_list    => title => loc('Queue list'),   path => '/Prefs/QueueList.html' );
@@ -1146,7 +1146,7 @@ sub _BuildAdminMenu {
         path        => '/Admin/Global/MyRT.html',
     );
     $admin_global->child( 'dashboards-in-menu' =>
-        title       => loc('Dashboards in menu'),
+        title       => loc('Modify Reports menu'),
         description => loc('Customize dashboards in menu'),
         path        => '/Admin/Global/DashboardsInMenu.html',
     );
@@ -1269,7 +1269,7 @@ sub _BuildAdminMenu {
                 $page->child( history     => title => loc('History'),        path => "/Admin/Users/History.html?id=" . $id );
                 $page->child( 'my-rt'     => title => loc('RT at a glance'), path => "/Admin/Users/MyRT.html?id=" . $id );
                 $page->child( 'dashboards-in-menu' =>
-                    title => loc('Dashboards in menu'),
+                    title => loc('Modify Reports menu'),
                     path  => '/Admin/Users/DashboardsInMenu.html?id=' . $id,
                 );
                 if ( RT->Config->Get('Crypt')->{'Enable'} ) {

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


More information about the rt-commit mailing list