[Rt-commit] rt branch, 4.4/cf-default-values, updated. rt-4.2.3-206-g4f67026
? sunnavy
sunnavy at bestpractical.com
Wed Jun 11 13:06:57 EDT 2014
The branch, 4.4/cf-default-values has been updated
via 4f67026e92003a0b3475fcec26444dd1e6f45512 (commit)
via 655a063ce20a89fb5adaa55e2ec31478454ab678 (commit)
via d49c2749a22e8f0cbd1fd9c8a45e149adac49190 (commit)
from 782b3fd46ee342f662fc5ce8454127af0bc64ba4 (commit)
Summary of changes:
lib/RT/CustomField.pm | 42 ++++++++++++++------
lib/RT/Ticket.pm | 21 ++++++++++
lib/RT/Transaction.pm | 20 ++++++++++
.../UserRights.html => Queues/DefaultValues.html} | 46 ++++++++++++++--------
share/html/Elements/EditCustomField | 2 +-
share/html/Elements/Tabs | 1 +
share/html/Ticket/Create.html | 4 ++
.../Ticket/Elements/EditTransactionCustomFields | 1 +
8 files changed, 108 insertions(+), 29 deletions(-)
copy share/html/Admin/{CustomFields/UserRights.html => Queues/DefaultValues.html} (60%)
- Log -----------------------------------------------------------------
commit d49c2749a22e8f0cbd1fd9c8a45e149adac49190
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Jun 11 20:11:49 2014 +0800
allow default values for Ticket/Txn cfs only for now
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 547aa34..de2d29e 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1887,6 +1887,7 @@ sub BasedOnObj {
sub SupportDefaultValues {
my $self = shift;
return 0 unless $self->id;
+ return 0 unless $self->LookupType =~ /RT::(?:Ticket|Transaction)$/;
return $self->Type !~ /^(?:Image|Binary)$/;
}
commit 655a063ce20a89fb5adaa55e2ec31478454ab678
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Jun 11 20:14:41 2014 +0800
fill default custom field values on ticket/txn creation
so we can cover all kinds of ways of ticket/txn creation
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 42abbca..f9e901c 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -468,11 +468,13 @@ sub Create {
}
# 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} ) )
@@ -495,6 +497,25 @@ sub Create {
}
}
+ my $cfs = $self->QueueObj->TicketCustomFields;
+ while ( my $cf = $cfs->Next ) {
+ next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
+ my $values = $cf->DefaultValues(Object => RT->System); # TODO support queue-level default values
+ foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
+ next if $self->CustomFieldValueIsEmpty(
+ Field => $cf->id,
+ Value => $value,
+ );
+
+ my ( $status, $msg ) = $self->_AddCustomFieldValue(
+ Field => $cf->id,
+ Value => $value,
+ RecordTransaction => 0,
+ );
+ push @non_fatal_errors, $msg unless $status;
+ }
+ }
+
# Deal with setting up links
# TODO: Adding link may fire scrips on other end and those scrips
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index f6329b5..0f369f0 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1398,6 +1398,7 @@ sub UpdateCustomFields {
$args = \%args;
}
+ my %cf_added;
foreach my $arg ( keys %$args ) {
next
unless ( $arg =~
@@ -1407,6 +1408,7 @@ sub UpdateCustomFields {
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 )
{
@@ -1421,6 +1423,24 @@ sub UpdateCustomFields {
);
}
}
+
+ my $cfs = $self->Object->TransactionCustomFields;
+ while ( my $cf = $cfs->Next ) {
+ next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
+ my $values = $cf->DefaultValues(Object => RT->System); # TODO support queue-level default values
+ 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,
+ );
+ }
+ }
}
=head2 LoadCustomFieldByIdentifier
commit 4f67026e92003a0b3475fcec26444dd1e6f45512
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Jun 12 01:06:25 2014 +0800
queue-level default custom fields
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index de2d29e..b36dfb8 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1898,7 +1898,15 @@ sub DefaultValues {
@_,
);
my $attr = $args{Object}->FirstAttribute('CustomFieldDefaultValues');
- return $attr->Content->{$self->id} if $attr && $attr->Content;
+ 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;
}
@@ -1910,16 +1918,18 @@ sub SetDefaultValues {
@_,
);
my $attr = $args{Object}->FirstAttribute( 'CustomFieldDefaultValues' );
- my ( $old_content, $old_values );
- $old_content = $attr->Content if $attr && $attr->Content;
- $old_values = $old_content->{ $self->id } if $old_content;
+ my ( $old_values, $old_content, $new_values );
+ if ( $attr && $attr->Content ) {
+ $old_content = $attr->Content;
+ $old_values = $old_content->{ $self->id };
+ }
- my $ret = $args{Object}->SetAttribute(
- Name => 'CustomFieldDefaultValues',
- Content => {
- %{ $old_content || {} }, $self->id => $args{Values},
- },
- );
+ 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';
@@ -1928,7 +1938,7 @@ sub SetDefaultValues {
$old_values = $self->loc('(no value)');
}
- my $new_values = $args{Values};
+ $new_values = $args{Values};
if ( defined $new_values && length $new_values ) {
$new_values = join ', ', @$new_values if ref $new_values eq 'ARRAY';
}
@@ -1936,6 +1946,15 @@ sub SetDefaultValues {
$new_values = $self->loc( '(no value)' );
}
+ return 1 if $new_values eq $old_values;
+
+ my $ret = $args{Object}->SetAttribute(
+ Name => 'CustomFieldDefaultValues',
+ Content => {
+ %{ $old_content || {} }, $self->id => $args{Values},
+ },
+ );
+
if ( $ret ) {
return ( $ret, $self->loc( 'Default values changed from [_1] to [_2]', $old_values, $new_values ) );
}
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index f9e901c..bc14fdb 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -500,7 +500,7 @@ sub Create {
my $cfs = $self->QueueObj->TicketCustomFields;
while ( my $cf = $cfs->Next ) {
next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
- my $values = $cf->DefaultValues(Object => RT->System); # TODO support queue-level default values
+ my $values = $cf->DefaultValues(Object => $self->QueueObj);
foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
next if $self->CustomFieldValueIsEmpty(
Field => $cf->id,
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 0f369f0..03f99fe 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1427,7 +1427,7 @@ sub UpdateCustomFields {
my $cfs = $self->Object->TransactionCustomFields;
while ( my $cf = $cfs->Next ) {
next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
- my $values = $cf->DefaultValues(Object => RT->System); # TODO support queue-level default values
+ my $values = $cf->DefaultValues(Object => $self->Object->QueueObj);
foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
next if $self->CustomFieldValueIsEmpty(
Field => $cf->id,
diff --git a/share/html/Ticket/Elements/EditTransactionCustomFields b/share/html/Admin/Queues/DefaultValues.html
similarity index 56%
copy from share/html/Ticket/Elements/EditTransactionCustomFields
copy to share/html/Admin/Queues/DefaultValues.html
index 49a5224..456575c 100644
--- a/share/html/Ticket/Elements/EditTransactionCustomFields
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -45,62 +45,44 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-% $m->callback( CallbackName => 'BeforeTransactionCustomFields', TicketObj => $TicketObj, QueueObj => $QueueObj, InTable => $InTable );
-% if ( $WRAP ) {
-<<% $WRAP %> class="edit-transaction-custom-fields">
-% }
-% if ($CustomFields->Count) {
-% while (my $CF = $CustomFields->Next()) {
-% next unless $CF->CurrentUserHasRight('ModifyCustomField');
-<<% $FIELD %>>
-<<% $CELL %> class="label cflabel">
- <span class="name"><% $CF->Name %>:</span><br />
- <span class="type"><% $CF->EntryHint // '' %></span>
-</<% $CELL %>>
-<<% $CELL %>>
-<& /Elements/EditCustomField,
- CustomField => $CF,
- Object => RT::Transaction->new( $session{'CurrentUser'} ),
-&>
-% if (my $msg = $m->notes('InvalidField-' . $CF->Id)) {
- <br />
- <span class="cfinvalidfield"><% $msg %></span>
-% }
-</<% $CELL %>>
-</<% $FIELD %>>
-% }
-% }
-% if ( $WRAP ) {
-</<% $WRAP %>>
-% }
-% $m->callback( CallbackName => 'AfterTransactionCustomFields', TicketObj => $TicketObj, QueueObj => $QueueObj, InTable => $InTable );
+<& /Admin/Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
+<& /Elements/ListActions, actions => \@results &>
-<%INIT>
-my $CustomFields;
+<form method="post" action="DefaultValues.html" name="ModifyDefaultValues" id="ModifyDefaultValues">
+<input type="hidden" name="id" value="<% $queue->id %>" />
+<h2><&|/l&>Ticket Custom Fields</&></h2>
+<& /Elements/EditCustomFields, CustomFields => $ticket_cfs, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}), QueueObj => $queue &>
-if ($TicketObj) {
- $CustomFields = $TicketObj->TransactionCustomFields();
-} else {
- $CustomFields = $QueueObj->TicketTransactionCustomFields();
-}
+<h2><&|/l&>Transaction Custom Fields</&></h2>
+<& /Elements/EditCustomFields, CustomFields => $txn_cfs, NamePrefix => 'Default-', Object => RT::Transaction->new($session{CurrentUser}), QueueObj => $queue &>
-$m->callback( CallbackName => 'MassageTransactionCustomFields', CustomFields => $CustomFields, InTable => $InTable );
+<& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
+</form>
-$AsTable ||= $InTable;
-my $FIELD = $AsTable ? 'tr' : 'div';
-my $CELL = $AsTable ? 'td' : 'div';
-my $WRAP = '';
-if ( $AsTable ) {
- $WRAP = 'table' unless $InTable;
-} else {
- $WRAP = 'div';
-}
+<%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 $ticket_cfs = $queue->TicketCustomFields;
+my $txn_cfs = $queue->TicketTransactionCustomFields;
+
+my @results;
+if ( $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;
+ }
+ }
+}
</%INIT>
<%ARGS>
-$TicketObj => undef
-$QueueObj => undef
-$AsTable => 0
-$InTable => 0
+$id => undef
</%ARGS>
-
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 9887217..debaaa4 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -91,7 +91,7 @@ if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
}
if ( ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
- $Default = $CustomField->DefaultValues;
+ $Default = $CustomField->DefaultValues( Object => $ARGS{QueueObj} || RT->System );
}
my $MaxValues = $CustomField->MaxValues;
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 0b3a50e..fb435b4 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -307,6 +307,7 @@ my $build_admin_menu = sub {
$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);
}
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 57e66df..ede62bd 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -105,6 +105,7 @@
CustomFields => $QueueObj->TicketCustomFields,
Grouping => 'Basics',
InTable => 1,
+ QueueObj => $QueueObj,
&>
<& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
</table>
@@ -115,6 +116,7 @@
%ARGS,
Object => $ticket,
CustomFieldGenerator => sub { $QueueObj->TicketCustomFields },
+ QueueObj => $QueueObj,
&>
</div>
@@ -169,6 +171,7 @@
CustomFields => $QueueObj->TicketCustomFields,
Grouping => 'People',
InTable => 1,
+ QueueObj => $QueueObj,
&>
<tr>
@@ -263,6 +266,7 @@
CustomFields => $QueueObj->TicketCustomFields,
Grouping => 'Dates',
InTable => 1,
+ QueueObj => $QueueObj,
&>
</table>
</&>
diff --git a/share/html/Ticket/Elements/EditTransactionCustomFields b/share/html/Ticket/Elements/EditTransactionCustomFields
index 49a5224..4f30c6e 100644
--- a/share/html/Ticket/Elements/EditTransactionCustomFields
+++ b/share/html/Ticket/Elements/EditTransactionCustomFields
@@ -61,6 +61,7 @@
<& /Elements/EditCustomField,
CustomField => $CF,
Object => RT::Transaction->new( $session{'CurrentUser'} ),
+ QueueObj => $QueueObj,
&>
% if (my $msg = $m->notes('InvalidField-' . $CF->Id)) {
<br />
-----------------------------------------------------------------------
More information about the rt-commit
mailing list