Skip to content

Commit

Permalink
Merge branch 'release/team-slots' into hotfix/BB-20353-reject-team-wh…
Browse files Browse the repository at this point in the history
…en-cpt-is-rejected
  • Loading branch information
gannetson committed Aug 8, 2022
2 parents 69643a2 + 20b3331 commit 43efdb6
Show file tree
Hide file tree
Showing 7 changed files with 111 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
19 changes: 19 additions & 0 deletions bluebottle/activities/migrations/0059_auto_20220804_1214.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.24 on 2022-08-04 10:14

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('activities', '0058_auto_20220622_1050'),
]

operations = [
migrations.AlterField(
model_name='contributor',
name='team',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='members', to='activities.Team', verbose_name='team'),
),
]
2 changes: 1 addition & 1 deletion bluebottle/activities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Contributor(TriggerMixin, AnonymizationMixin, PolymorphicModel):

team = models.ForeignKey(
'activities.Team', verbose_name=_('team'),
null=True, blank=True, related_name='members', on_delete=models.SET_NULL
null=True, blank=True, related_name='members', on_delete=models.CASCADE
)
user = models.ForeignKey(
'members.Member', verbose_name=_('user'),
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
3 changes: 3 additions & 0 deletions bluebottle/time_based/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class JSONAPIMeta(TimeBasedBaseSerializer.JSONAPIMeta):
included_resources = TimeBasedBaseSerializer.JSONAPIMeta.included_resources + [
'my_contributor',
'my_contributor.user',
'my_contributor.location',
'my_contributor.slots',
'my_contributor.slots.slot',
]
Expand Down Expand Up @@ -497,6 +498,7 @@ class JSONAPIMeta(TimeBasedBaseSerializer.JSONAPIMeta):
'location',
'my_contributor.team',
'my_contributor.team.slot',
'my_contributor.team.slot.location',
]

included_serializers = dict(
Expand All @@ -506,6 +508,7 @@ class JSONAPIMeta(TimeBasedBaseSerializer.JSONAPIMeta):
'my_contributor': 'bluebottle.time_based.serializers.PeriodParticipantSerializer',
'my_contributor.team': 'bluebottle.activities.utils.TeamSerializer',
'my_contributor.team.slot': 'bluebottle.time_based.serializers.TeamSlotSerializer',
'my_contributor.team.slot.location': 'bluebottle.geo.serializers.GeolocationSerializer',
}
)

Expand Down
88 changes: 69 additions & 19 deletions bluebottle/time_based/tests/test_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.utils.timezone import now, get_current_timezone
from tenant_extras.utils import TenantLanguage

from bluebottle.activities.messages import ParticipantWithdrewConfirmationNotification, \
TeamMemberWithdrewMessage
from bluebottle.activities.messages import TeamMemberRemovedMessage, TeamCancelledTeamCaptainMessage, \
TeamCancelledMessage
from bluebottle.activities.models import Organizer, Activity
Expand All @@ -18,7 +20,8 @@
ParticipantJoinedNotification, ParticipantChangedNotification,
ParticipantAppliedNotification, ParticipantRemovedNotification, ParticipantRemovedOwnerNotification,
NewParticipantNotification, TeamParticipantJoinedNotification, ParticipantAddedNotification,
ParticipantAddedOwnerNotification, TeamSlotChangedNotification, ParticipantRejectedNotification
ParticipantRejectedNotification, ParticipantAddedOwnerNotification, TeamSlotChangedNotification,
ParticipantWithdrewNotification
)
from bluebottle.time_based.tests.factories import (
DateActivityFactory, PeriodActivityFactory,
Expand Down Expand Up @@ -1397,12 +1400,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 @@ -1417,11 +1420,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 @@ -1439,28 +1438,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 @@ -1931,6 +1963,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 @@ -1388,9 +1388,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 43efdb6

Please sign in to comment.