Skip to content

Commit

Permalink
Merge pull request #5189 from onepercentclub/bugfix/BB-20318-team-acc…
Browse files Browse the repository at this point in the history
…ept-reject-mails

Bugfix/bb 20318 team accept reject mails
  • Loading branch information
gannetson committed Aug 10, 2022
2 parents be3d3c6 + 7aa41d1 commit bd50a53
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 38 deletions.
22 changes: 17 additions & 5 deletions bluebottle/activities/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def action_link(self):
action_title = pgettext('email', 'View activity')

def get_recipients(self):
"""activity mananager"""
"""activity manager"""
return [self.obj.activity.owner]


Expand All @@ -300,13 +300,19 @@ class TeamAppliedMessage(TeamNotification):
template = 'messages/team_applied'


class TeamAcceptedMessage(TeamNotification):
class TeamCaptainAcceptedMessage(TeamNotification):
subject = pgettext('email', 'Your team has been accepted for "{title}"')
template = 'messages/team_accepted'

context = {
'title': 'activity.title',
'team_captain_email': 'team.owner.email',
'team_name': 'team.name'
}

def get_recipients(self):
"""team captain"""
return [self.obj.owner]
return [self.obj.user]


class TeamCancelledMessage(TeamNotification):
Expand All @@ -321,12 +327,18 @@ def get_recipients(self):


class TeamCancelledTeamCaptainMessage(TeamNotification):
subject = pgettext('email', "Your team has been rejected for '{title}'")
subject = pgettext('email', 'Your team has been rejected for "{title}"')
template = 'messages/team_cancelled_team_captain'

context = {
'title': 'activity.title',
'team_captain_email': 'team.owner.email',
'team_name': 'team.name'
}

def get_recipients(self):
"""team captain"""
return [self.obj.owner]
return [self.obj.user]


class TeamWithdrawnMessage(TeamNotification):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "mails/messages/activity_base.html" %}
{% load i18n %}

{% block message%}
{% block message %}
<p>
{% if custom_message %}
{{custom_message|linebreaks}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

{% block message%}
<p>
{% blocktrans context 'email' %}Unfortunately, your team has been rejected for the activity '{{title}}'.{% endblocktrans %}
{% if custom_message %}
{{custom_message|linebreaks}}
{% else %}
{% blocktrans context 'email' %}Unfortunately, your team has been rejected for the activity '{{title}}'.{% endblocktrans %}
{% endif %}
</p>
{% endblock %}
22 changes: 16 additions & 6 deletions bluebottle/activities/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
ActivityRejectedNotification, ActivityCancelledNotification,
ActivitySucceededNotification, ActivityRestoredNotification,
ActivityExpiredNotification, TeamAddedMessage,
TeamAppliedMessage, TeamAcceptedMessage, TeamCancelledMessage,
TeamAppliedMessage, TeamCancelledMessage,
TeamCancelledTeamCaptainMessage, TeamWithdrawnActivityOwnerMessage,
TeamWithdrawnMessage, TeamMemberAddedMessage, TeamMemberWithdrewMessage,
TeamMemberRemovedMessage, TeamReappliedMessage
TeamMemberRemovedMessage, TeamReappliedMessage, TeamCaptainAcceptedMessage
)
from bluebottle.activities.tests.factories import TeamFactory
from bluebottle.test.factory_models.accounts import BlueBottleUserFactory
Expand Down Expand Up @@ -116,11 +116,16 @@ def test_team_applied_notification(self):
self.assertActionTitle('View activity')

def test_team_accepted_notification(self):
self.obj = PeriodParticipantFactory.create(
user=self.captain,
activity=self.activity,
team=self.obj
)
self.activity.review = True
self.activity.save()
self.message_class = TeamAcceptedMessage
self.message_class = TeamCaptainAcceptedMessage
self.create()
self.assertRecipients([self.obj.owner])
self.assertRecipients([self.obj.user])
self.assertSubject("Your team has been accepted for \"Save the world!\"")
self.assertBodyContains('On the activity page you will find the link to invite your team members.')
self.assertBodyContains(f"Your team has been accepted for the activity '{self.activity.title}'.")
Expand All @@ -140,10 +145,15 @@ def test_team_cancelled_notification(self):
self.assertActionTitle('View activity')

def test_team_cancelled_team_captain_notification(self):
self.obj = PeriodParticipantFactory.create(
user=self.captain,
activity=self.activity,
team=self.obj
)
self.message_class = TeamCancelledTeamCaptainMessage
self.create()
self.assertRecipients([self.obj.owner])
self.assertSubject("Your team has been rejected for 'Save the world!'")
self.assertRecipients([self.obj.user])
self.assertSubject('Your team has been rejected for "Save the world!"')
self.assertHtmlBodyContains(
"Unfortunately, your team has been rejected for the activity 'Save the world!'."
)
Expand Down
66 changes: 51 additions & 15 deletions bluebottle/activities/tests/test_triggers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
from django.core import mail

from bluebottle.test.utils import TriggerTestCase
from bluebottle.test.factory_models.accounts import BlueBottleUserFactory

from bluebottle.activities.effects import TeamContributionTransitionEffect, ResetTeamParticipantsEffect
from bluebottle.activities.messages import (
TeamAddedMessage, TeamCancelledMessage, TeamReopenedMessage,
TeamAppliedMessage, TeamAcceptedMessage, TeamCancelledTeamCaptainMessage, TeamWithdrawnMessage,
TeamAppliedMessage, TeamCaptainAcceptedMessage, TeamCancelledTeamCaptainMessage, TeamWithdrawnMessage,
TeamWithdrawnActivityOwnerMessage, TeamReappliedMessage
)
from bluebottle.activities.effects import TeamContributionTransitionEffect, ResetTeamParticipantsEffect
from bluebottle.time_based.models import PeriodParticipant
from bluebottle.activities.tests.factories import TeamFactory

from bluebottle.time_based.tests.factories import PeriodActivityFactory, PeriodParticipantFactory
from bluebottle.test.factory_models.accounts import BlueBottleUserFactory
from bluebottle.test.utils import TriggerTestCase
from bluebottle.time_based.models import PeriodParticipant
from bluebottle.time_based.states import TimeContributionStateMachine
from bluebottle.time_based.tests.factories import PeriodActivityFactory, PeriodParticipantFactory


class TeamTriggersTestCase(TriggerTestCase):
Expand Down Expand Up @@ -71,13 +67,34 @@ def test_accept(self):
with self.execute(message=message):
self.assertEqual(self.model.status, 'open')

self.assertNotificationEffect(TeamAcceptedMessage)
self.model.save()

def test_accept_team_captain(self):
self.activity.review = True
self.activity.save()
captain = BlueBottleUserFactory.create()
self.model = PeriodParticipantFactory.create(
activity=self.activity,
team=TeamFactory.create(
activity=self.activity,
owner=captain
),
user=captain,
as_relation='user'
)
self.model.states.accept()

message = 'You were accepted, because you were great'

with self.execute(message=message):
self.assertEqual(self.model.status, 'accepted')
self.assertEqual(self.model.team.status, 'open')
self.assertNotificationEffect(TeamCaptainAcceptedMessage)
self.assertEqual(
self.effects[0].options['message'], message
)

self.model.save()
self.assertTrue(message in mail.outbox[-1].body)

def test_cancel(self):
self.create()
Expand All @@ -93,16 +110,35 @@ def test_cancel(self):
self.assertNotificationEffect(
TeamCancelledMessage, [other_participant.user]
)
self.assertNotificationEffect(
TeamCancelledTeamCaptainMessage, [self.model.owner]
)

self.model.save()
self.participant.refresh_from_db()

for contribution in self.participant.contributions.all():
self.assertEqual(contribution.status, TimeContributionStateMachine.failed.value)

def test_cancel_team_captain(self):
self.activity.review = True
self.activity.save()

captain = BlueBottleUserFactory.create()
self.model = PeriodParticipantFactory.create(
activity=self.activity,
team=TeamFactory.create(
activity=self.activity,
owner=captain
),
user=captain,
as_relation='user',
status='new'
)
self.model.states.reject()

with self.execute():
self.assertNotificationEffect(
TeamCancelledTeamCaptainMessage, [self.model.owner]
)

def test_withdrawn(self):
self.create()

Expand Down
10 changes: 2 additions & 8 deletions bluebottle/activities/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
TeamContributionTransitionEffect, ResetTeamParticipantsEffect
)
from bluebottle.activities.messages import (
TeamAddedMessage, TeamReopenedMessage, TeamAcceptedMessage, TeamAppliedMessage,
TeamWithdrawnMessage, TeamWithdrawnActivityOwnerMessage, TeamReappliedMessage, TeamCancelledMessage,
TeamCancelledTeamCaptainMessage
TeamAddedMessage, TeamReopenedMessage, TeamAppliedMessage,
TeamWithdrawnMessage, TeamWithdrawnActivityOwnerMessage, TeamReappliedMessage, TeamCancelledMessage
)
from bluebottle.activities.models import Organizer, EffortContribution, Team
from bluebottle.activities.states import (
Expand Down Expand Up @@ -280,10 +279,6 @@ class TeamTriggers(TriggerManager):
TransitionTrigger(
TeamStateMachine.accept,
effects=[
NotificationEffect(
TeamAcceptedMessage,
conditions=[needs_review]
),
RelatedTransitionEffect(
'members',
ParticipantStateMachine.accept,
Expand All @@ -307,7 +302,6 @@ class TeamTriggers(TriggerManager):
),
TeamContributionTransitionEffect(ContributionStateMachine.fail),
NotificationEffect(TeamCancelledMessage),
NotificationEffect(TeamCancelledTeamCaptainMessage)
]
),

Expand Down
Loading

0 comments on commit bd50a53

Please sign in to comment.