summaryrefslogtreecommitdiff
path: root/rt/lib
diff options
context:
space:
mode:
authormark <mark>2011-05-31 23:30:13 +0000
committermark <mark>2011-05-31 23:30:13 +0000
commite02e5448d8fdad322dbe5562f92d9623e5d6f0dd (patch)
tree0b7385d69d9a8bac89f8d7387387faa8eb55ac2e /rt/lib
parentdd65ba99bb9281571f19744154a3b03bcd3f01ab (diff)
improve mandatory fields, #9260
Diffstat (limited to 'rt/lib')
-rw-r--r--rt/lib/RT/CustomField.pm4
-rw-r--r--rt/lib/RT/CustomField_Vendor.pm12
-rw-r--r--rt/lib/RT/Interface/Web_Vendor.pm101
-rw-r--r--rt/lib/RT/Ticket_Vendor.pm20
4 files changed, 133 insertions, 4 deletions
diff --git a/rt/lib/RT/CustomField.pm b/rt/lib/RT/CustomField.pm
index c018356b2..0582edd5b 100644
--- a/rt/lib/RT/CustomField.pm
+++ b/rt/lib/RT/CustomField.pm
@@ -122,7 +122,6 @@ sub Create {
Disabled => '0',
LinkToValue => '',
IncludeContentForValue => '',
- Required => '0',
@_);
$self->SUPER::Create(
@@ -382,9 +381,6 @@ sub _CoreAccessible {
{read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
Disabled =>
{read => 1, write => 1, sql_type => 5, length => 6, is_blob => 0, is_numeric => 1, type => 'smallint(6)', default => '0'},
- Required =>
- {read => 1, write => 1, sql_type => 5, length => 6, is_blob => 0, is_numeric => 1, type => 'smallint(6)', default => '0'},
-
}
};
diff --git a/rt/lib/RT/CustomField_Vendor.pm b/rt/lib/RT/CustomField_Vendor.pm
new file mode 100644
index 000000000..9f55c9aa4
--- /dev/null
+++ b/rt/lib/RT/CustomField_Vendor.pm
@@ -0,0 +1,12 @@
+package RT::CustomField;
+use strict;
+no warnings 'redefine';
+
+sub _VendorAccessible {
+ {
+ Required =>
+ {read => 1, write => 1, sql_type => 5, length => 6, is_blob => 0, is_numeric => 1, type => 'smallint(6)', default => '0'},
+ },
+};
+
+1;
diff --git a/rt/lib/RT/Interface/Web_Vendor.pm b/rt/lib/RT/Interface/Web_Vendor.pm
index 1999096a7..c79222be5 100644
--- a/rt/lib/RT/Interface/Web_Vendor.pm
+++ b/rt/lib/RT/Interface/Web_Vendor.pm
@@ -34,6 +34,7 @@ use_ok(RT::Interface::Web_Vendor);
package HTML::Mason::Commands;
use strict;
+no warnings qw(redefine);
=head2 ProcessTicketCustomers
@@ -197,5 +198,105 @@ sub ProcessObjectCustomers {
}
+=head2 ProcessTicketBasics ( TicketObj => $Ticket, ARGSRef => \%ARGS );
+
+Updates all core ticket fields except Status, and returns an array of results
+messages.
+
+=cut
+
+sub ProcessTicketBasics {
+
+ my %args = (
+ TicketObj => undef,
+ ARGSRef => undef,
+ @_
+ );
+
+ my $TicketObj = $args{'TicketObj'};
+ my $ARGSRef = $args{'ARGSRef'};
+
+ # {{{ Set basic fields
+ my @attribs = qw(
+ Subject
+ FinalPriority
+ Priority
+ TimeEstimated
+ TimeWorked
+ TimeLeft
+ Type
+ Queue
+ );
+
+ if ( $ARGSRef->{'Queue'} and ( $ARGSRef->{'Queue'} !~ /^(\d+)$/ ) ) {
+ my $tempqueue = RT::Queue->new($RT::SystemUser);
+ $tempqueue->Load( $ARGSRef->{'Queue'} );
+ if ( $tempqueue->id ) {
+ $ARGSRef->{'Queue'} = $tempqueue->id;
+ }
+ }
+
+ my @results = UpdateRecordObject(
+ AttributesRef => \@attribs,
+ Object => $TicketObj,
+ ARGSRef => $ARGSRef,
+ );
+
+ # We special case owner changing, so we can use ForceOwnerChange
+ if ( $ARGSRef->{'Owner'} && ( $TicketObj->Owner != $ARGSRef->{'Owner'} ) ) {
+ my ($ChownType);
+ if ( $ARGSRef->{'ForceOwnerChange'} ) {
+ $ChownType = "Force";
+ } else {
+ $ChownType = "Give";
+ }
+
+ my ( $val, $msg ) = $TicketObj->SetOwner( $ARGSRef->{'Owner'}, $ChownType );
+ push( @results, $msg );
+ }
+
+ # }}}
+
+ return (@results);
+}
+
+=head2 ProcessTicketStatus (TicketObj => RT::Ticket, ARGSRef => {})
+
+Process updates to the 'Status' field of the ticket. If the new value
+of Status is 'resolved', this will check required custom fields before
+allowing the update.
+
+=cut
+
+sub ProcessTicketStatus {
+ my %args = (
+ TicketObj => undef,
+ ARGSRef => undef,
+ @_
+ );
+
+ my $TicketObj = $args{'TicketObj'};
+ my $ARGSRef = $args{'ARGSRef'};
+ my @results;
+
+ return () if !$ARGSRef->{'Status'};
+
+ if ( lc( $ARGSRef->{'Status'} ) eq 'resolved' ) {
+ foreach my $field ( $TicketObj->MissingRequiredFields ) {
+ push @results, loc('Missing required field: [_1]', $field->Name);
+ }
+ }
+ if ( @results ) {
+ $m->notes('RedirectToBasics' => 1);
+ return @results;
+ }
+
+ return UpdateRecordObject(
+ AttributesRef => [ 'Status' ],
+ Object => $TicketObj,
+ ARGSRef => $ARGSRef,
+ );
+}
+
1;
diff --git a/rt/lib/RT/Ticket_Vendor.pm b/rt/lib/RT/Ticket_Vendor.pm
index 604a84aa2..2039f3e2d 100644
--- a/rt/lib/RT/Ticket_Vendor.pm
+++ b/rt/lib/RT/Ticket_Vendor.pm
@@ -13,4 +13,24 @@ sub SetPriority {
$Ticket->SUPER::SetPriority($value);
}
+=head2 MissingRequiredFields {
+
+Return all custom fields with the Required flag set for which this object
+doesn't have any non-empty values.
+
+=cut
+
+sub MissingRequiredFields {
+ my $self = shift;
+ my $CustomFields = $self->CustomFields;
+ my @results;
+ while ( my $CF = $CustomFields->Next ) {
+ next if !$CF->Required;
+ if ( !length($self->FirstCustomFieldValue($CF->Id) || '') ) {
+ push @results, $CF;
+ }
+ }
+ return @results;
+}
+
1;