Skip to content

Commit

Permalink
Added support for Cc and Bcc to generic interface operations TicketCr…
Browse files Browse the repository at this point in the history
…eate and TicketUpdate.
  • Loading branch information
jepf committed Aug 23, 2019
1 parent 3564309 commit 1ddd297
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 112 deletions.
54 changes: 9 additions & 45 deletions Custom/Kernel/GenericInterface/Operation/Ticket/Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# Copyright (C) 2012-2019 Znuny GmbH, http://znuny.com/
# --
# $origin: otrs - 91c2cc2962e5a03d6538ca68d6196c117a41a29d - Kernel/GenericInterface/Operation/Ticket/Common.pm
# $origin: otrs - b9cf29ede488bbc3bf5bd0d49f422ecc65668a0c - Kernel/GenericInterface/Operation/Ticket/Common.pm
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
Expand Down Expand Up @@ -309,7 +309,7 @@ sub ValidateCustomer {

# if customer is not registered in the database, check if email is valid
if ( !IsHashRefWithData( \%CustomerData ) ) {
return $Self->ValidateFrom( From => $Param{CustomerUser} )
return $Self->ValidateFrom( From => $Param{CustomerUser} );
}

# if ValidID is present, check if it is valid!
Expand Down Expand Up @@ -750,7 +750,7 @@ sub ValidatePendingTime {
# check that no time attribute is empty or negative
for my $TimeAttribute ( sort keys %{ $Param{PendingTime} } ) {
return if $Param{PendingTime}->{$TimeAttribute} eq '';
return if int $Param{PendingTime}->{$TimeAttribute} < 0,
return if int $Param{PendingTime}->{$TimeAttribute} < 0;
}

# try to convert pending time to a DateTime object
Expand All @@ -759,7 +759,7 @@ sub ValidatePendingTime {
ObjectParams => {
%{ $Param{PendingTime} },
Second => 0,
}
}
);
return if !$PendingTime;

Expand Down Expand Up @@ -791,7 +791,7 @@ sub ValidateAutoResponseType {
return if !%AutoResponseType;

for my $AutoResponseType ( values %AutoResponseType ) {
return 1 if $AutoResponseType eq $Param{AutoResponseType}
return 1 if $AutoResponseType eq $Param{AutoResponseType};
}
return;
}
Expand Down Expand Up @@ -1166,50 +1166,14 @@ sub ValidateDynamicFieldValue {
# get dynamic field config
my $DynamicFieldConfig = $Self->{DynamicFieldLookup}->{ $Param{Name} };

my $ValueType = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueValidate(
# Validate value.
my $ValidateValue = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->FieldValueValidate(
DynamicFieldConfig => $DynamicFieldConfig,
Value => $Param{Value},
UserID => 1,
);

return if !$ValueType;

# Check if value parameter exists in config of possible values, for example for dropdown/multi-select fields.
# Please see bug#13444 for more information.
if (
defined $Param{Value}
&& length $Param{Value}
&& (
IsArrayRefWithData( $DynamicFieldConfig->{Config}->{PossibleValues} )
|| IsHashRefWithData( $DynamicFieldConfig->{Config}->{PossibleValues} )
)
)
{
my @Values;
if ( ref $Param{Value} eq 'ARRAY' ) {
@Values = @{ $Param{Value} };
}
else {
push @Values, $Param{Value};
}

if ( IsArrayRefWithData( $DynamicFieldConfig->{Config}->{PossibleValues} ) ) {
for my $Value (@Values) {
if ( !grep { $_ eq $Value } @{ $DynamicFieldConfig->{Config}->{PossibleValues} } ) {
return;
}
}
}
else {
for my $Value (@Values) {
if ( !grep { $_ eq $Value } keys %{ $DynamicFieldConfig->{Config}->{PossibleValues} } ) {
return;
}
}
}
}

return 1;
return $ValidateValue;
}

=head2 ValidateDynamicFieldObjectType()
Expand Down Expand Up @@ -1325,7 +1289,7 @@ sub SetDynamicFieldValue {

return {
Success => $Success,
}
};
}

=head2 CreateAttachment()
Expand Down
32 changes: 21 additions & 11 deletions Custom/Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# Copyright (C) 2012-2019 Znuny GmbH, http://znuny.com/
# --
# $origin: otrs - 4fe218beccdb926a29dd7bed9de48211430d69d0 - Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm
# $origin: otrs - 6cfd3aabcdcce0b7305ea3be51c73bd782ca4176 - Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
Expand Down Expand Up @@ -136,6 +136,8 @@ perform TicketCreate Operation. This will return the created ticket number.
# Znuny4OTRS-GIArticleSend
# ---
To => 'some to address', # optional, required if ArticleSend => 1
Cc => 'some Cc address', # optional
Bcc => 'some Bcc address', # optional
# ---
Subject => 'some subject',
Body => 'some body',
Expand Down Expand Up @@ -387,7 +389,7 @@ sub Run {

my $PermissionUserID = $UserID;
if ( $UserType eq 'Customer' ) {
$UserID = $Kernel::OM->Get('Kernel::Config')->Get('CustomerPanelUserID')
$UserID = $Kernel::OM->Get('Kernel::Config')->Get('CustomerPanelUserID');
}

# check needed hashes
Expand Down Expand Up @@ -812,7 +814,7 @@ sub _CheckTicket {
# if everything is OK then return Success
return {
Success => 1,
}
};
}

=head2 _CheckArticle()
Expand Down Expand Up @@ -1467,6 +1469,7 @@ sub _TicketCreate {
# $From = $Ticket->{CustomerUser};
# }


# When we are sending the article as an email, set the from address to the ticket's system address
if (
$Article->{ArticleSend}
Expand Down Expand Up @@ -1515,8 +1518,13 @@ sub _TicketCreate {
# );
# }

my $Cc;
my $Bcc;

if ( $Article->{ArticleSend} ) {
$To = $Article->{To};
$To = $Article->{To};
$Cc = $Article->{Cc};
$Bcc = $Article->{Bcc};
}
elsif ( $Ticket->{Queue} ) {
$To = $Ticket->{Queue};
Expand Down Expand Up @@ -1560,10 +1568,10 @@ sub _TicketCreate {
# ---
# # Create article.
# my $ArticleID = $ArticleBackendObject->ArticleCreate(
# NoAgentNotify => $Article->{NoAgentNotify} || 0,
# TicketID => $TicketID,
# SenderTypeID => $Article->{SenderTypeID} || '',
# SenderType => $Article->{SenderType} || '',
# NoAgentNotify => $Article->{NoAgentNotify} || 0,
# TicketID => $TicketID,
# SenderTypeID => $Article->{SenderTypeID} || '',
# SenderType => $Article->{SenderType} || '',
# IsVisibleForCustomer => $Article->{IsVisibleForCustomer},
# From => $From,
# To => $To,
Expand Down Expand Up @@ -1643,6 +1651,8 @@ sub _TicketCreate {
IsVisibleForCustomer => $Article->{IsVisibleForCustomer},
From => $From,
To => $To,
Cc => $Cc,
Bcc => $Bcc,
Subject => $Subject,
Body => $Article->{Body},
MimeType => $MimeType || '',
Expand Down Expand Up @@ -1842,7 +1852,7 @@ sub _TicketCreate {
Success => 0,
ErrorMessage => 'Could not get new ticket information, please contact the system'
. ' administrator',
}
};
}

# get web service configuration
Expand Down Expand Up @@ -1935,8 +1945,8 @@ sub _TicketCreate {

next ATTACHMENT if !IsHashRefWithData( \%Attachment );

# convert content to base64
$Attachment{Content} = MIME::Base64::encode_base64( $Attachment{Content} );
# convert content to base64, but prevent 76 chars brake, see bug#14500.
$Attachment{Content} = MIME::Base64::encode_base64( $Attachment{Content}, '' );
push @Attachments, {%Attachment};
}

Expand Down
Loading

0 comments on commit 1ddd297

Please sign in to comment.