Empêche la création d'asso orphelines #119
|
@ -374,6 +374,7 @@ class Role(HTMLDocString, AbstractAssociated, AbstractRole):
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
# FIXME: impossible de changer le rôle new_comers dans ces conditions
|
# FIXME: impossible de changer le rôle new_comers dans ces conditions
|
||||||
|
errors = []
|
||||||
if self.association_id:
|
if self.association_id:
|
||||||
if (
|
if (
|
||||||
self.new_comers
|
self.new_comers
|
||||||
|
@ -383,11 +384,13 @@ class Role(HTMLDocString, AbstractAssociated, AbstractRole):
|
||||||
association_id=self.association_id,
|
association_id=self.association_id,
|
||||||
).exists()
|
).exists()
|
||||||
):
|
):
|
||||||
raise ValidationError(
|
errors.append(
|
||||||
"Un autre rôle possède déjà l'attribut « nouvel arrivant "
|
ValidationError(
|
||||||
"». Il ne peut n'y en avoir qu'un."
|
"Un autre rôle possède déjà l'attribut « nouvel "
|
||||||
|
"arrivant ». Il ne peut n'y en avoir qu'un."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
elif (
|
if (
|
||||||
not self.new_comers
|
not self.new_comers
|
||||||
and not Role.objects.filter(
|
and not Role.objects.filter(
|
||||||
~models.Q(id=self.id),
|
~models.Q(id=self.id),
|
||||||
|
@ -395,11 +398,33 @@ class Role(HTMLDocString, AbstractAssociated, AbstractRole):
|
||||||
association_id=self.association_id,
|
association_id=self.association_id,
|
||||||
).exists()
|
).exists()
|
||||||
):
|
):
|
||||||
raise ValidationError(
|
errors.append(
|
||||||
"Aucun autre rôle ne possède l'attribut « nouvel arrivant "
|
ValidationError(
|
||||||
"». Vous devez en disposer d'un pour permettre "
|
"Aucun autre rôle ne possède l'attribut « nouvel "
|
||||||
"l'inscription d'un⋅e bénévole."
|
"arrivant ». Vous devez en disposer d'un pour "
|
||||||
|
"permettre l'inscription d'un⋅e bénévole."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
if (
|
||||||
|
self.id
|
||||||
|
and not self.manage_association
|
||||||
|
and not Engagement.objects.filter(
|
||||||
|
~models.Q(role_id=self.id),
|
||||||
|
association_id=self.association_id,
|
||||||
|
role__manage_association=True,
|
||||||
|
).exists()
|
||||||
|
):
|
||||||
|
errors.append(
|
||||||
|
ValidationError(
|
||||||
|
"Modifier ainsi ce rôle rendrait impossible la "
|
||||||
|
"gestion de l'association. Avant ça, vous devez "
|
||||||
|
"prévoir qu'au moins un rôle lié à au moins une "
|
||||||
|
"personne conserve la capacité de gérer "
|
||||||
|
"l'association.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if errors:
|
||||||
|
raise ValidationError(errors)
|
||||||
|
|
||||||
|
|
||||||
class EngagementQuerySet(models.QuerySet):
|
class EngagementQuerySet(models.QuerySet):
|
||||||
|
|
|
@ -935,7 +935,7 @@ class TestRole(ManagerOnlyViewMixin):
|
||||||
)
|
)
|
||||||
assert len(table_row) == 3
|
assert len(table_row) == 3
|
||||||
|
|
||||||
def test_self_downgrade_go_back_to_home(self, client, user, manager):
|
def test_self_downgrade_dont_create_orphans(self, client, user, manager):
|
||||||
client.force_login(user)
|
client.force_login(user)
|
||||||
|
|
||||||
assert self.association.can_manage_engagements(user)
|
assert self.association.can_manage_engagements(user)
|
||||||
|
@ -950,6 +950,39 @@ class TestRole(ManagerOnlyViewMixin):
|
||||||
follow=True,
|
follow=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert self.association.can_manage_engagements(user)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.resolver_match.view_name == 'association:role:update'
|
||||||
|
|
||||||
|
assert count_text_in_content(
|
||||||
|
response, "rendrait impossible la gestion"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_self_downgrade_go_back_to_home(
|
||||||
|
self, client, user, foreign, manager
|
||||||
|
):
|
||||||
|
# we need to define the next leader before leaving
|
||||||
|
r = self.association.role_set.get_benevole()
|
||||||
|
r.manage_association = True
|
||||||
|
r.save()
|
||||||
|
self.association.engagement_set.create(user=foreign, role=r)
|
||||||
|
|
||||||
|
assert self.association.can_manage_engagements(user)
|
||||||
|
assert self.association.can_manage_engagements(foreign)
|
||||||
|
|
||||||
|
client.force_login(user)
|
||||||
|
|
||||||
|
data = {'name': 'underground'}
|
||||||
|
response = client.post(
|
||||||
|
reverse(
|
||||||
|
'association:role:update',
|
||||||
|
args=[self.association.id, manager.role.id],
|
||||||
|
),
|
||||||
|
data,
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
|
||||||
assert not self.association.can_manage_engagements(user)
|
assert not self.association.can_manage_engagements(user)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
Chargement…
Référencer dans un nouveau ticket