[Rt-commit] rt branch, 4.0/sanity-check-stylesheets, updated. rt-4.0.2-62-g143c21c

Jason May jasonmay at bestpractical.com
Wed Sep 21 17:49:27 EDT 2011


The branch, 4.0/sanity-check-stylesheets has been updated
       via  143c21c27c51dcc5982d6a09611913ebf314ce5e (commit)
       via  daf95c016a59f7554e6a208f25392d76f7c791e3 (commit)
       via  b2b90c6a8e4a745f3515578318141106f8db4073 (commit)
       via  a0e17a18ad6263dbb63aa56678ad0bfb847c7ab0 (commit)
      from  04378a44db8be6cdd421a6b5dfc835b6ca93ec4c (commit)

Summary of changes:
 .../upgrade/sanity-check-stylesheets.pl            |   73 ++++++++------------
 lib/RT/Config.pm                                   |   20 ++++++
 lib/RT/User.pm                                     |   25 +++++++
 share/html/Elements/Header                         |   35 +++-------
 4 files changed, 84 insertions(+), 69 deletions(-)
 copy lib/RT/Classes.pm => etc/upgrade/sanity-check-stylesheets.pl (66%)

- Log -----------------------------------------------------------------
commit a0e17a18ad6263dbb63aa56678ad0bfb847c7ab0
Author: Jason May <jasonmay at bestpractical.com>
Date:   Mon Sep 19 17:07:38 2011 -0400

    Factor style-checking to the user for easier reuse in the future.
    
    As part of the factoring, all comp roots provided by Mason itself is
    checked instead of just the standard and local roots.

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 87e3130..9eac350 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -1320,6 +1320,31 @@ sub SetPreferences {
     }
 }
 
+=head2 Stylesheet
+
+Returns a list of valid stylesheets take from preferences.
+
+=cut
+
+sub Stylesheet {
+    my $self = shift;
+    my @roots = @_;
+
+    my $style = RT->Config->Get('WebDefaultStylesheet', $self->CurrentUser);
+
+
+    my @css_paths = map { $_ . '/NoAuth/css' } @roots;
+
+    for my $css_path (@css_paths) {
+        if (-d "$css_path/$style") {
+            return $style
+        }
+    }
+
+    # Fall back to the system stylesheet.
+    return RT->Config->Get('WebDefaultStylesheet');
+}
+
 =head2 WatchedQueues ROLE_LIST
 
 Returns a RT::Queues object containing every queue watched by the user.
diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index 830f4ee..83b22de 100755
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -120,31 +120,14 @@ $id =~ s|index$||g
     if $id ne 'index';
 $id =~ s|-$||g;
 
-sub style_exists {
-    my $style = shift;
-
-    my @css_paths = (
-        $RT::MasonComponentRoot . '/NoAuth/css',
-        $RT::MasonLocalComponentRoot . '/NoAuth/css',
-    );
-
-    for my $css_path (@css_paths) {
-        if (-d "$css_path/$style") {
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-my $style = RT->Config->Get( 'WebDefaultStylesheet', $session{'CurrentUser'} );
-
-unless (style_exists($style)) {
-    my $system_style = RT->Config->Get('WebDefaultStylesheet');
-    if (style_exists($system_style)) {
-        $style = $system_style;
-    }
-}
+my @roots = map $_->[1],
+    $HTML::Mason::VERSION <= 1.28
+        ? $m->interp->resolver->comp_root_array
+        : $m->interp->comp_root_array;
+
+my $style = $session{'CurrentUser'}
+          ? $session{'CurrentUser'}->Stylesheet(@roots)
+          : RT->Config->Get('WebDefaultStylesheet');
 
 my @css_files;
 if ( RT->Config->Get('DevelMode') ) {

commit b2b90c6a8e4a745f3515578318141106f8db4073
Author: Jason May <jasonmay at bestpractical.com>
Date:   Tue Sep 20 11:30:51 2011 -0400

    Use the sanity-checked style pref in the body

diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index 83b22de..235740a 100755
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -79,7 +79,7 @@
 <& HeaderJavascript, focus => $Focus, onload => $onload, RichText => $RichText &>
 % }
 
-% my $stylesheet_plugin = "/NoAuth/css/". RT->Config->Get( 'WebDefaultStylesheet', $session{'CurrentUser'} )."/InHeader";
+% my $stylesheet_plugin = "/NoAuth/css/".$style."/InHeader";
 % if ($m->comp_exists($stylesheet_plugin) ) {
 <& $stylesheet_plugin &>
 % }
@@ -96,7 +96,7 @@
 % $m->callback( %ARGS, CallbackName => 'Head' );
 
 </head>
-  <body class="<% lc RT->Config->Get('WebDefaultStylesheet', $session{'CurrentUser'}) %>" <% $id && qq[id="comp-$id"] |n %>>
+  <body class="<% lc $style %>" <% $id && qq[id="comp-$id"] |n %>>
 
 % if ($ShowBar) {
 <& /Elements/Logo, %ARGS &>

commit daf95c016a59f7554e6a208f25392d76f7c791e3
Author: Jason May <jasonmay at bestpractical.com>
Date:   Wed Sep 21 16:19:07 2011 -0400

    Add a post load check for non-existent stylesheets
    
    If someone upgrades while using 3.5-default or removes a plugin with a
    custom stylesheet, styles decided by the system aren't sanity-checked.

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 50cb0c8..ca6d91d 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -198,6 +198,26 @@ our %META = (
             # XXX: we need support for 'get values callback'
             Values => [qw(web2 aileron ballard)],
         },
+        PostLoadCheck => sub {
+            my $self = shift;
+            my $value = $self->Get('WebDefaultStylesheet');
+
+            my @comp_roots = (
+                $RT::MasonLocalComponentRoot,
+                (map { $_->ComponentRoot } @{RT->Plugins}),
+                $RT::MasonComponentRoot,
+            );
+            for my $comp_root (@comp_roots) {
+                return if -d $comp_root.'/NoAuth/css/'.$value;
+            }
+
+            $RT::Logger->warning(
+                "The default stylesheet ($value) does not exist in this instance of RT. "
+              . "Defaulting to aileron."
+            );
+
+            $self->Set('WebDefaultStylesheet', 'aileron');
+        },
     },
     UseSideBySideLayout => {
         Section => 'Ticket composition',

commit 143c21c27c51dcc5982d6a09611913ebf314ce5e
Author: Jason May <jasonmay at bestpractical.com>
Date:   Wed Sep 21 17:49:47 2011 -0400

    Add an upgrade script to sanitize stylesheet preferences for all users

diff --git a/etc/upgrade/sanity-check-stylesheets.pl b/etc/upgrade/sanity-check-stylesheets.pl
new file mode 100644
index 0000000..1bdafed
--- /dev/null
+++ b/etc/upgrade/sanity-check-stylesheets.pl
@@ -0,0 +1,91 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+#                                          <sales at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+use strict;
+use warnings;
+
+use RT;
+RT::LoadConfig();
+RT->Config->Set('LogToScreen' => 'debug');
+RT::Init();
+
+$| = 1;
+
+use RT::Users;
+my $users = RT::Users->new( $RT::SystemUser );
+$users->UnLimit();
+
+my @comp_roots = (
+    $RT::MasonLocalComponentRoot,
+    (map { $_->ComponentRoot} @{RT->Plugins}),
+    $RT::MasonComponentRoot,
+);
+my %comp_root_check_cache;
+sub stylesheet_exists {
+    my $stylesheet = shift;
+
+    return $comp_root_check_cache{$stylesheet}
+        if exists $comp_root_check_cache{$stylesheet};
+
+    for my $comp_root (@comp_roots) {
+        return ++$comp_root_check_cache{$stylesheet}
+            if -d "$comp_root/NoAuth/css/$stylesheet";
+    }
+
+    return $comp_root_check_cache{$stylesheet} = 0;
+}
+
+my $system_stylesheet = RT->Config->Get('WebDefaultStylesheet');
+
+while (my $u = $users->Next) {
+    my $stylesheet = RT->Config->Get('WebDefaultStylesheet', $u);
+    unless (stylesheet_exists $stylesheet) {
+        my $prefs = $u->Preferences($RT::System);
+        $prefs->{WebDefaultStylesheet} = $system_stylesheet;
+        $u->SetPreferences($RT::System, $prefs);
+    }
+}

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


More information about the Rt-commit mailing list