[Rt-commit] rt branch, 4.0/preferences-viewer, created. rt-4.0.1-124-gc265cda

Kevin Falcone falcone at bestpractical.com
Fri Jul 22 16:17:51 EDT 2011


The branch, 4.0/preferences-viewer has been created
        at  c265cda315bd395d6d015cb3298d8aaabe124027 (commit)

- Log -----------------------------------------------------------------
commit c265cda315bd395d6d015cb3298d8aaabe124027
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Fri Jul 22 16:07:54 2011 -0400

    Add a new rt-preferences-viewer script

diff --git a/.gitignore b/.gitignore
index 7b74b55..3c23f17 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ sbin/rt-email-dashboards
 sbin/rt-email-digest
 sbin/rt-email-group-admin
 sbin/rt-fulltext-indexer
+sbin/rt-preferences-viewer
 sbin/rt-server
 sbin/rt-server.fcgi
 sbin/rt-session-viewer
diff --git a/Makefile.in b/Makefile.in
index 33c104b..b716013 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -146,6 +146,7 @@ SYSTEM_BINARIES		=	rt-attributes-viewer \
 				rt-email-digest \
 				rt-email-group-admin \
 				rt-fulltext-indexer \
+				rt-preferences-viewer \
 				rt-server \
 				rt-server.fcgi \
 				rt-session-viewer \
diff --git a/configure.ac b/configure.ac
index 19c7145..8048469 100755
--- a/configure.ac
+++ b/configure.ac
@@ -395,6 +395,7 @@ AC_CONFIG_FILES([
                  etc/upgrade/upgrade-articles
                  etc/upgrade/vulnerable-passwords
                  sbin/rt-attributes-viewer
+                 sbin/rt-preferences-viewer
                  sbin/rt-session-viewer
                  sbin/rt-dump-metadata
                  sbin/rt-setup-database
diff --git a/sbin/rt-preferences-viewer.in b/sbin/rt-preferences-viewer.in
new file mode 100644
index 0000000..5696740
--- /dev/null
+++ b/sbin/rt-preferences-viewer.in
@@ -0,0 +1,149 @@
+#!@PERL@
+# 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;
+
+# fix lib paths, some may be relative
+BEGIN {
+    require File::Spec;
+    my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
+    my $bin_path;
+
+    for my $lib (@libs) {
+        unless ( File::Spec->file_name_is_absolute($lib) ) {
+            unless ($bin_path) {
+                if ( File::Spec->file_name_is_absolute(__FILE__) ) {
+                    $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
+                }
+                else {
+                    require FindBin;
+                    no warnings "once";
+                    $bin_path = $FindBin::Bin;
+                }
+            }
+            $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
+        }
+        unshift @INC, $lib;
+    }
+}
+
+use Getopt::Long;
+my %opt;
+GetOptions( \%opt, 'help|h', 'user|u=s', 'option|o=s' );
+
+if ( $opt{help} ) {
+    require Pod::Usage;
+    Pod::Usage::pod2usage({ verbose => 2 });
+    exit;
+}
+
+require RT;
+RT::LoadConfig();
+RT::Init();
+
+require RT::Attributes;
+my $attrs = RT::Attributes->new( RT->SystemUser );
+$attrs->Limit( FIELD => 'Name', VALUE => 'Pref-RT::System-1' );
+$attrs->Limit( FIELD => 'ObjectType', VALUE => 'RT::User' );
+
+if ($opt{user}) {
+    my $user = RT::User->new( RT->SystemUser );
+    my ($val, $msg) = $user->Load($opt{user});
+    unless ($val) {
+        RT->Logger->error("Unable to load $opt{user}: $msg");
+        exit(1);
+    }
+    $attrs->Limit( FIELD => 'ObjectId', VALUE => $user->Id );
+}
+
+use Data::Dumper;
+$Data::Dumper::Terse = 1;
+
+while (my $attr = $attrs->Next ) {
+    my $user = RT::User->new( RT->SystemUser );
+    my ($val, $msg) = $user->Load($attr->ObjectId);
+    unless ($val) {
+        RT->Logger->warn("Unable to load User ".$attr->ObjectId." $msg");
+        next;
+    }
+    next if $user->Disabled;
+
+    my $content = $attr->Content;
+    if ( my $config_name = $opt{option} ) {
+        if ( exists $content->{$config_name} ) {
+            my $setting = $content->{$config_name};
+            print $user->Name, "\t$config_name: $setting\n";
+        }
+    } else {
+        print $user->Name, " => ", Dumper($content);
+    }
+
+}
+
+__END__
+
+=head1 NAME
+
+rt-preferences-viewer - show user defined preferences
+
+=head1 SYNOPSIS
+
+    rt-preferences-viewer
+
+    rt-preferences-viewer --user=falcone
+        show only the falcone user's preferences
+
+    rt-preferences-viewer --option=EmailFrequency
+        show users who have set the EmailFrequence config option
+
+=head1 DESCRIPTION
+
+This script shows user settings of preferences.  If a user is using the system
+default, it will not be listed.  You can limit to a user name or id or to users
+with a particular option set.

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


More information about the Rt-commit mailing list