X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FInterface%2FWeb%2FMenu.pm;h=1d7d75c7886c1fd76333e9d07378ca4ba8ec5dff;hp=8670b8acf76d6fb37e1426adbfe7d5cc37c42fe6;hb=44dd00a3ff974a17999e86e64488e996edc71e3c;hpb=9aee669886202be7035e6c6049fc71bc99dd3013 diff --git a/rt/lib/RT/Interface/Web/Menu.pm b/rt/lib/RT/Interface/Web/Menu.pm index 8670b8acf..1d7d75c78 100644 --- a/rt/lib/RT/Interface/Web/Menu.pm +++ b/rt/lib/RT/Interface/Web/Menu.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -375,4 +375,52 @@ sub _insert_sibling { $parent->child( @_, sort_order => $sort_order ); } +=head2 RemoveDashboardMenuItems + +Remove dashboards from individual user and system dash menus. + +Requires a hash with DashboardId and CurrentUser object. + + $menu->RemoveDashboardMenuItem( DashboardId => $id, CurrentUser => $session{CurrentUser}->UserObj ); + +=cut + +sub RemoveDashboardMenuItem { + my $self = shift; + my %args = @_; + + return unless $args{'DashboardId'} and $args{'CurrentUser'}; + my $dashboard_id = $args{'DashboardId'}; + my $current_user = $args{'CurrentUser'}; + + # First clear from user's dashboards + my $dashboards_in_menu = $current_user->Preferences('DashboardsInMenu', {} ); + + my @dashboards = grep { $_ != $dashboard_id } @{$dashboards_in_menu->{'dashboards'}}; + $dashboards_in_menu->{'dashboards'} = \@dashboards || []; + + my ($ret, $msg) = $current_user->SetPreferences('DashboardsInMenu', $dashboards_in_menu); + RT::Logger->warn("Unable to update dashboard for user " . $current_user->Name . ": $msg") + unless $ret; + + # Now update the system dashboard + my $system = RT::System->new( $current_user ); + my ($default_dashboards) = $system->Attributes->Named('DashboardsInMenu'); + + if ($default_dashboards) { + $dashboards_in_menu = $default_dashboards->Content; + my @dashboards = grep { $_ != $dashboard_id } @{$dashboards_in_menu->{'dashboards'}}; + + # Update only if we removed one + if ( @{$dashboards_in_menu->{'dashboards'}} > @dashboards ){ + $dashboards_in_menu->{'dashboards'} = \@dashboards || []; + + ($ret, $msg) = $default_dashboards->SetContent($dashboards_in_menu); + RT::Logger->warn("Unable to update system dashboard menu: $msg") + unless $ret; + } + } + return; +} + 1;