[Rt-commit] rt branch, 4.0/better-userlogo-caching, created. rt-4.0.0rc6-19-g92ecb04
Kevin Falcone
falcone at bestpractical.com
Wed Mar 9 11:42:31 EST 2011
The branch, 4.0/better-userlogo-caching has been created
at 92ecb043fbab6ecf8c7dd901443af21b4df8aad9 (commit)
- Log -----------------------------------------------------------------
commit 92ecb043fbab6ecf8c7dd901443af21b4df8aad9
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Mar 3 11:45:35 2011 -0500
Improve custom user logo caching with the same MD5 trick JS/CSS uses
Bad caching here is more painful than with the JS/CSS because it's an
easy, user-changeable item that looks like a bug. It affects end users
of the system since they won't see the logo change or know to force
refresh.
The dhandler serves up the current user logo, if we have one, regardless
of the url after /NoAuth/Helpers/CustomLogo/. Users of release
candidates who uploaded a logo won't experience a broken logo after
upgrade because their attribute doesn't have the hash key.
This commit also refactors /Admin/Global/Theme.html to display the logo
using /Elements/Logo as well to avoid code duplication. A pleasant
side-effect is that the default BPS logo shows up as the current logo
when there is no user logo; previously it was just blank.
diff --git a/share/html/Admin/Global/Theme.html b/share/html/Admin/Global/Theme.html
index 23bd7ce..0d72300 100644
--- a/share/html/Admin/Global/Theme.html
+++ b/share/html/Admin/Global/Theme.html
@@ -56,9 +56,7 @@
<div id="simple-customize">
<div id="upload-logo">
<h2>Logo</h2>
-% if ($imgdata) {
- <img src="<% RT->Config->Get('WebPath') %>/NoAuth/Helpers/CustomLogo?<% time() %>" />
-% }
+ <& /Elements/Logo, id => 'logo-theme-editor', ShowName => 0 &>
<form method="POST" enctype="multipart/form-data">
<label for="logo-upload"><&|/l&>Upload a new logo</&>:</label>
<input type="file" name="logo-upload" id="logo-upload" /><br />
@@ -187,6 +185,7 @@ unless ($session{'CurrentUser'}->HasRight( Object=> RT->System, Right => 'SuperU
}
require JSON;
+use Digest::MD5 'md5_hex';
my $text_threshold = 0.6;
my @results;
@@ -197,7 +196,9 @@ if (my $file_hash = _UploadedFile( 'logo-upload' )) {
Description => "User-provided logo",
Content => {
type => $file_hash->{ContentType},
- data => $file_hash->{LargeContent} } );
+ data => $file_hash->{LargeContent},
+ hash => md5_hex($file_hash->{LargeContent}),
+ } );
push @results, loc("Unable to set UserLogo: [_1]", $msg) unless $id;
$imgdata = $file_hash->{LargeContent};
diff --git a/share/html/Elements/Logo b/share/html/Elements/Logo
index 8454c24..a6e1719 100644
--- a/share/html/Elements/Logo
+++ b/share/html/Elements/Logo
@@ -45,10 +45,10 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<div id="logo">
-% if ($use_user_logo) {
+<div id="<% $id %>">
+% if ($user_logo) {
<a href="<%$ARGS{'LogoLinkURL'}||RT->Config->Get('LogoLinkURL')%>"><img
- src="<% RT->Config->Get('WebPath') %>/NoAuth/Helpers/CustomLogo"
+ src="<% RT->Config->Get('WebPath') %>/NoAuth/Helpers/CustomLogo/<% $user_logo->Content->{'hash'} %>"
alt="<%loc($ARGS{'LogoAltText'}||RT->Config->Get('LogoAltText'))%>" /></a>
% } else {
<a href="<%$ARGS{'LogoLinkURL'}||RT->Config->Get('LogoLinkURL')%>"><img
@@ -68,10 +68,11 @@ if ( exists $ARGS{'show_name'} ) {
}
use Scalar::Util qw(blessed);
-my $use_user_logo = blessed $RT::System ? $RT::System->FirstAttribute('UserLogo') : 0;
+my $user_logo = blessed $RT::System ? $RT::System->FirstAttribute('UserLogo') : undef;
</%INIT>
<%ARGS>
$ShowName => 1
$Name => undef
+$id => 'logo'
</%ARGS>
diff --git a/share/html/NoAuth/Helpers/CustomLogo b/share/html/NoAuth/Helpers/CustomLogo/dhandler
similarity index 90%
rename from share/html/NoAuth/Helpers/CustomLogo
rename to share/html/NoAuth/Helpers/CustomLogo/dhandler
index ccef9de..2a2f8d7 100644
--- a/share/html/NoAuth/Helpers/CustomLogo
+++ b/share/html/NoAuth/Helpers/CustomLogo/dhandler
@@ -46,13 +46,16 @@
%#
%# END BPS TAGGED BLOCK }}}
<%INIT>
-RT::Interface::Web::StaticFileHeaders();
if ( my $attr = $RT::System->FirstAttribute('UserLogo') ) {
+ # The extra path in the url doesn't matter, we always want to serve the
+ # latest logo if we have one.
+ RT::Interface::Web::StaticFileHeaders();
my $content = $attr->Content;
- $r->content_type($content->{type}) ;
+ $r->content_type( $content->{type} );
$m->out( $content->{data} );
- $m->abort;
}
-# XXX: 404
-
+else {
+ # 404
+ return $m->decline;
+}
</%INIT>
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list