From e55480c10e8ecbfde43985d02b5772698e3f242f Mon Sep 17 00:00:00 2001 From: Czw <459749926@qq.com> Date: Tue, 17 Oct 2023 14:05:31 +0800 Subject: [PATCH] feat: update --- apps/system/models.py | 1 + apps/system/views.py | 6 ++++-- extensions/permissions.py | 3 +++ scripts/create_user.py | 5 +++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/system/models.py b/apps/system/models.py index 9a5fce8..a899f4c 100644 --- a/apps/system/models.py +++ b/apps/system/models.py @@ -10,6 +10,7 @@ class Team(Model): remark = CharField(max_length=256, blank=True, null=True, verbose_name='备注') enable_auto_stock_in = BooleanField(default=False, verbose_name='启用自动入库') enable_auto_stock_out = BooleanField(default=False, verbose_name='启用自动出库') + is_active = BooleanField(default=True, verbose_name='激活状态') register_phone = CharField(max_length=32, blank=True, null=True, verbose_name='注册手机号') register_city = CharField(max_length=32, blank=True, null=True, verbose_name='所在城市') diff --git a/apps/system/views.py b/apps/system/views.py index 0c936f2..1851e54 100644 --- a/apps/system/views.py +++ b/apps/system/views.py @@ -260,12 +260,14 @@ class AdminActionViewSet(FunctionViewSet): company = validated_data['company'] username = validated_data['username'] expiry_date = validated_data['expiry_date'] + is_active = validated_data['is_active'] if team := Team.objects.filter(number=company).first(): team.expiry_time = expiry_date - team.save(update_fields=['expiry_time']) + team.is_active = is_active + team.save(update_fields=['expiry_time', 'is_active']) else: - create_user(company, None, None, expiry_date, username, '123456') + create_user(company, None, None, expiry_date, username, '123456', is_active) return Response(status=status.HTTP_204_NO_CONTENT) diff --git a/extensions/permissions.py b/extensions/permissions.py index 115b393..216891e 100644 --- a/extensions/permissions.py +++ b/extensions/permissions.py @@ -22,6 +22,9 @@ class IsAuthenticated(BasePermission): if not isinstance(request.user, User): return False + if not request.user.team.is_active: + raise ValidationError(f'账号已冻结') + if (expiry_time := request.user.team.expiry_time) < pendulum.now(): raise ValidationError(f'已到期, 到期日期: {expiry_time}') diff --git a/scripts/create_user.py b/scripts/create_user.py index 21c4758..3cac04b 100644 --- a/scripts/create_user.py +++ b/scripts/create_user.py @@ -5,12 +5,13 @@ import pendulum @transaction.atomic -def create_user(team_number, register_phone, register_city, expiry_time, username, password): +def create_user(team_number, register_phone, register_city, expiry_time, username, password, is_active=True): team = Team.objects.create( number=team_number, expiry_time=expiry_time, register_phone=register_phone, - register_city=register_city) + register_city=register_city, + is_active=is_active) User.objects.create(team=team, username=username, password=make_password(password), name=username, is_manager=True)