mirror of
https://github.com/ae-utbm/sith.git
synced 2025-01-06 15:11:21 +00:00
change club group names when the club name changes
This commit is contained in:
parent
efca10e252
commit
bb210f8d47
@ -106,9 +106,16 @@ class Club(models.Model):
|
||||
@transaction.atomic()
|
||||
def save(self, *args, **kwargs):
|
||||
creation = self._state.adding
|
||||
if not creation and Club.objects.get(id=self.id).unix_name != self.unix_name:
|
||||
self.home.name = self.unix_name
|
||||
self.home.save()
|
||||
if not creation:
|
||||
db_club = Club.objects.get(id=self.id)
|
||||
if self.unix_name != db_club.unix_name:
|
||||
self.home.name = self.unix_name
|
||||
self.home.save()
|
||||
if self.name != db_club.name:
|
||||
self.board_group.name = f"{self.name} - Bureau"
|
||||
self.board_group.save()
|
||||
self.members_group.name = f"{self.name} - Membres"
|
||||
self.members_group.save()
|
||||
if creation:
|
||||
self.board_group = Group.objects.create(
|
||||
name=f"{self.name} - Bureau", is_manually_manageable=False
|
||||
|
@ -548,6 +548,26 @@ class TestClubModel(TestClub):
|
||||
Membership(club=self.ae, user=self.sli, role=3).save()
|
||||
assert self.club.is_owned_by(self.sli)
|
||||
|
||||
def test_change_club_name(self):
|
||||
"""Test that changing the club name doesn't break things."""
|
||||
members_group = self.club.members_group
|
||||
board_group = self.club.board_group
|
||||
initial_members = set(members_group.users.values_list("id", flat=True))
|
||||
initial_board = set(board_group.users.values_list("id", flat=True))
|
||||
self.club.name = "something else"
|
||||
self.club.save()
|
||||
self.club.refresh_from_db()
|
||||
|
||||
# The names should have changed, but not the ids nor the group members
|
||||
assert self.club.members_group.name == "something else - Membres"
|
||||
assert self.club.board_group.name == "something else - Bureau"
|
||||
assert self.club.members_group.id == members_group.id
|
||||
assert self.club.board_group.id == board_group.id
|
||||
new_members = set(self.club.members_group.users.values_list("id", flat=True))
|
||||
new_board = set(self.club.board_group.users.values_list("id", flat=True))
|
||||
assert new_members == initial_members
|
||||
assert new_board == initial_board
|
||||
|
||||
|
||||
class TestMailingForm(TestCase):
|
||||
"""Perform validation tests for MailingForm."""
|
||||
|
Loading…
Reference in New Issue
Block a user