mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-20 07:59:50 +00:00
end barmanship on ban
This commit is contained in:
1 parent
079ec8a8e5
commit
e45b4eb9e0
2 files changed
+30
-5
No files matched your search
@@ -769,6 +769,14 @@ class UserBan(models.Model):
|
||||
def __str__(self):
|
||||
return f"Ban of user {self.user.id}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.ban_group_id in [
|
||||
settings.SITH_GROUP_BANNED_COUNTER_ID,
|
||||
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
]:
|
||||
self.user.counters.clear()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class GlobalPermissionRights(models.Model):
|
||||
"""Little hack to have permissions not linked to a specific db table."""
|
||||
|
||||
@@ -8,7 +8,10 @@ from django.utils.timezone import localtime
|
||||
from model_bakery import baker
|
||||
from pytest_django.asserts import assertRedirects
|
||||
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.models import BanGroup, User, UserBan
|
||||
from counter.models import Counter
|
||||
from sith import settings
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.test import Client
|
||||
@@ -33,11 +36,7 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
|
||||
client.force_login(operator)
|
||||
user = baker.make(User)
|
||||
ban_group = BanGroup.objects.first()
|
||||
data = {
|
||||
"user": user.id,
|
||||
"ban_group": ban_group.id,
|
||||
"reason": "Being naughty",
|
||||
}
|
||||
data = {"user": user.id, "ban_group": ban_group.id, "reason": "Being naughty"}
|
||||
if expires_at is not None:
|
||||
data["expires_at"] = expires_at.strftime("%Y-%m-%d %H:%M")
|
||||
response = client.post(reverse("rootplace:ban_create"), data)
|
||||
@@ -49,6 +48,24 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
|
||||
assert bans[0].ban_group == ban_group
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ban_counter_ends_barmanship():
|
||||
user = subscriber_user.make()
|
||||
counter = baker.make(Counter)
|
||||
counter.sellers.add(user, through_defaults={"is_regular": True})
|
||||
|
||||
UserBan.objects.create(
|
||||
user=user,
|
||||
ban_group_id=settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
reason="ban comptoir",
|
||||
)
|
||||
|
||||
# check that we did effectively delete the barmanship
|
||||
# and not the bar itself (better safe than sorry)
|
||||
assert Counter.objects.filter(id=counter.id).exists()
|
||||
assert not user.counters.exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_remove_ban(client: Client, operator: User):
|
||||
client.force_login(operator)
|
||||
|
||||
Reference in new issue
Block a user