[Rt-commit] rt branch, 4.0/reset-rt-at-a-glance, created. rt-4.0.19-65-g7d0236d
Alex Vandiver
alexmv at bestpractical.com
Thu Apr 3 18:39:26 EDT 2014
The branch, 4.0/reset-rt-at-a-glance has been created
at 7d0236dc9438009b5f45a6b79ca8e8c2c9c40f31 (commit)
- Log -----------------------------------------------------------------
commit 2898cadebedd3651e99fbdf3910f5fdba91dcf38
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Jun 21 13:11:39 2012 -0400
Add a method to remove a user preference
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 95fe9a2..20ce784 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -1390,6 +1390,28 @@ sub SetPreferences {
}
}
+=head2 DeletePreferences NAME/OBJ VALUE
+
+Delete user preferences associated with given object or name.
+
+=cut
+
+sub DeletePreferences {
+ my $self = shift;
+ my $name = _PrefName( shift );
+
+ return (0, $self->loc("No permission to set preferences"))
+ unless $self->CurrentUserCanModify('Preferences');
+
+ my $attr = RT::Attribute->new( $self->CurrentUser );
+ $attr->LoadByNameAndObject( Object => $self, Name => $name );
+ if ( $attr->Id ) {
+ return $attr->Delete;
+ }
+
+ return (0, $self->loc("Preferences were not found"));
+}
+
=head2 Stylesheet
Returns a list of valid stylesheets take from preferences.
commit f8547ece845877beef06102b7fc074b8dbd00f76
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Jun 21 13:38:03 2012 -0400
Add a "Reset" button to configuration of homepage portlets
This allows the user to reset to the search's defaults.
diff --git a/share/html/Prefs/Search.html b/share/html/Prefs/Search.html
index bb52a62..92b44fb 100644
--- a/share/html/Prefs/Search.html
+++ b/share/html/Prefs/Search.html
@@ -68,6 +68,14 @@
</form>
+<&|/Widgets/TitleBox, title => loc("Reset") &>
+<form method="post" name="ResetSearchOptions" action="Search.html">
+<input type="hidden" name="Reset" value="1" />
+<input type="hidden" name="name" value="<%$ARGS{name}%>" class="hidden" />
+<input type="submit" class="button" name="ResetSearchOptions" value="<% loc('Reset to default') %>">
+</form>
+</&>
+
<%INIT>
my @actions;
my $title = loc("Customize").' ';
@@ -81,6 +89,13 @@ Abort('No search specified')
my $search = $class->new ($session{'CurrentUser'});
$search->LoadById ($id);
+
+# If we are resetting prefs, do so before attempting to load them
+if ($ARGS{'Reset'}) {
+ my ($ok, $msg) = $session{'CurrentUser'}->UserObj->DeletePreferences($ARGS{name});
+ push @actions, $ok ? loc('Preferences saved.') : $msg;
+}
+
$title .= loc (RT::SavedSearch->EscapeDescription($search->Description), loc ('"N"'));
my $user = $session{'CurrentUser'}->UserObj;
my $SearchArg = $user->Preferences($search, $search->Content);
commit b3ddad9412dfe0bc5713ee367e49ac933d8e44b2
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Jun 21 13:58:32 2012 -0400
Remove HomepageSettings preference on "reset" to pick up global defaults
Ensure that the global settings for "RT at a Glance" are taken when a
user resets their preferences. Previously, the setting was simply set
to an empty hash, which meant that the global defaults were not applied.
This causes the reset button to revert current session to the current
state of the global configuration, which is thereafter cached for the
duration of the session in $session{'my_rt_portlets'}.
diff --git a/share/html/Prefs/MyRT.html b/share/html/Prefs/MyRT.html
index a595ccf..7083dea 100644
--- a/share/html/Prefs/MyRT.html
+++ b/share/html/Prefs/MyRT.html
@@ -97,8 +97,12 @@ if ( $ARGS{'UpdateSummaryRows'} ) {
$ARGS{'SummaryRows'} ||= $user->Preferences('SummaryRows', RT->Config->Get('DefaultSummaryRows'));
if ($ARGS{Reset}) {
- my ($ok, $msg) = $user->SetPreferences('HomepageSettings', {});
- push @results, $ok ? loc('Preferences saved.') : $msg;
+ for my $pref_name ('HomepageSettings', 'SummaryRows') {
+ next unless $user->Preferences($pref_name);
+ my ($ok, $msg) = $user->DeletePreferences($pref_name);
+ push @results, $msg unless $ok;
+ }
+ push @results, loc('Preferences saved.') unless @results;
delete $session{'my_rt_portlets'};
}
commit 7d0236dc9438009b5f45a6b79ca8e8c2c9c40f31
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Jun 21 14:10:19 2012 -0400
Remove the session cache of the "RT at a Glance" portlet lists
The initial commit of "RT at a Glance" configurability (8b8e90d) added a
caching layer in the session, rather than hit the Attribute for the
preferences on each request. Remove this caching, in order to ensure
that users who have not overridden the preference always get the most
recent global configuration. This comes at the cost of an extra 1-2
Attribute queries on the front page, but as these are well-indexed, this
negligable performance impact seems worth it to obey the principle of
least surprise when the admin updates the global configuration.
diff --git a/share/html/Elements/MyRT b/share/html/Elements/MyRT
index c59ec1c..84db949 100644
--- a/share/html/Elements/MyRT
+++ b/share/html/Elements/MyRT
@@ -67,12 +67,10 @@
my %allowed_components = map {$_ => 1} @{RT->Config->Get('HomepageComponents')};
my $user = $session{'CurrentUser'}->UserObj;
-$Portlets ||= $session{'my_rt_portlets'};
+$Portlets ||= $user->Preferences('HomepageSettings');
unless ( $Portlets ) {
- my ($default_portlets) = RT::System->new($session{'CurrentUser'})->Attributes->Named('HomepageSettings');
- $Portlets = $session{'my_rt_portlets'} = $user->Preferences(
- HomepageSettings => $default_portlets? $default_portlets->Content: {},
- );
+ my ($defaults) = RT::System->new($session{'CurrentUser'})->Attributes->Named('HomepageSettings');
+ $Portlets = $defaults ? $defaults->Content : {};
}
$m->callback( CallbackName => 'MassagePortlets', Portlets => $Portlets );
diff --git a/share/html/Prefs/MyRT.html b/share/html/Prefs/MyRT.html
index 7083dea..288df0b 100644
--- a/share/html/Prefs/MyRT.html
+++ b/share/html/Prefs/MyRT.html
@@ -103,16 +103,13 @@ if ($ARGS{Reset}) {
push @results, $msg unless $ok;
}
push @results, loc('Preferences saved.') unless @results;
- delete $session{'my_rt_portlets'};
}
-unless (exists $session{'my_rt_portlets'}) {
- my ($default_portlets) = RT::System->new($session{'CurrentUser'})->Attributes->Named('HomepageSettings');
- my $portlets = $default_portlets ? $default_portlets->Content : {};
-
- $session{'my_rt_portlets'} = $user->Preferences('HomepageSettings', $portlets);
+my $portlets = $user->Preferences('HomepageSettings');
+unless ($portlets) {
+ my ($defaults) = RT::System->new($session{'CurrentUser'})->Attributes->Named('HomepageSettings');
+ $portlets = $defaults ? $defaults->Content : {};
}
-my $portlets = $session{'my_rt_portlets'};
my %seen;
my @items = map ["component-$_", loc($_)], grep !$seen{$_}++, @{RT->Config->Get('HomepageComponents')};
@@ -161,7 +158,6 @@ my @panes = $m->comp(
my ( $conf, $pane ) = @_;
my ($ok, $msg) = $user->SetPreferences( 'HomepageSettings', $conf );
push @results, $ok ? loc('Preferences saved for [_1].', $pane) : $msg;
- delete $session{'my_rt_portlets'};
}
);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list