mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-13 13:29:23 +00:00
Mise à jour d'avril (#643)
This commit is contained in:
@ -9,7 +9,6 @@ import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("subscription", "0001_initial"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
|
@ -8,7 +8,6 @@ import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("counter", "0001_initial"),
|
||||
|
@ -7,7 +7,6 @@ from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0002_auto_20160826_1342")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0003_permanency_activity")]
|
||||
|
||||
operations = [
|
||||
|
@ -6,7 +6,6 @@ import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0004_auto_20160826_1907")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0005_auto_20160826_2330")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0006_auto_20160831_1304")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0007_product_archived")]
|
||||
|
||||
operations = [
|
||||
|
@ -6,7 +6,6 @@ import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0008_counter_token")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0009_eticket")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0010_auto_20161003_1900")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0011_auto_20161004_2039")]
|
||||
|
||||
operations = [
|
||||
|
@ -37,7 +37,6 @@ def balance_ecocups(apps, schema_editor):
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0012_auto_20170515_2202")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0013_customer_recorded_products")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0013_customer_recorded_products")]
|
||||
|
||||
operations = [
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("counter", "0014_auto_20170817_1537"),
|
||||
("counter", "0014_auto_20170816_1521"),
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0015_merge")]
|
||||
|
||||
operations = [
|
||||
|
@ -8,7 +8,6 @@ import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0016_producttype_comment")]
|
||||
|
||||
operations = [
|
||||
|
@ -4,7 +4,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("counter", "0017_studentcard"),
|
||||
]
|
||||
|
@ -6,7 +6,6 @@ import django_countries.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("counter", "0018_producttype_priority"),
|
||||
]
|
||||
|
@ -5,7 +5,6 @@ from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("counter", "0019_billinginfo"),
|
||||
]
|
||||
|
@ -228,7 +228,9 @@ class ProductType(models.Model):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -294,9 +296,11 @@ class Product(models.Model):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(
|
||||
settings.SITH_GROUP_ACCOUNTING_ADMIN_ID
|
||||
) or user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID):
|
||||
pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID
|
||||
) or user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -318,8 +322,8 @@ class Product(models.Model):
|
||||
"""
|
||||
if not self.buying_groups.exists():
|
||||
return True
|
||||
for group in self.buying_groups.all():
|
||||
if user.is_in_group(group.name):
|
||||
for group_id in self.buying_groups.values_list("pk", flat=True):
|
||||
if user.is_in_group(pk=group_id):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -402,18 +406,17 @@ class Counter(models.Model):
|
||||
return reverse("counter:details", kwargs={"counter_id": self.id})
|
||||
|
||||
def is_owned_by(self, user):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
mem = self.club.get_membership_for(user)
|
||||
if mem and mem.role >= 7:
|
||||
return True
|
||||
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
||||
return user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
if self.type == "BAR":
|
||||
return True
|
||||
return (
|
||||
user.is_in_group(settings.SITH_MAIN_BOARD_GROUP)
|
||||
or user in self.sellers.all()
|
||||
)
|
||||
return user.is_board_member or user in self.sellers.all()
|
||||
|
||||
def gen_token(self):
|
||||
"""Generate a new token for this counter"""
|
||||
@ -621,6 +624,8 @@ class Refilling(models.Model):
|
||||
)
|
||||
|
||||
def is_owned_by(self, user):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_owner(self.counter) and self.payment_method != "CARD"
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
@ -713,6 +718,8 @@ class Selling(models.Model):
|
||||
)
|
||||
|
||||
def is_owned_by(self, user):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_owner(self.counter) and self.payment_method != "CARD"
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
@ -953,7 +960,9 @@ class CashRegisterSummary(models.Model):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
if user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -1022,7 +1031,9 @@ class Eticket(models.Model):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
||||
|
||||
def get_hash(self, string):
|
||||
import hashlib
|
||||
|
@ -30,13 +30,13 @@ from sith.settings import SITH_MAIN_CLUB
|
||||
|
||||
|
||||
class CounterTest(TestCase):
|
||||
def setUp(self):
|
||||
call_command("populate")
|
||||
self.skia = User.objects.filter(username="skia").first()
|
||||
self.sli = User.objects.filter(username="sli").first()
|
||||
self.krophil = User.objects.filter(username="krophil").first()
|
||||
self.mde = Counter.objects.filter(name="MDE").first()
|
||||
self.foyer = Counter.objects.get(id=2)
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.skia = User.objects.filter(username="skia").first()
|
||||
cls.sli = User.objects.filter(username="sli").first()
|
||||
cls.krophil = User.objects.filter(username="krophil").first()
|
||||
cls.mde = Counter.objects.filter(name="MDE").first()
|
||||
cls.foyer = Counter.objects.get(id=2)
|
||||
|
||||
def test_full_click(self):
|
||||
self.client.post(
|
||||
@ -161,9 +161,7 @@ class CounterTest(TestCase):
|
||||
|
||||
class CounterStatsTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
call_command("populate")
|
||||
def setUpTestData(cls):
|
||||
cls.counter = Counter.objects.filter(id=2).first()
|
||||
cls.krophil = User.objects.get(username="krophil")
|
||||
cls.skia = User.objects.get(username="skia")
|
||||
@ -171,10 +169,7 @@ class CounterStatsTest(TestCase):
|
||||
cls.root = User.objects.get(username="root")
|
||||
cls.subscriber = User.objects.get(username="subscriber")
|
||||
cls.old_subscriber = User.objects.get(username="old_subscriber")
|
||||
cls.counter.sellers.add(cls.sli)
|
||||
cls.counter.sellers.add(cls.root)
|
||||
cls.counter.sellers.add(cls.skia)
|
||||
cls.counter.sellers.add(cls.krophil)
|
||||
cls.counter.sellers.add(cls.sli, cls.root, cls.skia, cls.krophil)
|
||||
|
||||
barbar = Product.objects.get(code="BARB")
|
||||
|
||||
@ -368,7 +363,7 @@ class CounterStatsTest(TestCase):
|
||||
|
||||
class BillingInfoTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def setUpTestData(cls):
|
||||
cls.payload_1 = {
|
||||
"first_name": "Subscribed",
|
||||
"last_name": "User",
|
||||
@ -385,8 +380,6 @@ class BillingInfoTest(TestCase):
|
||||
"city": "Sète",
|
||||
"country": "FR",
|
||||
}
|
||||
super().setUpClass()
|
||||
call_command("populate")
|
||||
|
||||
def test_edit_infos(self):
|
||||
user = User.objects.get(username="subscriber")
|
||||
@ -596,7 +589,6 @@ class BillingInfoTest(TestCase):
|
||||
|
||||
class BarmanConnectionTest(TestCase):
|
||||
def setUp(self):
|
||||
call_command("populate")
|
||||
self.krophil = User.objects.get(username="krophil")
|
||||
self.skia = User.objects.get(username="skia")
|
||||
self.skia.customer.account = 800
|
||||
@ -662,7 +654,6 @@ class StudentCardTest(TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
call_command("populate")
|
||||
self.krophil = User.objects.get(username="krophil")
|
||||
self.sli = User.objects.get(username="sli")
|
||||
|
||||
|
@ -87,8 +87,8 @@ class CounterAdminMixin(View):
|
||||
edit_club = []
|
||||
|
||||
def _test_group(self, user):
|
||||
for g in self.edit_group:
|
||||
if user.is_in_group(g):
|
||||
for grp_id in self.edit_group:
|
||||
if user.is_in_group(pk=grp_id):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -486,14 +486,12 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
|
||||
pid = str(pid)
|
||||
price = self.get_price(pid)
|
||||
total = self.sum_basket(request)
|
||||
product = self.get_product(pid)
|
||||
can_buy = False
|
||||
if not product.buying_groups.exists():
|
||||
can_buy = True
|
||||
else:
|
||||
for g in product.buying_groups.all():
|
||||
if self.customer.user.is_in_group(g.name):
|
||||
can_buy = True
|
||||
product: Product = self.get_product(pid)
|
||||
user: User = self.customer.user
|
||||
buying_groups = list(product.buying_groups.values_list("pk", flat=True))
|
||||
can_buy = len(buying_groups) == 0 or any(
|
||||
user.is_in_group(pk=group_id) for group_id in buying_groups
|
||||
)
|
||||
if not can_buy:
|
||||
request.session["not_allowed"] = True
|
||||
return False
|
||||
@ -514,18 +512,17 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
|
||||
):
|
||||
request.session["not_allowed"] = True
|
||||
return False
|
||||
if product.limit_age >= 18 and not self.customer.user.date_of_birth:
|
||||
if product.limit_age >= 18 and not user.date_of_birth:
|
||||
request.session["no_age"] = True
|
||||
return False
|
||||
if product.limit_age >= 18 and self.customer.user.is_banned_alcohol:
|
||||
if product.limit_age >= 18 and user.is_banned_alcohol:
|
||||
request.session["not_allowed"] = True
|
||||
return False
|
||||
if self.customer.user.is_banned_counter:
|
||||
if user.is_banned_counter:
|
||||
request.session["not_allowed"] = True
|
||||
return False
|
||||
if (
|
||||
self.customer.user.date_of_birth
|
||||
and self.customer.user.get_age() < product.limit_age
|
||||
user.date_of_birth and self.customer.user.get_age() < product.limit_age
|
||||
): # Check if affordable
|
||||
request.session["too_young"] = True
|
||||
return False
|
||||
@ -586,7 +583,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
|
||||
- <str>, where the string is the code of the product
|
||||
- <int>X<str>, where the integer is the quantity and str the code
|
||||
"""
|
||||
string = parse_qs(request.body.decode())["code"][0].upper()
|
||||
string = parse_qs(request.body.decode()).get("code", [""])[0].upper()
|
||||
if string == "FIN":
|
||||
return self.finish(request)
|
||||
elif string == "ANN":
|
||||
|
Reference in New Issue
Block a user