Skip to content

Commit

Permalink
Add a separate signal for when something is being unpublished
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-s committed Oct 22, 2019
1 parent 9370420 commit 7ce61de
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
23 changes: 16 additions & 7 deletions djangocms_moderation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,22 @@ def published_view(self, request):
moderation_requests = self._publish_flow(request, treenodes)

post_bulk_actions(collection)
signals.published.send(
sender=self.model,
collection=collection,
moderator=collection.author,
moderation_requests=moderation_requests,
workflow=collection.workflow
)
if collection.workflow.is_unpublishing:
signals.unpublished.send(
sender=self.model,
collection=collection,
moderator=collection.author,
moderation_requests=moderation_requests,
workflow=collection.workflow
)
else:
signals.published.send(
sender=self.model,
collection=collection,
moderator=collection.author,
moderation_requests=moderation_requests,
workflow=collection.workflow
)
return HttpResponseRedirect(redirect_url)

def rework_view(self, request):
Expand Down
9 changes: 9 additions & 0 deletions djangocms_moderation/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@
"workflow"
]
)

unpublished = django.dispatch.Signal(
providing_args=[
"collection",
"moderator",
"moderation_requests",
"workflow"
]
)
28 changes: 22 additions & 6 deletions tests/test_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ModerationRequestTreeNode,
Role,
)
from djangocms_moderation.signals import published
from djangocms_moderation.signals import published, unpublished

from .utils import factories

Expand Down Expand Up @@ -604,11 +604,6 @@ def setUp(self):

@mock.patch("django.contrib.messages.success")
def test_unpublish_selected_unpublishes_approved_request(self, message_mock):

# resp = self.client.get(self.url)
# import pdb; pdb.set_trace()

print('correct flow')
data = get_url_data(self, "unpublish_selected")
response = self.client.post(self.url, data)
# And now go to the view the action redirects to
Expand All @@ -628,6 +623,27 @@ def test_unpublish_selected_unpublishes_approved_request(self, message_mock):
self.assertFalse(self.mr1.is_active)
self.assertTrue(self.mr2.is_active)

def test_signal_when_unpublished(self):
"""
A signal should be sent so further action can be taken when a moderation
collection is being unpublished.
"""
data = get_url_data(self, "unpublish_selected")
response = self.client.post(self.url, data)

with signal_tester(unpublished) as signal:
# And now go to the view the action redirects to
self.client.post(response.url)
args, kwargs = signal.calls[0]
published_mr = kwargs['moderation_requests']
self.assertEquals(signal.call_count, 1)
self.assertEquals(kwargs['sender'], ModerationRequest)
self.assertEquals(kwargs['collection'], self.collection)
self.assertEquals(kwargs['moderator'], self.collection.author)
self.assertEquals(len(published_mr), 1)
self.assertEquals(published_mr[0], self.mr1)
self.assertEquals(kwargs['workflow'], self.collection.workflow)


class PublishSelectedTest(CMSTestCase):

Expand Down

0 comments on commit 7ce61de

Please sign in to comment.