- 0 Talk
-
BasicVsAdvancedInterface
This feature provides a simple way to offer privileged users a basic interface (i.e. the SelfService interface) or an advanced interface (the default RT at a Glance interface). Non-privileged users will still only ever see the SelfService screens. A cookie keeps track of the user's preference. This patch was created against 3.6.3 source.
There are two files to patch, Elements/Header and SelfService/Elements/Header, as well as two new files (Elements/UIPrefCookieCheck and Elements/UIPrefSwitchView). To install the feature:
- create the directory <rt-root>/local/html/Elements, if needed
- copy the file <rt-root>/share/html/Elements/Header to <rt-root>/local/html/Elements, if it does not already exist
- create the directory <rt-root>/local/html/SelfService/Elements, if needed
- copy the file <rt-root>/share/html/SelfService/Elements/Header] to <rt-root>/local/html/SelfService/Elements, if it does not already exist
- create the file <rt-root>/local/html/Elements/UIPrefCookieCheck, with the contents shown below
- create the file <rt-root>/local/html/Elements/UIPrefSwitchView, with the contents shown below
- create the file <rt-root>/UIPref.diff, with the contents shown below
- apply the patch (assuming
<rt-root> == /opt/rt3):
$ cd /opt/rt3 $ patch -p0 <UIPref.diff
<rt-root>/local/html/Elements/UIPrefCookieCheck
Edit
<%INIT>
#***** fetch the cookie *****
my(%cookies) = CGI::Cookie->fetch();
my($cookiename) = "RT_USER_UI_PREF_" . $RT::rtname . "." . $ENV{'SERVER_PORT'};
my($cookie) = $cookies{$cookiename};
#***** default to basic mode *****
my($mode) = 'Basic';
$mode = $cookie->value() if $cookie;
#***** if I have no cookie, set a cookie to the default *****
if (! $cookie) {
my($newcookie) = new CGI::Cookie(
-name => $cookiename,
-value => $mode,
-path => $RT::WebPath,
-secure => ($RT::WebSecureCookies ? 1 :0)
-expires => '+1M',
);
$r->headers_out->{'Set-Cookie'} = $newcookie->as_string;
}
if (($mode eq 'Basic') && (! $viaSelfService)) {
#***** I want basic, but was called under advanced *****
$m->comp("/SelfService/index.html", %ARGS, SkipUIPrefCookieCheck => !0);
$m->abort();
}
elsif (($mode eq 'Advanced') && ($viaSelfService)) {
#***** I want advanced, but was called under basic *****
$m->comp("/index.html", %ARGS, SkipUIPrefCookieCheck => !0);
$m->abort();
}
</%INIT>
<%ARGS>
$viaSelfService => undef
</%ARGS>
<rt-root>/local/html/Elements/UIPrefSwitchView
Edit
<%INIT>
#***** fetch the cookie *****
my(%cookies) = CGI::Cookie->fetch();
my($cookiename) = "RT_USER_UI_PREF_" . $RT::rtname . "." . $ENV{'SERVER_PORT'};
my($cookie) = $cookies{$cookiename};
#***** default to basic mode *****
my($mode) = 'Basic';
$mode = $cookie->value() if $cookie;
my($newmode) = ($mode eq 'Basic' ? 'Advanced' : 'Basic');
my($newcookie) = new CGI::Cookie(
-name => $cookiename,
-value => $newmode,
-path => $RT::WebPath,
-secure => ($RT::WebSecureCookies ? 1 :0),
-expires => '+1M',
);
$r->headers_out->{'Set-Cookie'} = $newcookie->as_string;
if ($newmode eq 'Basic') {
RT::Interface::Web::Redirect($RT::WebURL . "SelfService/index.html");
}
else {
RT::Interface::Web::Redirect($RT::WebURL . "index.html");
}
$m->abort();
</%INIT>
<%ARGS>
</%ARGS>
<rt-root>/UIPref.diff
Edit
--- share/html/Elements/Header 2007-02-14 13:10:35.000000000 -0500
+++ local/html/Elements/Header 2007-02-14 13:12:43.000000000 -0500
@@ -92,6 +92,14 @@
% if ($session{'CurrentUser'}->HasRight( Right => 'ModifySelf', Object => $RT::System )) {
| <a href="<%$RT::WebPath%><%$Prefs%>"><&|/l&>Preferences</&></a>
% }
+% if ($session{'CurrentUser'}->Privileged) {
+% if ($viaSelfService) {
+ | <a href="<%$RT::WebPath%>/Elements/UIPrefSwitchView"><&|/l&>Advanced</&></a>
+% }
+% else {
+ | <a href="<%$RT::WebPath%>/Elements/UIPrefSwitchView"><&|/l&>Basic</&></a>
+% }
+% }
% } else {
<&|/l&>Not logged in.</&>
% }
@@ -104,6 +112,11 @@
% }
<%INIT>
+# check the UI Pref cookie unless we've done so already
+if (($session{'CurrentUser'}) && ($session{'CurrentUser'}->Privileged) && (! $SkipUIPrefCookieCheck)) {
+ $m->comp("/Elements/UIPrefCookieCheck", %ARGS);
+}
+
$r->headers_out->{'Pragma'} = 'no-cache';
$r->headers_out->{'Cache-control'} = 'no-cache';
@@ -128,4 +141,7 @@
$URL => undef
$RSSAutoDiscovery => undef
$onload => undef
+$viaSelfService => undef
+$SkipUIPrefCookieCheck => undef
</%ARGS>
--- share/html/SelfService/Elements/Header 2007-02-14 13:11:09.000000000 -0500
+++ local/html/SelfService/Elements/Header 2007-02-14 13:12:03.000000000 -0500
@@ -43,5 +43,5 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<& /Elements/Header, %ARGS, Prefs => '/SelfService/Prefs.html' &>
+<& /Elements/Header, %ARGS, Prefs => '/SelfService/Prefs.html', viaSelfService => !0 &>
<& /SelfService/Elements/Tabs, %ARGS &>
If you find any problems with it, let me know -- JoeCasadonte