[Rt-commit] rt branch, 4.2/migrate-old-dashboards-in-menu, created. rt-4.1.19-32-g31fb32b

? sunnavy sunnavy at bestpractical.com
Sat Aug 24 20:42:38 EDT 2013


The branch, 4.2/migrate-old-dashboards-in-menu has been created
        at  31fb32bda8acfc90cc01b50490ca8d91469b046f (commit)

- Log -----------------------------------------------------------------
commit 31fb32bda8acfc90cc01b50490ca8d91469b046f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Aug 23 22:31:46 2013 +0800

    populate existing dashboards in menu on 4.0
    
    to avoid user confusion of "missing dashboards in menu".
    
    see also #24564

diff --git a/etc/upgrade/4.1.21/content b/etc/upgrade/4.1.21/content
new file mode 100644
index 0000000..dbf75c7
--- /dev/null
+++ b/etc/upgrade/4.1.21/content
@@ -0,0 +1,64 @@
+use strict;
+use warnings;
+
+sub dashboards_for_object {
+    my $object = shift;
+    my $user   = shift;
+    my %dashboards;
+    my $privacy = RT::Dashboard->_build_privacy($object);
+
+    while ( my $attr = $object->Attributes->Next ) {
+        if ( $attr->Name =~ /^Dashboard\b/ ) {
+            my $dashboard = RT::Dashboard->new($user);
+            my ( $ok, $msg ) = $dashboard->Load( $privacy, $attr->id );
+            next unless $ok;
+
+            if ( $object->isa('RT::System') ) {
+                push @{ $dashboards{system} }, $dashboard;
+            }
+            elsif ( $object->isa('RT::User') ) {
+                push @{ $dashboards{personal} }, $dashboard;
+            }
+            elsif ( $object->isa('RT::Group') ) {
+                push @{ $dashboards{group}{ $object->Name } }, $dashboard;
+            }
+        }
+    }
+    return \%dashboards;
+}
+
+our @Final = (
+    sub {
+        my $users = RT::Users->new( RT->SystemUser );
+        $users->LimitToPrivileged();
+        while ( my $user = $users->Next ) {
+            my @objs = RT::Dashboard->new($user)->ObjectsForLoading( IncludeSuperuserGroups => 0 );
+
+            my %dashboard_map;
+
+            for my $object (@objs) {
+                my $dashboards = dashboards_for_object( $object, $user );
+                push @{ $dashboard_map{$_} }, @{ $dashboards->{$_} || [] } for qw/personal system/;
+
+                push @{ $dashboard_map{group}{$_} }, @{ $dashboards->{group}{$_} }
+                    for keys %{ $dashboards->{group} || {} };
+            }
+
+            my @dashboards = (
+                ( sort { $a->Id <=> $b->Id } @{ $dashboard_map{personal} || [] } ),
+                ( sort { $a->Id <=> $b->Id } @{ $dashboard_map{system}   || [] } ),
+
+                map {
+                    sort { $a->Id <=> $b->Id }
+                        @{ $dashboard_map{group}{$_} }
+                    }
+                    keys %{ $dashboard_map{group} || {} },
+            );
+
+            splice @dashboards, 7 if @dashboards > 7;
+            @dashboards = map { $_->id } @dashboards;
+            my ( $ret, $msg ) = $user->SetPreferences( 'DashboardsInMenu', { dashboards => \@dashboards } );
+            RT->Logger->error( $msg ) unless $ret;
+        }
+    },
+);

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


More information about the Rt-commit mailing list