[Rt-commit] rt branch, 4.2/migrate-old-dashboards-in-menu, created. rt-4.1.19-32-gae0c693
? sunnavy
sunnavy at bestpractical.com
Fri Aug 23 10:37:53 EDT 2013
The branch, 4.2/migrate-old-dashboards-in-menu has been created
at ae0c6931801a2353f6918ae890b6e2e46693bf4b (commit)
- Log -----------------------------------------------------------------
commit ae0c6931801a2353f6918ae890b6e2e46693bf4b
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..cf83f1c
--- /dev/null
+++ b/etc/upgrade/4.1.21/content
@@ -0,0 +1,61 @@
+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;
+}
+
+ at 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