[Rt-commit] rt branch, 4.4/default-values, repushed
? sunnavy
sunnavy at bestpractical.com
Tue Aug 19 02:31:44 EDT 2014
The branch 4.4/default-values was deleted and repushed:
was 873d062f4d55c179021d3969fe92aab90f4f18f1
now e567a94744925deabd5a031fd239f4ca8a2715af
1: 075d655 = 1: afd5b61 make datepicker less zealous
2: a678380 < -: ------- $name is more right as it handles the case when $Name is not defined
3: 85bd292 ! 2: 1022a16 system level cf default values support
@@ -1,27 +1,6 @@
Author: sunnavy <sunnavy at bestpractical.com>
- added cf default values support
-
-diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
---- a/lib/RT/Config.pm
-+++ b/lib/RT/Config.pm
-@@
- return 1;
- }
-
-+sub ObjectHasCustomFieldGrouping {
-+ my $self = shift;
-+ my %args = ( Object => undef, Grouping => undef, @_ );
-+ my $object_type = ref $args{Object};
-+ my $groupings = RT->Config->Get( 'CustomFieldGroupings' );
-+ return 0 unless $groupings;
-+ return 1 if $groupings->{$object_type} && grep { $_ eq $args{Grouping} } @{ $groupings->{$object_type} };
-+ return 0;
-+}
-+
- RT::Base->_ImportOverlays();
-
- 1;
+ system level cf default values support
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
--- a/lib/RT/CustomField.pm
@@ -65,14 +44,7 @@
+ my $attr = $args{Object}->FirstAttribute('CustomFieldDefaultValues');
+ my $values;
+ $values = $attr->Content->{$self->id} if $attr && $attr->Content;
-+ return $values if defined $values;
-+
-+ if ( !$args{Object}->isa( 'RT::System' ) ) {
-+ my $system_attr = RT::System->FirstAttribute( 'CustomFieldDefaultValues' );
-+ $values = $system_attr->Content->{$self->id} if $system_attr && $system_attr->Content;
-+ return $values if defined $values;
-+ }
-+ return undef;
++ return $values;
+}
+
+sub SetDefaultValues {
@@ -89,13 +61,6 @@
+ $old_values = $old_content->{ $self->id };
+ }
+
-+ if ( !$args{Object}->isa( 'RT::System' ) && !defined $old_values ) {
-+ my $system_attr = RT::System->FirstAttribute( 'CustomFieldDefaultValues' );
-+ if ( $system_attr && $system_attr->Content ) {
-+ $old_values = $system_attr->Content->{ $self->id };
-+ }
-+ }
-+
+ if ( defined $old_values && length $old_values ) {
+ $old_values = join ', ', @$old_values if ref $old_values eq 'ARRAY';
+ }
@@ -112,7 +77,7 @@
+ }
+
+ return 1 if $new_values eq $old_values;
-+
+
+ my ($ret, $msg) = $args{Object}->SetAttribute(
+ Name => 'CustomFieldDefaultValues',
+ Content => {
@@ -148,7 +113,7 @@
+ $content->{ $self->id } = $content->{ $self->id }[ 0 ];
+ $changed = 1;
+ }
-
++
+ my $default_values = $content->{ $self->id };
+ if ( $default_values ) {
+ if ( $self->Type eq 'Select' ) {
@@ -266,31 +231,26 @@
=head2 ApplySortOrder
-diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
---- a/lib/RT/Ticket.pm
-+++ b/lib/RT/Ticket.pm
-@@
- }
-
- # Add all the custom fields
-+ my %cf_added;
- foreach my $arg ( keys %args ) {
- next unless $arg =~ /^CustomField-(\d+)$/i;
- my $cfid = $1;
- my $cf = $self->LoadCustomFieldByIdentifier($cfid);
- next unless $cf->ObjectTypeFromLookupType->isa(ref $self);
-+ $cf_added{$cfid}++;
-
- foreach my $value (
- UNIVERSAL::isa( $args{$arg} => 'ARRAY' ) ? @{ $args{$arg} } : ( $args{$arg} ) )
-@@
- }
- }
-
-+ my $cfs = $self->QueueObj->TicketCustomFields;
+diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
+--- a/lib/RT/Record.pm
++++ b/lib/RT/Record.pm
+@@
+ }
+ }
+
++=head2 AddCustomFieldDefaultValues
++
++Add default values to object's empty custom fields.
++
++=cut
++
++sub AddCustomFieldDefaultValues {
++ my $self = shift;
++ my $cfs = $self->CustomFields;
++ my @msgs;
+ while ( my $cf = $cfs->Next ) {
-+ next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
-+ my $values = $cf->DefaultValues(Object => $self->QueueObj);
++ next if $self->CustomFieldValues($cf->id)->Count || !$cf->SupportDefaultValues;
++ my $values = $cf->DefaultValues( Object => RT->System );
+ foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
+ next if $self->CustomFieldValueIsEmpty(
+ Field => $cf->id,
@@ -302,9 +262,26 @@
+ Value => $value,
+ RecordTransaction => 0,
+ );
-+ push @non_fatal_errors, $msg unless $status;
++ push @msgs, $msg unless $status;
+ }
+ }
++ return ( 0, @msgs ) if @msgs;
++ return 1;
++}
++
+ =head2 CustomFieldValueIsEmpty { Field => FIELD, Value => VALUE }
+
+ Check if the custom field value is empty.
+
+diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
+--- a/lib/RT/Ticket.pm
++++ b/lib/RT/Ticket.pm
+@@
+ }
+ }
+
++ my ( $status, @msgs ) = $self->AddCustomFieldDefaultValues;
++ push @non_fatal_errors, @msgs unless $status;
+
# Deal with setting up links
@@ -314,44 +291,11 @@
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@
- $args = \%args;
- }
-
-+ my %cf_added;
- foreach my $arg ( keys %$args ) {
- next
- unless ( $arg =~
-@@
- my $values = $args->{$arg};
- my $cf = $self->LoadCustomFieldByIdentifier($cfid);
- next unless $cf->ObjectTypeFromLookupType->isa(ref $self);
-+ $cf_added{$cfid}++;
- foreach
- my $value ( UNIVERSAL::isa( $values, 'ARRAY' ) ? @$values : $values )
- {
-@@
);
}
}
+
-+ my $cfs = $self->Object->TransactionCustomFields;
-+ while ( my $cf = $cfs->Next ) {
-+ next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
-+ my ( $on ) = grep { $_->isa( $cf->RecordClassFromLookupType ) } $cf->ACLEquivalenceObjects;
-+ my $values = $cf->DefaultValues( Object => $on || RT->System );
-+ foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
-+ next if $self->CustomFieldValueIsEmpty(
-+ Field => $cf->id,
-+ Value => $value,
-+ );
-+
-+ $self->_AddCustomFieldValue(
-+ Field => $cf->id,
-+ Value => $value,
-+ RecordTransaction => 0,
-+ );
-+ }
-+ }
++ $self->AddCustomFieldDefaultValues;
}
=head2 LoadCustomFieldByIdentifier
@@ -390,180 +334,6 @@
# Delete any fields that want to be deleted
foreach my $key ( keys %ARGS ) {
-diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
-new file mode 100644
---- /dev/null
-+++ b/share/html/Admin/Queues/DefaultValues.html
-@@
-+%# 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 }}}
-+<& /Admin/Elements/Header, Title => $title &>
-+<& /Elements/Tabs &>
-+<& /Elements/ListActions, actions => \@results &>
-+
-+<form method="post" action="DefaultValues.html" name="ModifyDefaultValues" id="ModifyDefaultValues">
-+<input type="hidden" name="id" value="<% $queue->id %>" />
-+
-+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Basics') ) {
-+<div class="ticket-info-basics">
-+ <&| /Widgets/TitleBox, title => loc('Basics') &>
-+ <table border="0">
-+ <& /Elements/EditCustomFields,
-+ NamePrefix => 'Default-',
-+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
-+ Grouping => 'Basics',
-+ InTable => 1,
-+ &>
-+ </table>
-+ </&>
-+</div>
-+% }
-+
-+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Dates') ) {
-+<div class="ticket-info-dates">
-+ <&|/Widgets/TitleBox, title => loc("Dates") &>
-+ <table>
-+ <& /Elements/EditCustomFields,
-+ NamePrefix => 'Default-',
-+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
-+ Grouping => 'Dates',
-+ InTable => 1,
-+ &>
-+ </table>
-+ </&>
-+</div>
-+% }
-+
-+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'People') ) {
-+<div class="ticket-info-people">
-+ <&|/Widgets/TitleBox, title => loc("People") &>
-+ <table>
-+ <& /Elements/EditCustomFields,
-+ NamePrefix => 'Default-',
-+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
-+ Grouping => 'People',
-+ InTable => 1,
-+ &>
-+ </table>
-+ </&>
-+</div>
-+% }
-+
-+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Links') ) {
-+<div class="ticket-info-links">
-+ <&|/Widgets/TitleBox, title => loc("Links") &>
-+ <table>
-+ <& /Elements/EditCustomFields,
-+ NamePrefix => 'Default-',
-+ Object => RT::Ticket->new($session{CurrentUser}),
-+ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
-+ Grouping => 'Links',
-+ InTable => 1,
-+ &>
-+ </table>
-+ </&>
-+</div>
-+% }
-+
-+<& /Elements/EditCustomFieldCustomGroupings, CustomFieldGenerator => sub { $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes }, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}) &>
-+
-+<div class="ticket-info-cfs">
-+ <&|/Widgets/TitleBox, title => loc("Transaction Custom Fields") &>
-+ <table>
-+ <& /Elements/EditCustomFields, CustomFields => $queue->TicketTransactionCustomFields->LimitToDefaultValuesSupportedTypes, NamePrefix => 'Default-', Object => RT::Transaction->new($session{CurrentUser}), QueueObj => $queue, InTable => 1 &>
-+ </table>
-+ </&>
-+</div>
-+
-+<& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
-+<& /Elements/Submit, Name => 'Reset', Label => loc('Reset Custom Field Values to Default') &>
-+</form>
-+
-+<%INIT>
-+my $queue = RT::Queue->new( $session{CurrentUser} );
-+$queue->Load($id) || Abort( loc( "Couldn't load object [_1]", $id ) );
-+
-+my $title = loc( 'Default Values for queue [_1]', $queue->Name );
-+
-+my @results;
-+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 $cf_id ( map { /^Default-(\d+)-/ ? $1 : () } keys %ARGS ) {
-+ my $cf = RT::CustomField->new($session{CurrentUser});
-+ $cf->Load($cf_id);
-+ if ( $cf->id && $cf->SupportDefaultValues ) {
-+ my ($ret, $msg) = $cf->SetDefaultValues(
-+ Object => $queue,
-+ Values => $ARGS{'Default-' . $cf->id . '-Value'} // $ARGS{'Default-' . $cf->id . '-Values'},
-+ );
-+ push @results, $msg;
-+ }
-+ }
-+}
-+
-+MaybeRedirectForResults(
-+ Actions => \@results,
-+ Arguments => { id => $queue->id },
-+);
-+</%INIT>
-+<%ARGS>
-+$id => undef
-+</%ARGS>
-
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -572,23 +342,10 @@
}
+if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
-+ my ( $on ) = grep {$_->isa($CustomField->RecordClassFromLookupType)} $CustomField->ACLEquivalenceObjects;
-+ $Default = $CustomField->DefaultValues(Object => $on || RT->System);
++ $Default = $CustomField->DefaultValues(Object => RT->System);
+}
+
my $MaxValues = $CustomField->MaxValues;
if ($MaxValues == 1 && $Values) {
# what exactly is this doing? Without the "unless" it breaks RTFM
-diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
---- a/share/html/Elements/Tabs
-+++ b/share/html/Elements/Tabs
-@@
- $queue->child( 'group-rights' => title => loc('Group Rights'), path => "/Admin/Queues/GroupRights.html?id=".$id );
- $queue->child( 'user-rights' => title => loc('User Rights'), path => "/Admin/Queues/UserRights.html?id=" . $id );
- $queue->child( 'history' => title => loc('History'), path => "/Admin/Queues/History.html?id=" . $id );
-+ $queue->child( 'default-values' => title => loc('Default Values'), path => "/Admin/Queues/DefaultValues.html?id=" . $id );
-
- $m->callback( CallbackName => 'PrivilegedQueue', queue_id => $id, page_menu => $queue);
- }
-
-: ------- > 3: d2a07fc queue level cf default values support
4: 2c2506e = 4: b729b61 clear caches after each web request for tests(thanks to chmrr++)
5: d668084 = 5: f5952d0 no need to clear these caches explicitly
6: 33d1cdf ! 6: 1d926af queue-level default values for priority/due
@@ -330,7 +330,7 @@
-% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Basics') ) {
<div class="ticket-info-basics">
<&| /Widgets/TitleBox, title => loc('Basics') &>
- <table border="0">
+ <table>
+ <tr><td class="label"><&|/l&>Priority</&>:</td>
+ <td><& /Elements/SelectPriority,
+ Name => "InitialPriority",
@@ -434,8 +434,8 @@
% }
<select name="QueueField">
--% foreach my $col (qw(Name Description CorrespondAddress CommentAddress InitialPriority FinalPriority DefaultDueIn)) {
-+% foreach my $col (qw(Name Description CorrespondAddress CommentAddress)) {
+-% foreach my $col (qw(Name Description CorrespondAddress CommentAddress InitialPriority FinalPriority DefaultDueIn Lifecycle SubjectTag)) {
++% foreach my $col (qw(Name Description CorrespondAddress CommentAddress Lifecycle SubjectTag)) {
<option <% $QueueField eq $col ? 'selected="selected"' : '' |n %> value="<% $col %>"><% loc($col) %></option>
% }
</select>
7: 873d062 = 7: e567a94 queue level default value for Starts
More information about the rt-commit
mailing list