[Rt-commit] rtir branch 5.0/homepage-dashboard created. 5.0.1-14-g39090f17

BPS Git Server git at git.bestpractical.com
Tue Aug 24 22:44:31 UTC 2021


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 "rtir".

The branch, 5.0/homepage-dashboard has been created
        at  39090f1768c31881455f469bcb998cabdf796313 (commit)

- Log -----------------------------------------------------------------
commit 39090f1768c31881455f469bcb998cabdf796313
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Aug 25 06:14:36 2021 +0800

    Update tests for the migration of Homepage => dashboard

diff --git a/t/web/custom_frontpage.t b/t/web/custom_frontpage.t
index 437c8e37..32b9370c 100644
--- a/t/web/custom_frontpage.t
+++ b/t/web/custom_frontpage.t
@@ -16,6 +16,10 @@ $user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch');
 $user_obj->PrincipalObj->GrantRight(Right => 'EditSavedSearches');
 $user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
 $user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
+$user_obj->PrincipalObj->GrantRight(Right => 'SeeDashboard');
+$user_obj->PrincipalObj->GrantRight(Right => 'SeeOwnDashboard');
+$user_obj->PrincipalObj->GrantRight(Right => 'CreateOwnDashboard');
+$user_obj->PrincipalObj->GrantRight(Right => 'ModifyOwnDashboard');
 
 ok $m->login( customer => 'customer' ), "logged in";
 
@@ -28,32 +32,52 @@ $m->field ( "ValueOfAttachment" => 'stupid');
 $m->field ( "SavedSearchDescription" => 'stupid tickets');
 $m->click_button (name => 'SavedSearchSave');
 
-$m->get ( $url.'RTIR/Prefs/Home.html' );
+$m->get_ok( $url . "Dashboards/Modify.html?Create=1" );
+$m->form_name('ModifyDashboard');
+$m->field( Name => 'My RTIR homepage' );
+$m->click_button( value => 'Create' );
+
+$m->follow_link_ok( { text => 'Content' } );
 $m->content_contains('stupid tickets', 'saved search listed in rt at a glance items');
 
 ok $m->login('root', 'password', logout => 1), 'we did log in as root';
 
+$m->get_ok( $url . "Dashboards/Modify.html?Create=1" );
+$m->form_name('ModifyDashboard');
+$m->field( Name => 'My RTIR homepage' );
+$m->click_button( value => 'Create' );
+
+my ($id) = ( $m->uri =~ /id=(\d+)/ );
+ok( $id, "got a dashboard ID, $id" );
+
 my $args = {
     UpdateSearches => "Save",
-    dashboard_id   => "RTIR_HomepageSettings",
     body           => [],
     sidebar        => [],
 };
 
+$m->follow_link_ok( { text => 'Content' } );
 # remove all portlets from the body pane except 'newest unowned tickets'
 push(
     @{$args->{body}},
-    ( "system-Unowned Tickets", )
+    "saved-" . $m->dom->find('[data-description="Unowned Tickets"]')->first->attr('data-name'),
 );
 
 my $res = $m->post(
-    $url . 'RTIR/Prefs/Home.html',
+    $url . "Dashboards/Queries.html?id=$id",
     $args,
 );
 
 is( $res->code, 200, "remove all portlets from body except 'newest unowned tickets'" );
 like( $m->uri, qr/results=[A-Za-z0-9]{32}/, 'URL redirected for results' );
-$m->content_contains( 'Preferences saved' );
+$m->content_contains( 'Dashboard updated' );
+
+$m->get_ok( $url . '/RTIR/Prefs/Home.html' );
+$m->submit_form_ok(
+    {   form_name => 'UpdateRTIRDefaultDashboard',
+        button    => "RTIRDefaultDashboard-$id",
+    },
+);
 
 $m->get( $url."RTIR/" );
 $m->content_contains( 'newest unowned tickets', "'newest unowned tickets' is present" );
@@ -61,10 +85,14 @@ $m->content_lacks( 'highest priority tickets', "'highest priority tickets' is no
 $m->content_lacks( 'Bookmarked Tickets<span class="results-count">', "'Bookmarked Tickets' is not present" );  # 'Bookmarked Tickets' also shows up in the nav, so we need to be more specific
 $m->content_lacks( 'Quick ticket creation', "'Quick ticket creation' is not present" );
 
+$m->get_ok( $url . "Dashboards/Queries.html?id=$id" );
+
 # add back the previously removed portlets
 push(
     @{$args->{body}},
-    ( "system-My Tickets", "system-Bookmarked Tickets", "component-QuickCreate" )
+    "saved-" . $m->dom->find('[data-description="My Tickets"]')->first->attr('data-name'),
+    "saved-" . $m->dom->find('[data-description="Bookmarked Tickets"]')->first->attr('data-name'),
+    "component-QuickCreate",
 );
 
 push(
@@ -73,13 +101,13 @@ push(
 );
 
 $res = $m->post(
-    $url . 'RTIR/Prefs/Home.html',
+    $url . "Dashboards/Queries.html?id=$id",
     $args,
 );
 
 is( $res->code, 200, 'add back previously removed portlets' );
 like( $m->uri, qr/results=[A-Za-z0-9]{32}/, 'URL redirected for results' );
-$m->content_contains( 'Preferences saved' );
+$m->content_contains( 'Dashboard updated' );
 
 $m->get( $url."RTIR/" );
 $m->content_contains( 'newest unowned tickets', "'newest unowned tickets' is present" );
@@ -95,7 +123,7 @@ $m->field( "SavedSearchDescription" => 'special chars [test] [_1] ~[_1~]' );
 $m->click_button( name => 'SavedSearchSave' );
 my ($name) = $m->content =~ /value="(RT::User-\d+-SavedSearch-\d+)"/;
 ok( $name, 'saved search name' );
-$m->get( $url . 'RTIR/Prefs/Home.html' );
+$m->get_ok( $url . "Dashboards/Queries.html?id=$id" );
 $m->content_contains( 'special chars [test] [_1] ~[_1~]',
     'saved search listed in rt at a glance items' );
 
@@ -106,13 +134,13 @@ push(
 );
 
 $res = $m->post(
-    $url . 'RTIR/Prefs/Home.html',
+    $url . "Dashboards/Queries.html?id=$id",
     $args,
 );
 
 is( $res->code, 200, 'add saved search to body' );
 like( $m->uri, qr/results=[A-Za-z0-9]{32}/, 'URL redirected for results' );
-$m->content_contains( 'Preferences saved' );
+$m->content_contains( 'Dashboard updated' );
 
 $m->get( $url."RTIR/" );
 $m->content_like( qr/special chars \[test\] \d+ \[_1\]/,

commit 9e4e6e0c933c056e3ad6dcf0daaaa764a053fe3b
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Aug 25 06:13:39 2021 +0800

    Migrate RTIR homepage to dashboard

diff --git a/etc/initialdata b/etc/initialdata
index 277fe1f6..d6b687fa 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -625,35 +625,6 @@ for my $cf (@CustomFields) {
         );
 }
 
- at Attributes = (
-    {   Name        => 'RTIR_HomepageSettings',
-        Description => 'RTIR homepage settings',
-        Content     => {
-            body => [
-                { type => 'component', name => '/RTIR/Elements/NewReports' },
-                {   type => 'component',
-                    name => '/RTIR/Elements/UserDueIncidents'
-                },
-                {   type => 'component',
-                    name => '/RTIR/Elements/NobodyDueIncidents'
-                },
-                {   type => 'component',
-                    name => '/RTIR/Elements/DueIncidents'
-                },
-            ],
-            sidebar => [
-                {   type => 'component',
-                    name => '/RTIR/Elements/WorkWithConstituency'
-                },
-                {   type => 'component',
-                    name => '/RTIR/Elements/QueueSummary'
-                },
-                { type => 'component', name => 'RefreshHomepage' },
-            ]
-        },
-    }
-);
-
 @Final = (
     sub {
         $| = 1;
@@ -717,6 +688,82 @@ for my $cf (@CustomFields) {
             Object => RT->System
         );
 
-    }
+    },
+    sub {
+        my $dashboard = RT::Dashboard->new( RT->SystemUser );
+        my ( $ret, $msg ) = $dashboard->Save(
+            Name    => 'RTIR Homepage',
+            Privacy => join( '-', ref( RT->System ), RT->System->Id ),
+        );
+
+        if ($ret) {
+            my $panes = {
+                body => [
+                    {   pane         => 'body',
+                        portlet_type => 'component',
+                        component    => '/RTIR/Elements/NewReports',
+                        description  => '/RTIR/Elements/NewReports',
+                        path         => '/RTIR/Elements/NewReports',
+                    },
+                    {   pane         => 'body',
+                        portlet_type => 'component',
+                        component    => '/RTIR/Elements/UserDueIncidents',
+                        description  => '/RTIR/Elements/UserDueIncidents',
+                        path         => '/RTIR/Elements/UserDueIncidents',
+                    },
+                    {   pane         => 'body',
+                        portlet_type => 'component',
+                        component    => '/RTIR/Elements/NobodyDueIncidents',
+                        description  => '/RTIR/Elements/NobodyDueIncidents',
+                        path         => '/RTIR/Elements/NobodyDueIncidents',
+                    },
+                    {   pane         => 'body',
+                        portlet_type => 'component',
+                        component    => '/RTIR/Elements/DueIncidents',
+                        description  => '/RTIR/Elements/DueIncidents',
+                        path         => '/RTIR/Elements/DueIncidents',
+                    },
+                ],
+                sidebar => [
+                    {   pane         => 'sidebar',
+                        portlet_type => 'component',
+                        component    => '/RTIR/Elements/WorkWithConstituency',
+                        description  => '/RTIR/Elements/WorkWithConstituency',
+                        path         => '/RTIR/Elements/WorkWithConstituency',
+                    },
+                    {   pane         => 'sidebar',
+                        portlet_type => 'component',
+                        component    => '/RTIR/Elements/QueueSummary',
+                        description  => '/RTIR/Elements/QueueSummary',
+                        path         => '/RTIR/Elements/QueueSummary',
+                    },
+                    {   pane         => 'sidebar',
+                        portlet_type => 'component',
+                        component    => 'RefreshHomepage',
+                        description  => 'RefreshHomepage',
+                        path         => '/Elements/RefreshHomepage',
+                    },
+                ]
+            };
+
+            # fill content
+            my ( $ret, $msg ) = $dashboard->Update( Panes => $panes );
+            if ( !$ret ) {
+                RT->Logger->error("Couldn't update content for dashboard Homepage: $msg");
+            }
+
+            ( $ret, $msg ) = RT->System->SetAttribute(
+                'Name'        => 'RTIRDefaultDashboard',
+                'Description' => 'RTIR Default Dashboard',
+                'Content'     => $dashboard->Id,
+            );
+            if ( !$ret ) {
+                RT->Logger->error("Couldn't set RTIRDefaultDashboard: $msg");
+            }
+        }
+        else {
+            RT->Logger->error("Couldn't create dashboard RTIR Homepage: $msg");
+        }
+    },
 );
 
diff --git a/etc/upgrade/5.0.2/content b/etc/upgrade/5.0.2/content
new file mode 100644
index 00000000..4dc54058
--- /dev/null
+++ b/etc/upgrade/5.0.2/content
@@ -0,0 +1,146 @@
+use strict;
+use warnings;
+
+our @ScripConditions;
+
+our @Final = (
+    sub {
+        RT->Logger->debug("Converting homepages to dashboards");
+        my $attrs = RT::Attributes->new( RT->SystemUser );
+        $attrs->Limit( FIELD => 'Name', VALUE => [ 'Pref-RTIR_HomepageSettings', 'RTIR_HomepageSettings' ], OPERATOR => 'IN' );
+    OUTER: while ( my $attr = $attrs->Next ) {
+            my $attr_id = $attr->Id;
+            my $object  = $attr->Object;
+            my $content = $attr->Content;
+
+            if ( $object && ( $object->isa('RT::User') || $object->isa('RT::System') ) && $content ) {
+                my $dashboard = RT::Dashboard->new( RT->SystemUser );
+                my $panes     = {};
+
+                for my $pane ( sort keys %$content ) {
+                    my $list = $content->{$pane} or next;
+                    for my $entry (@$list) {
+                        my $new_entry = { pane => $pane };
+                        if ( $entry->{type} eq 'system' ) {
+                            if ( my $name = $entry->{name} ) {
+                                my ($search)
+                                    = RT::System->new( RT->SystemUser )->Attributes->Named( 'Search - ' . $name );
+
+                                # Check user created system searches
+                                if ( !$search ) {
+                                    my (@searches)
+                                        = RT::System->new( RT->SystemUser )->Attributes->Named('SavedSearch');
+                                    for my $custom (@searches) {
+                                        if ( $custom->Description eq $entry->{name} ) {
+                                            $search = $custom;
+                                            last;
+                                        }
+                                    }
+                                }
+
+                                if ( $search ) {
+                                    $new_entry->{portlet_type} = 'search';
+                                    $new_entry->{id}           = $search->Id;
+                                    $new_entry->{description}  = "Saved Search: $name";
+                                    $new_entry->{privacy}      = 'RT::System-1';
+                                }
+                                else {
+                                    RT->Logger->warning(
+                                        "System search $name in attribute #$attr_id not found, skipping");
+                                    next;
+                                }
+                            }
+                            else {
+                                RT->Logger->warning("Missing system search name in attribute #$attr_id, skipping");
+                                next;
+                            }
+                        }
+                        elsif ( $entry->{type} eq 'saved' ) {
+                            if ( my $name = $entry->{name} ) {
+                                if ( $name =~ /(.+)-SavedSearch-(\d+)/ ) {
+                                    $new_entry->{privacy}      = $1;
+                                    $new_entry->{id}           = $2;
+                                    $new_entry->{portlet_type} = 'search';
+                                    my $search = RT::Attribute->new( RT->SystemUser );
+                                    $search->Load( $new_entry->{id} );
+                                    if ( $search->Id ) {
+                                        $new_entry->{description} = "Saved Search: " . $search->Description;
+                                    }
+                                    else {
+                                        RT->Logger->warning(
+                                            "Saved search $name in attribute #$attr_id not found, skipping");
+                                        next;
+                                    }
+                                }
+                                else {
+                                    RT->Logger->warning(
+                                        "System search $name in attribute #$attr_id not found, skipping");
+                                    next;
+                                }
+                            }
+                            else {
+                                RT->Logger->warning("Missing system search name in attribute #$attr_id, skipping");
+                                next;
+                            }
+                        }
+                        elsif ( $entry->{type} eq 'component' ) {
+                            $new_entry->{portlet_type} = 'component';
+                            $new_entry->{component}    = $entry->{name};
+                            $new_entry->{description}  = $entry->{name};
+                            $new_entry->{path}         = $entry->{name} =~ m{^/} ? $entry->{name} : "/Elements/$entry->{name}";
+                        }
+                        else {
+                            RT->Logger->warning("Unsupported type $entry->{type} in attribute #$attr_id, skipping");
+                            next;
+                        }
+                        push @{$panes->{$pane}}, $new_entry;
+                    }
+                }
+
+                $RT::Handle->BeginTransaction;
+                my %new_values = (
+                    'Name'        => 'Dashboard',
+                    'Description' => 'RTIR Homepage',
+                    'Content'     => { Panes => $panes },
+                );
+
+                for my $field ( sort keys %new_values ) {
+                    my $method = "Set$field";
+                    my ( $ret, $msg ) = $attr->$method( $new_values{$field} );
+                    if ( !$ret ) {
+                        RT->Logger->error("Couldn't update $field of attribute #$attr_id: $msg");
+                        $RT::Handle->Rollback;
+                        next OUTER;
+                    }
+                }
+
+                my ( $id, $msg ) = $object->SetAttribute(
+                    'Name'        => $object->isa('RT::User') ? 'Pref-RTIRDefaultDashboard' : 'RTIRDefaultDashboard',
+                    'Description' => 'RTIR Default Dashboard',
+                    'Content'     => $attr_id,
+                );
+                if ($id) {
+                    $RT::Handle->Commit;
+                }
+                else {
+                    RT->Logger->error("Couldn't set DefaultDashboard to $id for attribute #$attr_id: $msg");
+                    $RT::Handle->Rollback;
+                }
+            }
+        }
+    },
+    sub {
+        my $attrs = RT::Attributes->new( RT->SystemUser );
+        $attrs->Limit(
+            FIELD    => 'Name',
+            VALUE    => [ 'RTIRDefaultDashboard', 'Pref-RTIRDefaultDashboard' ],
+            OPERATOR => 'IN',
+        );
+        while ( my $attr = $attrs->Next ) {
+            my ( $ret, $msg ) = $attr->_SyncLinks;
+            if ( !$ret ) {
+                die "Couldn't sync links for attribute #" . $attr->id . ": $msg";
+            }
+        }
+    },
+);
diff --git a/html/RTIR/Prefs/Home.html b/html/RTIR/Prefs/Home.html
index 5c7506ec..46c1d47e 100644
--- a/html/RTIR/Prefs/Home.html
+++ b/html/RTIR/Prefs/Home.html
@@ -49,159 +49,42 @@
 <& /Elements/Tabs &>
 <& /Elements/ListActions, actions => \@results &>
 
-<form method="post" name="UpdateSearches" class="mx-auto max-width-lg">
-  <& /Widgets/SearchSelection,
-    pane_name => \%pane_name,
-    sections  => \@sections,
-    selected  => \%selected,
-    filters   => \@filters,
-  &>
-  <& /Elements/Submit, Name => "UpdateSearches", Label => loc('Save') &>
+<&|/Widgets/TitleBox, title => loc('Set RTIR Homepage'), bodyclass => "", class => "mx-auto max-width-xl" &>
+<form method="post" name="UpdateRTIRDefaultDashboard" class="mx-auto max-width-xl">
+  <div class="form-row">
+    <div class="col-12">
+      <& /Elements/SelectDashboard, Dashboards => GetDashboards( DefaultAttribute => 'RTIRDefaultDashboard' ), Name => 'RTIRDefaultDashboard', Default => $default_dashboard_id &>
+    </div>
+  </div>
 </form>
+</&>
 
 <%INIT>
 my @results;
-my $user = $session{'CurrentUser'}->UserObj;
 
-my $portlets = $user->Preferences('RTIR_HomepageSettings');
-unless ($portlets) {
-    my ($defaults) = RT::System->new($session{'CurrentUser'})->Attributes->Named('RTIR_HomepageSettings');
-    $portlets = $defaults ? $defaults->Content : {};
-}
-
-my @sections;
-my %item_for;
-
-my @components = map { type => "component", name => $_, label => loc($_) }, @{RT->Config->Get('RTIR_HomepageComponents')};
-
-$item_for{ $_->{type} }{ $_->{name} } = $_ for @components;
-
-push @sections, {
-    id    => 'components',
-    label => loc("Components"),
-    items => \@components,
-};
-
-my $sys = RT::System->new($session{'CurrentUser'});
-my @objs = ($sys);
-
-push @objs, RT::SavedSearch->new( $session{CurrentUser} )->ObjectsForLoading
-    if $session{'CurrentUser'}->HasRight( Right  => 'LoadSavedSearch',
-                                          Object => $RT::System );
-
-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) = @$_;
-
-        my $SearchType = 'Ticket';
-        if ((ref($search->Content)||'') eq 'HASH') {
-            $SearchType = $search->Content->{'SearchType'}
-                if $search->Content->{'SearchType'};
-        }
-        else {
-            $RT::Logger->debug("Search ".$search->id." ($desc) appears to have no Content");
-        }
-
-        my $item;
-        if ($object eq $sys && $SearchType eq 'Ticket') {
-            $item = { type => 'system', name => $desc, label => $loc_desc };
-        }
-        else {
-            my $oid = $object_id.'-SavedSearch-'.$search->Id;
-            $item = { type => 'saved', name => $oid, search_type => $SearchType, label => $loc_desc };
-        }
+my $default_dashboard_id = $session{'CurrentUser'}->Preferences( RTIRDefaultDashboard => 0 );
 
-        $item_for{ $item->{type} }{ $item->{name} } = $item;
-        push @items, $item;
+my ($default) = map { /^RTIRDefaultDashboard-(\d+)/ ? $1 : () } keys %ARGS;
+if ( defined $default ) {
+    my ( $ret, $msg );
+    if ( $default ) {
+        ( $ret, $msg ) = $session{CurrentUser}->SetPreferences( 'RTIRDefaultDashboard', $default );
     }
-
-    my $label = $object eq $sys           ? loc('System')
-                : $object->isa('RT::Group') ? $object->Label
-                                            : $object->Name;
-
-    push @sections, {
-        id    => $object_id,
-        label => $label,
-        items => [ sort { lc($a->{label}) cmp lc($b->{label}) } @items ],
-    };
-}
-
-my %selected;
-for my $pane (keys %$portlets) {
-    my @items;
-
-    for my $saved (@{ $portlets->{$pane} }) {
-        my $item = $item_for{ $saved->{type} }{ $saved->{name} };
-        if ($item) {
-            push @items, $item;
+    else {
+        if ( $default_dashboard_id ) {
+            ( $ret, $msg ) = $session{CurrentUser}->DeletePreferences( 'RTIRDefaultDashboard' );
         }
         else {
-            push @results, loc('Unable to find [_1] [_2]', $saved->{type}, $saved->{name});
-        }
-    }
-
-    $selected{$pane} = \@items;
-}
-
-my %pane_name = (
-    'body'    => loc('Body'),
-    'sidebar' => loc('Sidebar'),
-);
-
-my @filters = (
-    [ 'component' => loc('Components') ],
-    [ 'ticket'    => loc('Tickets') ],
-    [ 'chart'     => loc('Charts') ],
-);
-
-$m->callback(
-    CallbackName => 'Default',
-    pane_name    => \%pane_name,
-    sections     => \@sections,
-    selected     => \%selected,
-    filters      => \@filters,
-);
-
-if ($ARGS{UpdateSearches}) {
-    my $data = {
-        "panes"        => {
-            "body"    => [],
-            "sidebar" => []
-        }
-    };
-
-    foreach my $arg (qw{ body sidebar }) {
-        my $pane   = $arg;
-        my $values = $ARGS{$pane};
-
-        next unless $values;
-
-        # force value to an arrayref so we can handle both single and multiple members of each pane.
-        $values = [$values] unless ref $values;
-
-        foreach my $value ( @{$values} ) {
-            $value =~ m/^(\w+)-(.+)$/i;
-            my $type = $1;
-            my $name = $2;
-            push @{ $data->{panes}->{$pane} }, { type => $type, name => $name };
+            $ret = 1;
         }
     }
 
-    my ( $ok, $msg ) = $user->SetPreferences( 'RTIR_HomepageSettings', $data->{panes} );
-    if ( $ok ) {
-        push @results, loc("Preferences saved.");
-    }
-    else {
-        push @results, loc("Could not save preferences.");
-    }
+    push @results, $ret ? loc('Preferences saved.') : $msg;
 
     MaybeRedirectForResults(
-        Actions   => \@results,
-        Path      => "/RTIR/Prefs/Home.html",
+        Actions => \@results,
+        Path    => "/RTIR/Prefs/Home.html",
     );
 }
+
 </%INIT>
diff --git a/html/RTIR/index.html b/html/RTIR/index.html
index 5c91895e..f093682f 100644
--- a/html/RTIR/index.html
+++ b/html/RTIR/index.html
@@ -51,12 +51,6 @@
 <& /Elements/MyRT, Portlets => $portlets &>
 <%INIT>
 
-my $portlets = $session{'CurrentUser'}->Preferences('RTIR_HomepageSettings');
-unless ($portlets) {
-    my ($defaults) = RT::System->new($session{'CurrentUser'})->Attributes->Named('RTIR_HomepageSettings');
-    $portlets = $defaults ? $defaults->Content : {};
-}
-
 if ( defined $q && length $q ) {
 
     if ($q =~ /^#?(\d+)$/) {
@@ -74,6 +68,45 @@ if ( defined $q && length $q ) {
     );
 }
 
+my ($system_default) = RT::System->new($session{'CurrentUser'})->Attributes->Named('RTIRDefaultDashboard');
+my $system_default_id = $system_default ? $system_default->Content : 0;
+my $user = $session{'CurrentUser'}->UserObj;
+my $portlets;
+if ( my $dashboard_id = $user->Preferences( RTIRDefaultDashboard => $system_default_id ) ) {
+
+    # Allow any user to read system default dashboard
+    my $dashboard
+        = RT::Dashboard->new( $system_default_id == $dashboard_id ? RT->SystemUser : $session{'CurrentUser'} );
+    my ( $ok, $msg ) = $dashboard->LoadById($dashboard_id);
+    if ( !$ok ) {
+        my $user_msg = loc('Unable to load selected dashboard, it may have been deleted');
+        if ( $dashboard_id == $system_default_id ) {
+            RT->Logger->warn("Unable to load dashboard: $msg");
+            $m->out( $m->scomp( '/Elements/ListActions', actions => $user_msg ) );
+            return;
+        }
+        else {
+            my ( $ok, $sys_msg ) = $dashboard->LoadById($system_default_id);
+            if ($ok) {
+                $m->out(
+                    $m->scomp(
+                        '/Elements/ListActions',
+                        actions => [ $user_msg, loc('Setting homepage to system default RTIR homepage') ]
+                    )
+                );
+                my ( $ok, $msg ) = $user->DeletePreferences('RTIRDefaultDashboard');
+                RT->Logger->error( "Couldn't delete RTIRDefaultDashboard of user " . $user->Name . ": $msg" ) unless $ok;
+            }
+            else {
+                RT->Logger->warn("Unable to load dashboard: $msg $sys_msg");
+                $m->out( $m->scomp( '/Elements/ListActions', actions => $user_msg ) );
+                return;
+            }
+        }
+    }
+    $portlets = $dashboard->Panes;
+}
+
 my @results;
 if ( $HomeRefreshInterval ) {
     $session{'home_refresh_interval'} = $HomeRefreshInterval;

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


hooks/post-receive
-- 
rtir


More information about the rt-commit mailing list