[Bps-public-commit] RT-Extension-UsernameFormat-Organization branch, master, created. da8fd2601c291af3d56c144a10ab45279a053ed9

Thomas Sibley trs at bestpractical.com
Wed Aug 1 15:34:02 EDT 2012


The branch, master has been created
        at  da8fd2601c291af3d56c144a10ab45279a053ed9 (commit)

- Log -----------------------------------------------------------------
commit da8fd2601c291af3d56c144a10ab45279a053ed9
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Aug 1 12:32:10 2012 -0700

    Show organization info via username format

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae95dbf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+blib*
+Makefile
+Makefile.old
+pm_to_blib*
+*.tar.gz
+.lwpcookies
+cover_db
+pod2htm*.tmp
+/RT-Extension-UsernameFormat-Organization*
+README
+*.bak
+*.swp
+/MYMETA.*
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..c0f24b5
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,10 @@
+use inc::Module::Install;
+
+
+RTx 'RT-Extension-UsernameFormat-Organization';
+all_from 'lib/RT/Extension/UsernameFormat/Organization.pm';
+readme_from 'lib/RT/Extension/UsernameFormat/Organization.pm';
+license  'gplv2';
+
+sign;
+WriteAll;
diff --git a/html/Elements/ShowUserOrganization b/html/Elements/ShowUserOrganization
new file mode 100644
index 0000000..1542587
--- /dev/null
+++ b/html/Elements/ShowUserOrganization
@@ -0,0 +1,76 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2012 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 }}}
+%# Released under the terms of version 2 of the GNU Public License
+<% $display |n %>\
+<%ARGS>
+$User => undef
+$Address => undef
+</%ARGS>
+<%INIT>
+if ( !$User && $Address ) {
+    $User = RT::User->new( $session{'CurrentUser'} );
+    $User->LoadByEmail( $Address->address );
+    if ( $User->Id ) {
+        $Address = '';
+    } else {
+        $Address = $Address->address;
+    }
+}
+
+my $organization;
+if ($User) {
+    $organization = join ", ", grep { defined && length }
+                                map { $User->$_ }
+                                    qw(Organization City Country);
+}
+
+my $display = $Address || $User->RealName || $User->Name;
+   $display .= " ($organization)" if $organization;
+   $display = $m->interp->apply_escapes( $display, 'h' )
+        unless $ARGS{'NoEscape'};
+</%INIT>
diff --git a/lib/RT/Extension/UsernameFormat/Organization.pm b/lib/RT/Extension/UsernameFormat/Organization.pm
new file mode 100644
index 0000000..3e3225e
--- /dev/null
+++ b/lib/RT/Extension/UsernameFormat/Organization.pm
@@ -0,0 +1,99 @@
+use strict;
+use warnings;
+package RT::Extension::UsernameFormat::Organization;
+
+our $VERSION = '0.01';
+
+=head1 NAME
+
+RT-Extension-UsernameFormat-Organization - Adds a username format option for "Name (Org, City, Country)"
+
+=head1 DESCRIPTION
+
+Adds "Name (Organization, City, Country)" to the "Username format" preference.
+
+Only non-empty values are shown, so if your users only have an organization and
+city you'd see something like "John Smith (Best Practical, Boston)" without any
+country.  The same goes for Organization and City.
+
+This extension makes City and Country a B<public> field, meaning any user can
+see any other user's value.  Default RT normally prevents non-administrators
+from seeing City and Country.
+
+=cut
+
+my $meta = RT->Config->Meta('UsernameFormat');
+push @{$meta->{WidgetArguments}{Values}}, 'organization';
+$meta->{WidgetArguments}{ValuesLabel}{organization} = 'Name (Organization, City, Country)';
+
+package RT::User;
+no warnings 'redefine';
+
+# Ensure these user fields are readable by all users
+sub RT::User::_VendorAccessible {
+    my %columns;
+    $columns{$_} = { public => 1 } for qw(
+        Organization
+        City
+        Country
+    );
+    return \%columns;
+}
+
+# Required to work around a loading quirk
+__PACKAGE__->_BuildTableAttributes;
+
+package RT::Extension::UsernameFormat::Organization;
+
+=head1 INSTALLATION 
+
+=over
+
+=item perl Makefile.PL
+
+=item make
+
+=item make install
+
+May need root permissions
+
+=item Edit your /opt/rt4/etc/RT_SiteConfig.pm
+
+Add this line:
+
+    Set(@Plugins, qw(RT::Extension::UsernameFormat::Organization));
+
+or add C<RT::Extension::UsernameFormat::Organization> to your existing C<@Plugins> line.
+
+=item Clear your mason cache
+
+    rm -rf /opt/rt4/var/mason_data/obj
+
+=item Restart your webserver
+
+=item Navigate to Logged in as... then Settings and select the new Username Format
+
+=back
+
+=head1 AUTHOR
+
+Thomas Sibley <trs at bestpractical.com>
+
+=head1 BUGS
+
+All bugs should be reported via
+L<http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-UsernameFormat-Organization>
+or L<bug-RT-Extension-UsernameFormat-Organization at rt.cpan.org>.
+
+
+=head1 LICENSE AND COPYRIGHT
+
+This software is Copyright (c) 2012 by Best Practical Solutions
+
+This is free software, licensed under:
+
+  The GNU General Public License, Version 2, June 1991
+
+=cut
+
+1;

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



More information about the Bps-public-commit mailing list