[Rt-commit] [rtir] 01/03: Initial simple move to fetch Constituencies via an External CF
Kevin Falcone
falcone at bestpractical.com
Wed Jan 7 16:13:53 EST 2015
This is an automated email from the git hooks/post-receive script.
falcone pushed a commit to branch 3.4/constituency-external-cf
in repository rtir.
commit 3afdb003f2a1e584b864c3ba97b860d22c818630
Author: Kevin Falcone <falcone at bestpractical.com>
Date: Wed Dec 3 15:59:47 2014 -0500
Initial simple move to fetch Constituencies via an External CF
All this currently does is read from the internal CustomFieldValues
table. It provides the scaffolding that Constituency needs to limit
available values on a per user / ticket basis.
EditCustomFieldConstituency just calls through to a simple
CustomFieldSelect for now.
Removes EditConstituency which was previously used to generate the
trimmed list of Constituencies for certain users.
Mild shenanigans are required in initialdata to ensure that the
CustomFieldValue is set prior to make initdb (or
RT::Test::bootstrap_db). Neither of these codepaths loads plugins
before running initialdata. Doing something like Assets and require'ing
RT::IR will cause problems with all the various caches set up in the
package. Instead, we just continue the trend of dummy lifecycles with
manual frobbing of CustomFieldValuesSources and ensuring that
RT::CustomFieldValues::Constituency is loaded so that our ValuesClass is
obeyed (and RenderTypes are found/validated).
---
MANIFEST | 4 +-
etc/initialdata | 18 ++-
.../EditCustomFieldConstituency} | 30 +---
html/RTIR/Elements/EditConstituency | 160 ---------------------
lib/RT/CustomFieldValues/Constituency.pm | 121 ++++++++++++++++
lib/RT/IR.pm | 4 +
t/constituency/basics.t | 2 +-
7 files changed, 147 insertions(+), 192 deletions(-)
diff --git a/MANIFEST b/MANIFEST
index 74bf7e2..80e7b57 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -48,7 +48,6 @@ etc/upgrade/3.0.0rc2/content
etc/upgrade/3.1.0/content
etc/upgrade/upgrade.pl.in
html/Callbacks/RTIR/autohandler/SuccessfulLogin
-html/Callbacks/RTIR/Elements/EditCustomField/EditComponentName
html/Callbacks/RTIR/Elements/EditCustomFields/MassageCustomFields
html/Callbacks/RTIR/Elements/Header/Head
html/Callbacks/RTIR/Elements/MakeClicky/Default
@@ -63,6 +62,7 @@ html/Callbacks/RTIR/Search/Elements/PickBasics/Default
html/Callbacks/RTIR/Search/Results.html/Initial
html/Callbacks/RTIR/Ticket/Create.html/Default
html/Callbacks/RTIR/Ticket/Display.html/Initial
+html/Elements/EditCustomFieldConstituency
html/RTIR/Advanced.html
html/RTIR/Create.html
html/RTIR/Crypt.html
@@ -72,7 +72,6 @@ html/RTIR/EditUsername
html/RTIR/Elements/AddWatchers
html/RTIR/Elements/AttachReports
html/RTIR/Elements/DueIncidents
-html/RTIR/Elements/EditConstituency
html/RTIR/Elements/EditCustomFields
html/RTIR/Elements/EditPeople
html/RTIR/Elements/EditRTIRField
@@ -188,6 +187,7 @@ lib/RT/Condition/RTIR_RequireConstituencyGroupChange.pm
lib/RT/Condition/RTIR_RequireDueChange.pm
lib/RT/Condition/RTIR_RequireReportActivation.pm
lib/RT/Condition/RTIR_StaffResponse.pm
+lib/RT/CustomFieldValues/Constituency.pm
lib/RT/IR.pm
lib/RT/IR/Config.pm
lib/RT/IR/Test.pm.in
diff --git a/etc/initialdata b/etc/initialdata
index 6a7f2ac..80c88e5 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -2,13 +2,26 @@
@Initial = (
sub {
- # put fake lifecycles for initiialization to succed
+
+ # make initdb will generally not have Plugin('RT::IR') set
+ # so we need to ensure that some dummy lifecycles and our CFV source
+ # are imported and configured.
+ #
+ # similarly, RT::Test runs InsertData without having actually loaded Plugins
+ #
+ # Some of this could be fixed with "require RT::IR" but there is so much
+ # caching that breaks with that happening before queues/CFs are loaded.
my $lc = RT->Config->Get('Lifecycles') || {};
foreach my $name (qw(incidents incident_reports investigations blocks)) {
$lc->{ $name } ||= $lc->{'default'} || {};
}
RT->Config->Set(Lifecycles => %$lc);
RT::Lifecycle->FillCache;
+
+ RT->Config->Set('CustomFieldValuesSources', ( RT->Config->Get('CustomFieldValuesSources'),
+ 'RT::CustomFieldValues::Constituency') );
+ require RT::CustomFieldValues::Constituency;
+
return 1;
},
);
@@ -44,8 +57,9 @@
@CustomFields = (
{
Name => 'Constituency',
- Type => 'SelectSingle',
+ Type => 'ConstituencySingle',
RenderType => 'Dropdown',
+ ValuesClass => 'RT::CustomFieldValues::Constituency',
Queue => ['Incidents', 'Incident Reports', 'Investigations', 'Blocks'],
Disabled => 0,
Description => 'Constituency for RTIR queues',
diff --git a/html/Callbacks/RTIR/Elements/EditCustomField/EditComponentName b/html/Elements/EditCustomFieldConstituency
similarity index 77%
rename from html/Callbacks/RTIR/Elements/EditCustomField/EditComponentName
rename to html/Elements/EditCustomFieldConstituency
index 46c9cde..c5f51ca 100644
--- a/html/Callbacks/RTIR/Elements/EditCustomField/EditComponentName
+++ b/html/Elements/EditCustomFieldConstituency
@@ -45,30 +45,6 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<%init>
-return unless $CustomField->LookupType eq 'RT::Queue-RT::Ticket';
-
-my $type = RT::IR->OurQueue( $ARGS{'QueueObj'} || $ARGS{'Queue'} || $Object->QueueObj );
-unless ( $type ) {
- RT->Logger->error("Couldn't figure out queue from arguments")
- unless defined $type;
- return;
-}
-
-my $cf_name = $CustomField->Name;
-my @paths = (
- "/RTIR/$type/Elements/Edit$cf_name",
- "/RTIR/Elements/Edit$cf_name",
-);
-foreach my $path ( @paths ) {
- next unless $m->comp_exists($path);
-
- $$Name = $path;
- return;
-}
-</%init>
-<%args>
-$Name
-$CustomField
-$Object
-</%args>
+<%INIT>
+return $m->comp( 'EditCustomFieldSelect', %ARGS );
+</%INIT>
diff --git a/html/RTIR/Elements/EditConstituency b/html/RTIR/Elements/EditConstituency
deleted file mode 100644
index d204c89..0000000
--- a/html/RTIR/Elements/EditConstituency
+++ /dev/null
@@ -1,160 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2014 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 }}}
-%# Build up the set of cascading select boxes as "guides"
-%# each one limits the options of the final one a bit
-%# (perhaps by tweaking the .display style?)
-% my $selected = 0;
-% my @category;
-% my $id = $NamePrefix . $CustomField->Id;
-% my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category, Object => $Object, Default => \@Default);
-% if (@category) {
-<script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/static/js/cascaded.js"></script>
-%# XXX - Hide this select from w3m?
- <select onchange="filter_cascade('<% $id %>-Values', this.value)" name="<% $id %>-Category">
- <option value="" <% !$selected && 'selected' %>><&|/l&>-</&></option>
-% foreach my $cat (@category) {
-% my ($depth, $name) = @$cat;
- <option value="<% $name %>"><% ' ' x $depth |n %><% $name %></option>
-% }
- </select><br />
-% }
- <select name="<%$id%>-Values" id="<%$id%>-Values"
-% if ( $Rows && ( $Multiple || !@category ) ) {
- size="<% $Rows %>"
-% }
- <% $Multiple && 'multiple' %> >
-% $m->out($out);
- </select>
-<%INIT>
-# Handle render types
-$RenderType ||= $CustomField->RenderType;
-if ( $RenderType eq 'Dropdown' ) {
- # Turn it into a dropdown
- $Rows = 0;
-}
-
- at Default = grep defined && length, @Default;
-unless (@Default) {
- my $default = $PropagationObject->FirstCustomFieldValue('Constituency') if $PropagationObject;
- $default ||= RT::IR::DefaultConstituency( $QueueObj ) if $QueueObj;
- $default ||= scalar RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Constituency'};
- push @Default, $default;
-}
-</%INIT>
-<%ARGS>
-$Object => undef
-$CustomField => undef
-$NamePrefix => undef
- at Default => ()
-$Values => undef
-$Multiple => 0
-$Rows => undef
-$RenderType => undef
-$PropagationObject => undef
-$QueueObj => undef
-</%ARGS>
-
-<%METHOD options>
-<%INIT>
-my $selected;
-my $CFVs = $CustomField->Values;
-my @levels;
-
-my $main_queue = RT::Queue->new($session{'CurrentUser'});
-if ( $Object ) {
- $main_queue->Load( $Object->Queue );
-} else {
- $main_queue->Load( $m->request_args->{'Queue'} || 'Incidents' );
-}
-$main_queue->{'disable_constituency_right_check'} = 1;
-my $show_all = $main_queue->CurrentUserHasRight('OwnTicket') ? 1 : 0;
-</%INIT>
-
-% while ( my $value = $CFVs->Next ) {
-% my $name = $value->Name;
-% my $subqueue = RT::Queue->new($session{'CurrentUser'});
-% next unless ($show_all || ($subqueue->LoadByCols(Name => $main_queue->Name . " - ".$name) && $subqueue->id && $subqueue->CurrentUserHasRight('OwnTicket')));
-% my $category = $value->Category || '';
-% my $level = (split /:/, $category, 2)[0] || '';
-% while (@levels) {
-% if ($levels[-1] eq $level) {
-% $level = '';
-% last;
-% } elsif (index($level, $levels[-1]) != 0) {
-% $m->out('</optgroup>');
-% pop @levels;
-% } else {
-% last;
-% }
-% }
-% if ( length $level ) {
-% push @$CategoryRef, [0+ at levels, $level];
- <optgroup style="padding-left: <% @levels/2 %>em" label="<% $category %>">
-% push @levels, $level;
-% }
- <option value="<% $name %>"
-% if ( grep( ( $_ || '') eq ( $name || '') , @Default )
-% || ( $Values && $Values->HasEntry( $name ) ) )
-% {
-% $$SelectedRef = 1;
- selected
-% }
- ><% $name %></option>
-% }
-% for (@levels) {
- </optgroup>
-% }
-<%ARGS>
-$CustomField => undef
- at Default => ()
-$Values => undef
-$SelectedRef => undef
-$CategoryRef => undef
-$Object => undef
-</%ARGS>
-</%METHOD>
diff --git a/lib/RT/CustomFieldValues/Constituency.pm b/lib/RT/CustomFieldValues/Constituency.pm
new file mode 100644
index 0000000..6bc7c13
--- /dev/null
+++ b/lib/RT/CustomFieldValues/Constituency.pm
@@ -0,0 +1,121 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2014 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 }}}
+
+package RT::CustomFieldValues::Constituency;
+
+use strict;
+use warnings;
+
+use base qw(RT::CustomFieldValues::External);
+
+#Constituencies are only usable as a single value
+$RT::CustomField::FieldTypes{Constituency} = {
+ sort_order => 10,
+ selection_type => 1,
+
+ labels => [ 'Select one value' ], # loc
+
+ render_types => {
+ single => [ 'Select box', # loc
+ 'Dropdown', # loc
+ 'List', # loc
+ ]
+ },
+};
+
+
+=head1 NAME
+
+RT::CustomFieldValues::Constituency - Provide's RTIR's Constituencies
+
+=head1 SYNOPSIS
+
+Visit the RTIR Admin Constituencies page to manage constituencies.
+
+=head1 METHODS
+
+
+=head2 SourceDescription
+
+Returns a brief string describing this data source.
+
+=cut
+
+sub SourceDescription {
+ return "RTIR's special Constituency Field";
+}
+
+=head2 ExternalValues
+
+Returns an arrayref containing a hashref for each possible value in this data
+source, where the value name is the group name.
+
+=cut
+
+sub ExternalValues {
+ my $self = shift;
+
+ my @res;
+ my $i = 0;
+ my $cfvs = RT::CustomFieldValues->new( $self->CurrentUser );
+ my $cf = $self->CustomFieldObject;
+ unless ($cf->Id) {
+ RT->Logger->error("Tried to load an External Custom Field without providing a CF");
+ }
+ $cfvs->Limit( FIELD => 'CustomField', VALUE => $cf->Id );
+
+ while( my $cfv = $cfvs->Next ) {
+ push @res, {
+ name => $cfv->Name,
+ sortorder => $i++,
+ };
+ }
+ return \@res;
+}
+
+1;
diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 0b1ca85..4157cfc 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -87,6 +87,10 @@ RT->AddStyleSheets( 'rtir-styles.css' );
$RT::Interface::Web::is_whitelisted_component{'/RTIR/Search/Results.html'} = 1;
+RT->Config->Set('CustomFieldValuesSources',
+ ( RT->Config->Get('CustomFieldValuesSources'),
+ 'RT::CustomFieldValues::Constituency') );
+
=head1 FUNCTIONS
=head2 IsStaff
diff --git a/t/constituency/basics.t b/t/constituency/basics.t
index d608eee..374ccd6 100644
--- a/t/constituency/basics.t
+++ b/t/constituency/basics.t
@@ -16,7 +16,7 @@ diag "load and check basic properties of the CF" if $ENV{'TEST_VERBOSE'};
is( $cfs->Count, 1, "found one CF with name 'Constituency'" );
$cf = $cfs->First;
- is( $cf->Type, 'Select', 'type check' );
+ is( $cf->Type, 'Constituency', 'type check' );
is( $cf->LookupType, 'RT::Queue-RT::Ticket', 'lookup type check' );
is( $cf->MaxValues, 1, "single value" );
ok( !$cf->Disabled, "not disabled" );
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the rt-commit
mailing list