fix forbidden sector add/update/remove in closed rounds
This commit is contained in:
parent
097823fab0
commit
789756d586
1 changed files with 22 additions and 4 deletions
|
|
@ -107,7 +107,7 @@ class Campaign:
|
||||||
def remove_campaign_participant(self, participant_id: str) -> None:
|
def remove_campaign_participant(self, participant_id: str) -> None:
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
raise ForbiddenOperation("Can't remove participant in a closed campaign.")
|
raise ForbiddenOperation("Can't remove participant in a closed campaign.")
|
||||||
rounds_blocking: list[Round] = []
|
rounds_blocking: List[Round] = []
|
||||||
for rnd in self.rounds:
|
for rnd in self.rounds:
|
||||||
if rnd.has_choice_with_participant(
|
if rnd.has_choice_with_participant(
|
||||||
participant_id
|
participant_id
|
||||||
|
|
@ -158,6 +158,10 @@ class Campaign:
|
||||||
) -> Sector:
|
) -> Sector:
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
raise ForbiddenOperation("Can't add sector in a closed campaign.")
|
raise ForbiddenOperation("Can't add sector in a closed campaign.")
|
||||||
|
if round_id is not None:
|
||||||
|
round = self.get_round(round_id)
|
||||||
|
if round.is_over:
|
||||||
|
raise ForbiddenOperation("Can't add sector with a closed round.")
|
||||||
sect = Sector(
|
sect = Sector(
|
||||||
name, round_id, major_id, minor_id, influence_id, mission, description
|
name, round_id, major_id, minor_id, influence_id, mission, description
|
||||||
)
|
)
|
||||||
|
|
@ -187,11 +191,18 @@ class Campaign:
|
||||||
mission: str | None,
|
mission: str | None,
|
||||||
description: str | None,
|
description: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
# TODO raise error if sector used in a closed round (potential tokens)
|
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
raise ForbiddenOperation("Can't update sector in a closed campaign.")
|
raise ForbiddenOperation("Can't update sector in a closed campaign.")
|
||||||
sect = self.get_sector(sector_id)
|
sect = self.get_sector(sector_id)
|
||||||
old_round_id = sect.round_id
|
old_round_id = sect.round_id
|
||||||
|
if old_round_id is not None:
|
||||||
|
old_round = self.get_round(old_round_id)
|
||||||
|
if old_round.is_over:
|
||||||
|
raise ForbiddenOperation("Can't update sector used in a closed round.")
|
||||||
|
if round_id is not None:
|
||||||
|
new_round = self.get_round(round_id)
|
||||||
|
if new_round.is_over:
|
||||||
|
raise ForbiddenOperation("Can't update sector with a closed round.")
|
||||||
|
|
||||||
def apply_update() -> None:
|
def apply_update() -> None:
|
||||||
sect.set_name(name)
|
sect.set_name(name)
|
||||||
|
|
@ -205,7 +216,7 @@ class Campaign:
|
||||||
if old_round_id == round_id:
|
if old_round_id == round_id:
|
||||||
apply_update()
|
apply_update()
|
||||||
return
|
return
|
||||||
affected_rounds: list[Round] = []
|
affected_rounds: List[Round] = []
|
||||||
for rnd in self.rounds:
|
for rnd in self.rounds:
|
||||||
if rnd.id == old_round_id and (
|
if rnd.id == old_round_id and (
|
||||||
rnd.has_choice_with_sector(sector_id)
|
rnd.has_choice_with_sector(sector_id)
|
||||||
|
|
@ -235,7 +246,14 @@ class Campaign:
|
||||||
def remove_sector(self, sector_id: str) -> None:
|
def remove_sector(self, sector_id: str) -> None:
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
raise ForbiddenOperation("Can't remove sector in a closed campaign.")
|
raise ForbiddenOperation("Can't remove sector in a closed campaign.")
|
||||||
rounds_blocking: list[Round] = []
|
sect = self.get_sector(sector_id)
|
||||||
|
round_id = sect.round_id
|
||||||
|
if round_id is not None:
|
||||||
|
round = self.get_round(round_id)
|
||||||
|
if round.is_over:
|
||||||
|
raise ForbiddenOperation("Can't remove sector used in a closed round.")
|
||||||
|
|
||||||
|
rounds_blocking: List[Round] = []
|
||||||
for rnd in self.rounds:
|
for rnd in self.rounds:
|
||||||
if rnd.has_battle_with_sector(sector_id) or rnd.has_choice_with_sector(
|
if rnd.has_battle_with_sector(sector_id) or rnd.has_choice_with_sector(
|
||||||
sector_id
|
sector_id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue