mirror of
https://github.com/himool/HimoolERP.git
synced 2024-12-25 00:11:23 +08:00
feat: update
This commit is contained in:
parent
3f1b970fa9
commit
e55480c10e
4 changed files with 11 additions and 4 deletions
|
@ -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='所在城市')
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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}')
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue