diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 3eda287cc..fba7c0f4c 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.10.22 + - fixed #12206: Bad Subscription Groups in Duplicated Threads 7.10.21 - added #9668 extension template variable to attachment loops for the following assets: diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 3b3bfb40d..0c69584c9 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -268,15 +268,17 @@ sub duplicate { my $self = shift; my $session = $self->session; my $copy = $self->SUPER::duplicate(@_); - my $oldGroupId = $self->get('subscriptionGroupId'); + my $key = 'subscriptionGroupId'; + my $oldGroupId = $self->get($key); if ($oldGroupId) { - my $newGroup = WebGUI::Group->new($session, 'new'); - my $oldGroup = WebGUI::Group->new($session, $oldGroupId); - if ($oldGroup) { + $copy->update({ $key => '' }); + $copy->createSubscriptionGroup(); + if (my $oldGroup = WebGUI::Group->new($session, $oldGroupId)) { + my $newGroup = WebGUI::Group->new($session, $copy->get($key)); $newGroup->addUsers($oldGroup->getUsers('withoutExpired')); + $newGroup->addGroups($oldGroup->getGroupsIn); } - $copy->update({subscriptionGroupId => $newGroup->getId}); } return $copy; } diff --git a/t/Asset/Post/Thread/bug_12206_bad_subscription_groups_in_duplicate.t b/t/Asset/Post/Thread/bug_12206_bad_subscription_groups_in_duplicate.t new file mode 100644 index 000000000..c2bd5390b --- /dev/null +++ b/t/Asset/Post/Thread/bug_12206_bad_subscription_groups_in_duplicate.t @@ -0,0 +1,46 @@ +# 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 +#------------------------------------------------------------------ + +=head1 BUG DESCRIPTION + +When Thread assets are copied, a new subscription group gets created for them, +but not by calling $thread->createSubscriptionGroup. Instead, a "blank" group +is created, and then the users from the old group are added to it -- which by +default has Admins subscribed in it. So, every time we copy a thread, our +admins start getting spammed with subscription updates. + +=cut + +use warnings; +use strict; + +use Test::More tests => 2; +use Test::Exception; +use FindBin; + +use lib "$FindBin::Bin/../../../lib"; +use WebGUI::Test; +use WebGUI::Asset; + +my $session = WebGUI::Test->session; +my $thread = WebGUI::Asset->getImportNode($session)->addChild( + { + className => 'WebGUI::Asset::Post::Thread', + } +); +WebGUI::Test->addToCleanup($thread); +$thread->createSubscriptionGroup(); +my $admin = WebGUI::User->new($session, 3); +ok !$admin->isInGroup($thread->get('subscriptionGroupId')); + +$thread = $thread->duplicate(); +WebGUI::Test->addToCleanup($thread); +ok !$admin->isInGroup($thread->get('subscriptionGroupId'));