Skip to content

Commit

Permalink
Merge pull request #5182 from onepercentclub/hotfix/BB-20314-only-not…
Browse files Browse the repository at this point in the history
…ify-team-captain

Hotfix/bb 20314 only notify team captain
  • Loading branch information
eodolphi committed Aug 8, 2022
2 parents dbef69e + 3deeefa commit 20b3331
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bluebottle/activities/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def get_recipients(self):


class TeamMemberWithdrewMessage(ActivityNotification):
subject = pgettext('email', "Withdrawal for '{title}'")
subject = pgettext('email', 'A participant has withdrawn from your team for "{title}"')
template = 'messages/team_member_withdrew'

context = {
Expand Down
2 changes: 1 addition & 1 deletion bluebottle/activities/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_team_member_withdrew_notification(self):
self.message_class = TeamMemberWithdrewMessage
self.create()
self.assertRecipients([self.captain])
self.assertSubject("Withdrawal for 'Save the world!'")
self.assertSubject('A participant has withdrawn from your team for "Save the world!"')
self.assertHtmlBodyContains(
f"{self.obj.user.full_name} has withdrawn from your team for the activity ‘Save the world!’."
)
Expand Down
88 changes: 68 additions & 20 deletions bluebottle/time_based/tests/test_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from django.utils.timezone import now, get_current_timezone
from tenant_extras.utils import TenantLanguage

from bluebottle.activities.messages import TeamMemberRemovedMessage
from bluebottle.activities.messages import TeamMemberRemovedMessage, ParticipantWithdrewConfirmationNotification, \
TeamMemberWithdrewMessage
from bluebottle.activities.models import Organizer, Activity
from bluebottle.activities.tests.factories import TeamFactory
from bluebottle.initiatives.tests.factories import InitiativeFactory, InitiativePlatformSettingsFactory
Expand All @@ -17,7 +18,7 @@
ParticipantJoinedNotification, ParticipantChangedNotification,
ParticipantAppliedNotification, ParticipantRemovedNotification, ParticipantRemovedOwnerNotification,
NewParticipantNotification, TeamParticipantJoinedNotification, ParticipantAddedNotification,
ParticipantAddedOwnerNotification, TeamSlotChangedNotification
ParticipantAddedOwnerNotification, TeamSlotChangedNotification, ParticipantWithdrewNotification
)
from bluebottle.time_based.tests.factories import (
DateActivityFactory, PeriodActivityFactory,
Expand Down Expand Up @@ -1396,12 +1397,12 @@ def test_withdraw_team(self):
user=BlueBottleUserFactory.create()
)

mail.outbox = []
participant = self.participant_factory.create(
activity=self.activity,
accepted_invite=team_captain.invite,
user=BlueBottleUserFactory.create()
)
mail.outbox = []
participant.states.withdraw(save=True)

self.activity.refresh_from_db()
Expand All @@ -1416,11 +1417,7 @@ def test_withdraw_team(self):
f'You have withdrawn from the activity "{self.activity.title}"' in subjects
)
self.assertTrue(
f'A participant has withdrawn from your activity "{self.activity.title}"' in subjects
)

self.assertTrue(
f"Withdrawal for '{self.activity.title}'" in subjects
f'A participant has withdrawn from your team for "{self.activity.title}"' in subjects
)

def test_reapply(self):
Expand All @@ -1438,28 +1435,61 @@ def test_reapply(self):
)
self.assertTrue(self.activity.followers.filter(user=self.participants[0].user).exists())

def test_reapply_cancelled_team(self):
self.activity.team_activity = Activity.TeamActivityChoices.teams
self.test_withdraw()
self.participants[0].team.states.cancel(save=True)

self.assertEqual(
self.participants[0].contributions.
exclude(timecontribution__contribution_type='preparation').get().status,
'failed'
def test_reapply_cancelled(self):
self.participants = self.participant_factory.create_batch(
self.activity.capacity,
activity=self.activity,
user=BlueBottleUserFactory.create()
)
self.activity.refresh_from_db()

self.participants[0].states.reapply(save=True)
self.assertEqual(self.activity.status, 'full')
mail.outbox = []

self.participants[0].states.withdraw(save=True)

self.activity.refresh_from_db()
self.assertEqual(self.activity.status, 'open')

self.assertEqual(self.activity.status, 'full')
self.assertEqual(
self.participants[0].contributions.
exclude(timecontribution__contribution_type='preparation').get().status,
'failed'
)
self.assertTrue(self.activity.followers.filter(user=self.participants[0].user).exists())

self.assertFalse(self.activity.followers.filter(user=self.participants[0].user).exists())

subjects = [mail.subject for mail in mail.outbox]
self.assertTrue(
f'You have withdrawn from the activity "{self.activity.title}"' in subjects
)
self.assertTrue(
f'A participant has withdrawn from your activity "{self.activity.title}"' in subjects
)

def test_withdraw_from_team(self):
self.activity.team_activity = Activity.TeamActivityChoices.teams
self.captain = self.participant_factory.create(
activity=self.activity,
user=BlueBottleUserFactory.create()
)
self.participant = self.participant_factory.create(
activity=self.activity,
user=BlueBottleUserFactory.create(),
team=self.captain.team
)

mail.outbox = []

self.participant.states.withdraw(save=True)

subjects = [mail.subject for mail in mail.outbox]
self.assertTrue(
f'You have withdrawn from the activity "{self.activity.title}"' in subjects
)
self.assertTrue(
f'A participant has withdrawn from your team for "{self.activity.title}"' in subjects
)


class DateParticipantTriggerTestCase(ParticipantTriggerTestCase, BluebottleTestCase):
Expand Down Expand Up @@ -1930,6 +1960,24 @@ def test_remove_participant(self):
self.assertNotificationEffect(ParticipantRemovedNotification)
self.assertNotificationEffect(ParticipantRemovedOwnerNotification)

def test_withdraw_team_participant(self):
self.activity.team_activity = 'teams'
captain = BlueBottleUserFactory.create()
team = TeamFactory.create(
owner=captain,
activity=self.activity
)
self.model = self.participant_factory.create(
activity=self.activity,
team=team,
status='accepted'
)
self.model.states.withdraw()
with self.execute():
self.assertNoNotificationEffect(ParticipantWithdrewNotification)
self.assertNotificationEffect(TeamMemberWithdrewMessage)
self.assertNotificationEffect(ParticipantWithdrewConfirmationNotification)

def test_remove_team_participant(self):
self.activity.team_activity = 'teams'
self.activity.save()
Expand Down
20 changes: 17 additions & 3 deletions bluebottle/time_based/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,9 +1371,23 @@ class ParticipantTriggers(ContributorTriggers):
TimeContributionStateMachine.fail,
),
UnFollowActivityEffect,
NotificationEffect(ParticipantWithdrewNotification),
NotificationEffect(ParticipantWithdrewConfirmationNotification),
NotificationEffect(TeamMemberWithdrewMessage),
NotificationEffect(
ParticipantWithdrewNotification,
conditions=[
is_not_team_activity
]
),
NotificationEffect(
ParticipantWithdrewConfirmationNotification
),
NotificationEffect(
TeamMemberWithdrewMessage,
conditions=[
is_team_activity,
not_team_captain
]

),
]
),

Expand Down

0 comments on commit 20b3331

Please sign in to comment.