Skip to content

Commit

Permalink
Merge pull request #5183 from onepercentclub/hotfix/BB-20353-reject-t…
Browse files Browse the repository at this point in the history
…eam-when-cpt-is-rejected

Reject team when captain is rejected
  • Loading branch information
gannetson committed Aug 8, 2022
2 parents 20b3331 + 43efdb6 commit 1d6d26f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
5 changes: 4 additions & 1 deletion bluebottle/activities/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def is_activity_owner(self, user):
)

cancel = Transition(
open,
[
open,
new
],
cancelled,
automatic=False,
permission=is_activity_owner,
Expand Down
45 changes: 43 additions & 2 deletions bluebottle/time_based/tests/test_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from django.utils.timezone import now, get_current_timezone
from tenant_extras.utils import TenantLanguage

from bluebottle.activities.messages import TeamMemberRemovedMessage, ParticipantWithdrewConfirmationNotification, \
from bluebottle.activities.messages import ParticipantWithdrewConfirmationNotification, \
TeamMemberWithdrewMessage
from bluebottle.activities.messages import TeamMemberRemovedMessage, TeamCancelledTeamCaptainMessage, \
TeamCancelledMessage
from bluebottle.activities.models import Organizer, Activity
from bluebottle.activities.tests.factories import TeamFactory
from bluebottle.initiatives.tests.factories import InitiativeFactory, InitiativePlatformSettingsFactory
Expand All @@ -18,7 +20,8 @@
ParticipantJoinedNotification, ParticipantChangedNotification,
ParticipantAppliedNotification, ParticipantRemovedNotification, ParticipantRemovedOwnerNotification,
NewParticipantNotification, TeamParticipantJoinedNotification, ParticipantAddedNotification,
ParticipantAddedOwnerNotification, TeamSlotChangedNotification, ParticipantWithdrewNotification
ParticipantRejectedNotification, ParticipantAddedOwnerNotification, TeamSlotChangedNotification,
ParticipantWithdrewNotification
)
from bluebottle.time_based.tests.factories import (
DateActivityFactory, PeriodActivityFactory,
Expand Down Expand Up @@ -2355,3 +2358,41 @@ def test_change_date(self):
self.assertNotificationEffect(TeamSlotChangedNotification)
self.assertEqual(self.model.status, 'open')
self.assertEqual(self.model.team.status, 'open')


class TeamReviewTriggerTestCase(TriggerTestCase):

def setUp(self):
super().setUp()
self.initiator = BlueBottleUserFactory()
self.user = BlueBottleUserFactory()
self.initiative = InitiativeFactory(owner=self.initiator)

self.activity = PeriodActivityFactory.create(
initiative=self.initiative,
team_activity='teams',
status='approved',
review=True
)
self.model = PeriodParticipantFactory.create(
user=self.user,
activity=self.activity,
as_relation='user'
)

def assertStatus(self, obj, status):
obj.refresh_from_db()
self.assertEqual(obj.status, status)

def test_reject(self):
self.assertTrue(self.model.team)
self.assertEqual(
self.model.team.owner,
self.user
)
self.model.states.reject()

with self.execute():
self.assertNoNotificationEffect(ParticipantRejectedNotification)
self.assertNoNotificationEffect(TeamCancelledMessage)
self.assertNotificationEffect(TeamCancelledTeamCaptainMessage)
19 changes: 18 additions & 1 deletion bluebottle/time_based/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,13 @@ def not_team_captain(effect):
return not effect.instance.team_id or effect.instance.team.owner != effect.instance.user


def is_team_captain(effect):
"""
is the team captain
"""
return effect.instance.team_id and effect.instance.team.owner == effect.instance.user


def user_is_not_team_captain(effect):
"""
current user is not team captain
Expand Down Expand Up @@ -1307,7 +1314,17 @@ class ParticipantTriggers(ContributorTriggers):
ParticipantStateMachine.reject,
effects=[
NotificationEffect(
ParticipantRejectedNotification
ParticipantRejectedNotification,
conditions=[
not_team_captain
]
),
RelatedTransitionEffect(
'team',
TeamStateMachine.cancel,
conditions=[
is_team_captain
]
),
RelatedTransitionEffect(
'activity',
Expand Down

0 comments on commit 1d6d26f

Please sign in to comment.