[Rt-commit] rt branch, 4.4/cf-default-values, repushed
? sunnavy
sunnavy at bestpractical.com
Fri Jun 20 11:25:43 EDT 2014
The branch 4.4/cf-default-values was deleted and repushed:
was 7fe79d62293ceecd22f205a4daf37177be813c12
now bbbece1fbd0556792c10e5478f7c9130100a62f1
1: bab107f ! 1: 555e1a6 added ticket cf global default values support
@@ -45,7 +45,7 @@
+ %{ $old_content || {} }, $self->id => $args{Values},
+ },
+ );
-
++
+ if ( defined $old_values && length $old_values ) {
+ $old_values = join ', ', @$old_values if ref $old_values eq 'ARRAY';
+ }
@@ -60,13 +60,85 @@
+ else {
+ $new_values = $self->loc( '(no value)' );
+ }
-
++
+ if ( $ret ) {
+ return ( $ret, $self->loc( 'Default values changed from [_1] to [_2]', $old_values, $new_values ) );
+ }
+ else {
+ return ( $ret, $self->loc( "Can't change default values from [_1] to [_2]", $old_values, $new_values ) );
+ }
++}
+
++sub CleanupDefaultValues {
++ my $self = shift;
++ my $attrs = RT::Attributes->new( $self->CurrentUser );
++ $attrs->Limit( FIELD => 'Name', VALUE => 'CustomFieldDefaultValues' );
++
++ my @values;
++ if ( $self->Type eq 'Select' ) {
++ @values = map { $_->Name } @{ $self->Values->ItemsArrayRef || [] };
++ }
++
++ while ( my $attr = $attrs->Next ) {
++ my $content = $attr->Content;
++ next unless $content;
++ my $changed;
++ if ( $self->SupportDefaultValues ) {
++ if ( $self->MaxValues == 1 && ref $content->{ $self->id } eq 'ARRAY' ) {
++ $content->{ $self->id } = $content->{ $self->id }[ 0 ];
++ $changed ||= 1;
++ }
+
++ my $default_values = $content->{ $self->id };
++ if ( $default_values && $self->Type eq 'Select' ) {
++ if ( ref $default_values eq 'ARRAY' ) {
++ my @new_defaults;
++ for my $default ( @$default_values ) {
++ if ( grep { $_ eq $default } @values ) {
++ push @new_defaults, $default;
++ }
++ else {
++ $changed ||= 1;
++ }
++ }
++
++ $content->{ $self->id } = \@new_defaults if $changed;
++ }
++ elsif ( !grep { $_ eq $default_values } @values ) {
++ delete $content->{ $self->id };
++ $changed ||= 1;
++ }
++ }
++ }
++ else {
++ if ( exists $content->{ $self->id } ) {
++ delete $content->{ $self->id };
++ $changed ||= 1;
++ }
++ }
++ $attr->SetContent( $content ) if $changed;
++ }
++}
+
+ =head2 id
+
+
+diff --git a/lib/RT/CustomFieldValue.pm b/lib/RT/CustomFieldValue.pm
+--- a/lib/RT/CustomFieldValue.pm
++++ b/lib/RT/CustomFieldValue.pm
+@@
+ return $self->SUPER::_Set( @_ );
+ }
+
++sub SetName {
++ my $self = shift;
++ my $value = shift;
++ my ( $ret, $msg ) = $self->_Set(
++ Field => 'Name',
++ Value => $value,
++ );
++
++ return ( $ret, $msg );
+}
=head2 id
@@ -126,7 +198,7 @@
+% if ( $CustomFieldObj->SupportDefaultValues ) {
+<tr class="edit_default_values"><td class="label"><&|/l, $CustomFieldObj->MaxValues &>Default [numerate,_1,value,values]</&></td>
+<td>
-+<& /Elements/EditCustomField, NamePrefix => 'Default-', CustomField => $CustomFieldObj, Default => $CustomFieldObj->DefaultValues(Object => RT->System) &>
++<& /Elements/EditCustomField, NamePrefix => 'Default-', CustomField => $CustomFieldObj &>
+</td>
+</tr>
+% }
@@ -134,6 +206,14 @@
<tr><td class="label"><&|/l&>Link values to</&></td><td>
<input size="60" name="LinkValueTo" value="<% $CustomFieldObj->LinkValueTo || $LinkValueTo || '' %>" />
<div class="hints">
+@@
+ Object => $CustomFieldObj,
+ ARGSRef => \%ARGS
+ );
++
+ if ( ($ValuesClass||'RT::CustomFieldValues') ne $CustomFieldObj->ValuesClass ) {
+ my $original = $CustomFieldObj->ValuesClass;
+ my ($good, $msg) = $CustomFieldObj->SetValuesClass( $ValuesClass );
@@
push @results, $msg;
}
@@ -149,6 +229,14 @@
my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
# Delete any fields that want to be deleted
foreach my $key ( keys %ARGS ) {
+@@
+ $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
+ CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
+ }
++ $CustomFieldObj->CleanupDefaultValues;
+ }
+
+ if ( $CustomFieldObj->id && $CustomFieldObj->IsOnlyGlobal ) {
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
--- a/share/html/Elements/EditCustomField
@@ -165,3 +253,29 @@
if ($MaxValues == 1 && $Values) {
# what exactly is this doing? Without the "unless" it breaks RTFM
+diff --git a/share/html/Elements/EditCustomFieldCombobox b/share/html/Elements/EditCustomFieldCombobox
+--- a/share/html/Elements/EditCustomFieldCombobox
++++ b/share/html/Elements/EditCustomFieldCombobox
+@@
+ %# those contributions and any derivatives thereof.
+ %#
+ %# END BPS TAGGED BLOCK }}}
++% $Name ||= $NamePrefix . $CustomField->Id . ( $Multiple ? '-Values' : '-Value' );
++
+ % while ($Values and my $value = $Values->Next and $Multiple) {
+ <input type="checkbox" id="<%$delete_name%>" class="checkbox CF-<%$CustomField->id%>-Edit" name="<%$delete_name%>" class="CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" />
+ <label for="<%$delete_name%>"><% $value->Content %></label>
+
+diff --git a/share/html/Elements/EditCustomFieldFreeform b/share/html/Elements/EditCustomFieldFreeform
+--- a/share/html/Elements/EditCustomFieldFreeform
++++ b/share/html/Elements/EditCustomFieldFreeform
+@@
+ unless ( $Multiple ) {
+ $Default =~ s/\s*\n+\s*/ /g if $Default;
+ }
++
++$Default = join "\n", @$Default if $Default && ref $Default eq 'ARRAY';
+ </%INIT>
+ <%ARGS>
+ $Object => undef
+
2: b4303c6 ! 2: 2dd02eb queue-level default custom fields
@@ -199,7 +199,8 @@
if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
- $Default = $CustomField->DefaultValues;
-+ $Default = $CustomField->DefaultValues(Object => $ARGS{DefaultValuesFromObject} || RT->System);
++ my ( $on ) = grep {$_->isa($CustomField->RecordClassFromLookupType)} $CustomField->ACLEquivalenceObjects;
++ $Default = $CustomField->DefaultValues(Object => $on || RT->System);
}
my $MaxValues = $CustomField->MaxValues;
@@ -216,47 +217,3 @@
$m->callback( CallbackName => 'PrivilegedQueue', queue_id => $id, page_menu => $queue);
}
-diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
---- a/share/html/Ticket/Create.html
-+++ b/share/html/Ticket/Create.html
-@@
- CustomFields => $QueueObj->TicketCustomFields,
- Grouping => 'Basics',
- InTable => 1,
-+ DefaultValuesFromObject => $QueueObj,
- &>
- <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
- </table>
-@@
- %ARGS,
- Object => $ticket,
- CustomFieldGenerator => sub { $QueueObj->TicketCustomFields },
-+ DefaultValuesFromObject => $QueueObj,
- &>
-
- </div>
-@@
- CustomFields => $QueueObj->TicketCustomFields,
- Grouping => 'People',
- InTable => 1,
-+ DefaultValuesFromObject => $QueueObj,
- &>
-
- <tr>
-@@
- CustomFields => $QueueObj->TicketCustomFields,
- Grouping => 'Dates',
- InTable => 1,
-+ DefaultValuesFromObject => $QueueObj,
- &>
- </table>
- </&>
-@@
- Object => $ticket,
- CustomFields => $QueueObj->TicketCustomFields,
- ARGSRef => \%ARGS,
-+ DefaultValuesFromObject => $QueueObj,
- &>
- </&>
- </div>
-
3: 9869252 ! 3: d7706ce queue-level default values for priority/starts/due
@@ -3,35 +3,6 @@
queue-level default values for priority/starts/due
with this, we can drop the old InitialPriority/FinalPriority/DefaultDueIn
-
-diff --git a/configure.ac b/configure.ac
---- a/configure.ac
-+++ b/configure.ac
-@@
- etc/upgrade/split-out-cf-categories
- etc/upgrade/generate-rtaddressregexp
- etc/upgrade/upgrade-articles
-+ etc/upgrade/upgrade-queue-defaults
- etc/upgrade/vulnerable-passwords
- etc/upgrade/switch-templates-to
- sbin/rt-attributes-viewer
-
-diff --git a/docs/UPGRADING-4.4 b/docs/UPGRADING-4.4
---- a/docs/UPGRADING-4.4
-+++ b/docs/UPGRADING-4.4
-@@
-
- =item *
-
-+Please run C<etc/upgrade/upgrade-queue-defaults> on old RT before upgrading.
-+In 4.4, we dropped some columns in Queues table, the script is to migrate the
-+column values into other places.
-+
-+=item *
-+
- The support for C<jsmin> (via the C<$JSMinPath> configuration) has been
- removed in favor of a built-in solution.
-
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
--- a/etc/RT_Config.pm.in
@@ -102,121 +73,69 @@
Created DATETIME NULL ,
LastUpdatedBy integer NOT NULL DEFAULT 0 ,
-diff --git a/etc/upgrade/4.3.2/schema.Oracle b/etc/upgrade/4.3.2/schema.Oracle
+diff --git a/etc/upgrade/4.3.2/content b/etc/upgrade/4.3.2/content
new file mode 100644
--- /dev/null
-+++ b/etc/upgrade/4.3.2/schema.Oracle
-@@
-+ALTER TABLE Queues DROP COLUMN InitialPriority;
-+ALTER TABLE Queues DROP COLUMN FinalPriority;
-+ALTER TABLE Queues DROP COLUMN DefaultDueIn;
-
-diff --git a/etc/upgrade/4.3.2/schema.Pg b/etc/upgrade/4.3.2/schema.Pg
++++ b/etc/upgrade/4.3.2/content
+@@
++use strict;
++use warnings;
++
++our @Initial = (
++ sub {
++ use RT::Queues;
++ my $queues = RT::Queues->new(RT->SystemUser);
++ $queues->UnLimit;
++ $queues->{'find_disabled_rows'} = 1;
++ while ( my $queue = $queues->Next ) {
++ next if $queue->FirstAttribute('DefaultValues');
++ my %default;
++ for my $priority ( qw/InitialPriority FinalPriority/ ) {
++ $default{$priority} = $queue->__Value($priority) if $queue->__Value($priority);
++ }
++ if ( my $due = $queue->__Value('DefaultDueIn') ) {
++ if ( $due == 1 ) {
++ $default{Due} = "$due day";
++ }
++ else {
++ $default{Due} = "$due days";
++ }
++ }
++ if ( %default ) {
++ $queue->SetAttribute( Name => 'DefaultValues', Content => \%default );
++ RT->Logger->warning("updated default values for queue " . $queue->Name);
++ }
++ }
++ return 1;
++ },
++);
+
+diff --git a/etc/upgrade/4.3.3/schema.Oracle b/etc/upgrade/4.3.3/schema.Oracle
new file mode 100644
--- /dev/null
-+++ b/etc/upgrade/4.3.2/schema.Pg
-@@
-+ALTER TABLE Queues DROP COLUMN InitialPriority;
-+ALTER TABLE Queues DROP COLUMN FinalPriority;
-+ALTER TABLE Queues DROP COLUMN DefaultDueIn;
-
-diff --git a/etc/upgrade/4.3.2/schema.SQLite b/etc/upgrade/4.3.2/schema.SQLite
++++ b/etc/upgrade/4.3.3/schema.Oracle
+@@
++ALTER TABLE Queues DROP( InitialPriority, FinalPriority, DefaultDueIn );
+
+diff --git a/etc/upgrade/4.3.3/schema.Pg b/etc/upgrade/4.3.3/schema.Pg
new file mode 100644
--- /dev/null
-+++ b/etc/upgrade/4.3.2/schema.SQLite
-@@
-+ALTER TABLE Queues DROP COLUMN InitialPriority;
-+ALTER TABLE Queues DROP COLUMN FinalPriority;
-+ALTER TABLE Queues DROP COLUMN DefaultDueIn;
-
-diff --git a/etc/upgrade/4.3.2/schema.mysql b/etc/upgrade/4.3.2/schema.mysql
++++ b/etc/upgrade/4.3.3/schema.Pg
+@@
++ALTER TABLE Queues
++ DROP COLUMN InitialPriority,
++ DROP COLUMN FinalPriority,
++ DROP COLUMN DefaultDueIn;
+
+diff --git a/etc/upgrade/4.3.3/schema.mysql b/etc/upgrade/4.3.3/schema.mysql
new file mode 100644
--- /dev/null
-+++ b/etc/upgrade/4.3.2/schema.mysql
-@@
-+ALTER TABLE Queues DROP COLUMN InitialPriority;
-+ALTER TABLE Queues DROP COLUMN FinalPriority;
-+ALTER TABLE Queues DROP COLUMN DefaultDueIn;
-
-diff --git a/etc/upgrade/upgrade-queue-defaults.in b/etc/upgrade/upgrade-queue-defaults.in
-new file mode 100755
---- /dev/null
-+++ b/etc/upgrade/upgrade-queue-defaults.in
-@@
-+#!@PERL@
-+# 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 }}}
-+use strict;
-+use warnings;
-+
-+use lib "@LOCAL_LIB_PATH@";
-+use lib "@RT_LIB_PATH@";
-+
-+use RT;
-+RT::LoadConfig();
-+RT::Init();
-+
-+my $queues = RT::Queues->new(RT->SystemUser);
-+$queues->UnLimit;
-+while ( my $queue = $queues->Next ) {
-+ next if $queue->FirstAttribute('DefaultValues');
-+ my %default;
-+ for my $priority ( qw/InitialPriority FinalPriority/ ) {
-+ $default{$priority} = $queue->$priority if $queue->$priority;
-+ }
-+ $default{Due} = $queue->DefaultDueIn . ' days' if $queue->DefaultDueIn;
-+ if ( %default ) {
-+ print "upgrading default values for queue " . $queue->Name . "\n";
-+ $queue->SetAttribute( Name => 'DefaultValues', Content => \%default );
-+ }
-+}
-+
-+print "done.\n";
++++ b/etc/upgrade/4.3.3/schema.mysql
+@@
++ALTER TABLE Queues
++ DROP COLUMN InitialPriority,
++ DROP COLUMN FinalPriority,
++ DROP COLUMN DefaultDueIn;
diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
--- a/lib/RT/Queue.pm
4: 5283963 ! 4: d5293ae make default values page be like ticket create or display pages
@@ -3,6 +3,32 @@
make default values page be like ticket create or display pages
i.e. split fields into various widgets(including custom groupings)
+
+ also add Reset button so we can reset cf valus to system default
+
+diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
+--- a/lib/RT/CustomFields.pm
++++ b/lib/RT/CustomFields.pm
+@@
+ $self->LimitToLookupType( 'RT::Queue-RT::Ticket' );
+ }
+
++=head2 LimitToDefaultValuesSupportedTypes
++
++Limits the Custom Field collection to ones of which types support default values.
++
++=cut
++
++sub LimitToDefaultValuesSupportedTypes {
++ my $self = shift;
++ $self->Limit( FIELD => 'Type', VALUE => 'Binary', OPERATOR => '!=', ENTRYAGGREGATOR => 'AND' );
++ $self->Limit( FIELD => 'Type', VALUE => 'Image', OPERATOR => '!=', ENTRYAGGREGATOR => 'AND' );
++ return $self;
++}
++
+
+ =head2 ApplySortOrder
+
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
--- a/share/html/Admin/Queues/DefaultValues.html
@@ -42,10 +68,9 @@
+ <& /Elements/EditCustomFields,
+ NamePrefix => 'Default-',
+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields,
++ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+ Grouping => 'Basics',
+ InTable => 1,
-+ QueueObj => $queue,
+ &>
+ </table>
+ </&>
@@ -61,10 +86,9 @@
+ <& /Elements/EditCustomFields,
+ NamePrefix => 'Default-',
+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields,
++ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+ Grouping => 'Dates',
+ InTable => 1,
-+ QueueObj => $queue,
+ &>
+ </table>
+ </&>
@@ -78,10 +102,9 @@
+ <& /Elements/EditCustomFields,
+ NamePrefix => 'Default-',
+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields,
++ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+ Grouping => 'People',
+ InTable => 1,
-+ QueueObj => $queue,
+ &>
+ </table>
+ </&>
@@ -95,18 +118,51 @@
+ <& /Elements/EditCustomFields,
+ NamePrefix => 'Default-',
+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields,
++ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+ Grouping => 'Links',
+ InTable => 1,
-+ QueueObj => $queue,
+ &>
+ </table>
+ </&>
+</div>
+% }
+
-+<& /Elements/EditCustomFieldCustomGroupings, CustomFieldGenerator => sub { $queue->TicketCustomFields }, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}), QueueObj => $queue &>
++<& /Elements/EditCustomFieldCustomGroupings, CustomFieldGenerator => sub { $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes }, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}) &>
<& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
++<& /Elements/Submit, Name => 'Reset', Label => loc('Reset Custom Field Values to Default') &>
</form>
+
+ <%INIT>
+@@
+ $queue->Load($id) || Abort( loc( "Couldn't load object [_1]", $id ) );
+
+ my $title = loc( 'Default Values for queue [_1]', $queue->Name );
+-my $ticket_cfs = $queue->TicketCustomFields;
+
+ my @results;
+-if ( $ARGS{Update} ) {
++if ( $ARGS{Reset} ) {
++ my $attr = $queue->FirstAttribute( 'CustomFieldDefaultValues' );
++ if ( $attr ) {
++ $attr->Delete;
++ push @results, "Custom Field default values are reset";
++ }
++}
++elsif ( $ARGS{Update} ) {
+ for my $field ( qw/InitialPriority FinalPriority Starts Due/ ) {
+ my ($ret, $msg) = $queue->SetDefaultValue(
+ Name => $field,
+@@
+ }
+ }
+ }
++
++MaybeRedirectForResults(
++ Actions => \@results,
++ Arguments => { id => $queue->id },
++);
+ </%INIT>
+ <%ARGS>
+ $id => undef
5: f743962 = 5: d261f62 make datepicker less zealous
6: 7fe79d6 < -: ------- remove outdated default values when a cfv is updated/deleted
-: ------- > 6: bbbece1 allow default values for txn cfs
More information about the rt-commit
mailing list