[Rt-commit] rt branch, 4.0/reset-rt-at-a-glance, created. rt-4.0.4-282-gee1277f

Alex Vandiver alexmv at bestpractical.com
Thu Jun 21 14:50:48 EDT 2012


The branch, 4.0/reset-rt-at-a-glance has been created
        at  ee1277fd5eb6ad88423762cbc84d725cbaf23105 (commit)

- Log -----------------------------------------------------------------
commit 676fd1244614852c3dc9cee83e4ce34e5069c334
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 8a82377..77cb86b 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -1323,6 +1323,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 ac548963a071d1c835a69037cb36cac9fa748785
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 fdd9c17..01ef876 100644
--- a/share/html/Prefs/Search.html
+++ b/share/html/Prefs/Search.html
@@ -68,6 +68,14 @@
 
 </form>
 
+<&|/Widgets/TitleBox, title => loc("Reset adjustments") &>
+<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 ($search->Description, loc ('"N"'));
 my $user = $session{'CurrentUser'}->UserObj;
 my $SearchArg = $user->Preferences($search, $search->Content);

commit eb5ecc085b2385a65b6dfd98b39deb89d283a706
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 55e5cc9..47a0ebc 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 ee1277fd5eb6ad88423762cbc84d725cbaf23105
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 2447fed..15b5751 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 47a0ebc..3d2fc98 100644
--- a/share/html/Prefs/MyRT.html
+++ b/share/html/Prefs/MyRT.html
@@ -103,15 +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-$_", $_], grep !$seen{$_}++, @{RT->Config->Get('HomepageComponents')};
@@ -160,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