diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ad57aaec5..b30429113 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.7.19 + - fixed #10838: Forwarded forum post email to new CS adds reply to original thread - fixed #10872: Purging an asset leaves old version tags - fixed #10867: EMS: can't set Ticket time - fixed #10855: Bug in submitting data to ITransact diff --git a/lib/WebGUI/Workflow/Activity/GetCsMail.pm b/lib/WebGUI/Workflow/Activity/GetCsMail.pm index 109f5ffda..ab7aeaac2 100644 --- a/lib/WebGUI/Workflow/Activity/GetCsMail.pm +++ b/lib/WebGUI/Workflow/Activity/GetCsMail.pm @@ -204,7 +204,12 @@ sub execute { my $post = undef; if ($message->{inReplyTo} && $message->{inReplyTo} =~ m/cs\-([\w_-]{22})\@/) { my $id = $1; - $post = WebGUI::Asset->newByDynamicClass($self->session, $id); + my $repliedPost = WebGUI::Asset->newByDynamicClass($self->session, $id); + if ($repliedPost + && $repliedPost->isa('WebGUI::Asset::Post') + && $repliedPost->getThread->getParent->getId eq $cs->getId) { + $post = $repliedPost; + } } if (defined $post && $cs->get("allowReplies") && $user->isInGroup($cs->get("postGroupId")) && (!$cs->get("requireSubscriptionForEmailPosting") || $user->isInGroup($cs->get("subscriptionGroupId")) || $user->isInGroup($post->get("subscriptionGroupId")))) { diff --git a/t/Workflow/Activity/GetCsMail.t b/t/Workflow/Activity/GetCsMail.t new file mode 100644 index 000000000..014ae95de --- /dev/null +++ b/t/Workflow/Activity/GetCsMail.t @@ -0,0 +1,154 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; +use Test::More; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; +use Test::MockObject; +use Test::MockObject::Extends; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 4; # Increment this number for each test you create + +my $sendmock = Test::MockObject->new( {} ); +$sendmock->set_isa('WebGUI::Mail::Send'); +$sendmock->set_true('addText', 'send'); +local *WebGUI::Mail::Send::create; +$sendmock->fake_module('WebGUI::Mail::Send', + create => sub { return $sendmock }, +); + +my $getmock = Test::MockObject->new( {} ); +$getmock->set_isa('WebGUI::Mail::Get'); +# false for now. use set_series later to add list of messages. +$getmock->set_false('getNextMessage'); +$getmock->set_true('disconnect'); +local *WebGUI::Mail::Get::connect; +$getmock->fake_module('WebGUI::Mail::Get', + connect => sub { return $getmock }, +); + +my $activity = Test::MockObject::Extends->new( 'WebGUI::Workflow::Activity::GetCsMail' ); +$activity->set_always('session', $session); +$activity->set_always('getTTL', 60); +$activity->set_always('COMPLETE', 'complete'); +my $parentAsset; +$activity->mock('addPost', sub { $parentAsset = $_[1] } ); + +my $cs_id = 'MAILCS________________'; +my $post_id = 'MAILCSPOST____________'; +my $cs2_id = 'OTHERCS_______________'; +my $post2_id = 'OTHERCSPOST___________'; + +my $csmock = Test::MockObject->new({ + getMail => 1, + postGroupId => 7, + allowReplies => 1, +}); +$csmock->set_isa('WebGUI::Asset::Wobject::Collaboration'); +$csmock->mock('get', sub { + my $self = shift; + if (@_) { + return $self->{$_[0]}; + } + return $self; +}); +$csmock->set_always('getId', $cs_id); + +my $postmock = Test::MockObject->new( {} ); +$postmock->set_isa('WebGUI::Asset::Post::Thread', 'WebGUI::Asset::Post'); +$postmock->set_always('getThread', $postmock); +$postmock->set_always('getParent', $csmock); +$postmock->set_always('getId', $post_id); + +my $cs2mock = Test::MockObject->new({}); +$cs2mock->set_isa('WebGUI::Asset::Wobject::Collaboration'); +$cs2mock->set_always('getId', $cs2_id); + +my $post2mock = Test::MockObject->new( {} ); +$post2mock->set_isa('WebGUI::Asset::Post::Thread', 'WebGUI::Asset::Post'); +$post2mock->set_always('getThread', $post2mock); +$post2mock->set_always('getParent', $cs2mock); +$post2mock->set_always('getId', $post2_id); + +{ + $getmock->set_series('getNextMessage', { + from => 'admin@localhost', + parts => ['parts'], + subject => 'Subject', + messageId => 'Message Id', + }); + $activity->execute($csmock); + is $parentAsset->getId, $cs_id, 'add as new thread to current cs if not reply'; +} + +{ + # simulate asset not found + local *WebGUI::Asset::newByDynamicClass = sub { + return undef; + }; + $getmock->set_series('getNextMessage', { + from => 'admin@localhost', + parts => ['parts'], + subject => 'Subject', + messageId => 'Message Id', + inReplyTo => 'cs-' . $post2_id . '@', + }); + $activity->execute($csmock); + is $parentAsset->getId, $cs_id, 'add as new thread to current cs if reply to nonexistant post'; +} + +{ + local *WebGUI::Asset::newByDynamicClass = sub { + return $post2mock; + }; + $getmock->set_series('getNextMessage', { + from => 'admin@localhost', + parts => ['parts'], + subject => 'Subject', + messageId => 'Message Id', + inReplyTo => 'cs-' . $post2_id . '@', + }); + $activity->execute($csmock); + is $parentAsset->getId, $cs_id, 'add as new thread to current cs if reply to post in another CS'; +} + +{ + local *WebGUI::Asset::newByDynamicClass = sub { + return $postmock; + }; + $getmock->set_series('getNextMessage', { + from => 'admin@localhost', + parts => ['parts'], + subject => 'Subject', + messageId => 'Message Id', + inReplyTo => 'cs-' . $post_id . '@', + }); + $activity->execute($csmock); + is $parentAsset->getId, $post_id, 'add as reply to post if reply to post in current CS'; +} + +#---------------------------------------------------------------------------- +# Cleanup +END { + +} +#vim:ft=perl