Browse Source

pref: 优化工单验证

pull/7102/head
ibuler 3 years ago committed by Jiangjie.Bai
parent
commit
6cf2bc4baf
  1. 13
      apps/acls/models/login_acl.py
  2. 15
      apps/tickets/serializers/ticket/meta/ticket_type/apply_asset.py

13
apps/acls/models/login_acl.py

@ -1,11 +1,10 @@
from django.db import models
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from .base import BaseACL, BaseACLQuerySet
from common.utils import get_request_ip, get_ip_city
from common.utils.ip import contains_ip
from common.utils.time_period import contains_time_period
from common.utils.timezone import local_now_display
class ACLManager(models.Manager):
@ -59,7 +58,9 @@ class LoginACL(BaseACL):
@staticmethod
def allow_user_confirm_if_need(user, ip):
acl = LoginACL.filter_acl(user).filter(action=LoginACL.ActionChoices.confirm).first()
acl = LoginACL.filter_acl(user).filter(
action=LoginACL.ActionChoices.confirm
).first()
acl = acl if acl and acl.reviewers.exists() else None
if not acl:
return False, acl
@ -71,7 +72,9 @@ class LoginACL(BaseACL):
@staticmethod
def allow_user_to_login(user, ip):
acl = LoginACL.filter_acl(user).exclude(action=LoginACL.ActionChoices.confirm).first()
acl = LoginACL.filter_acl(user).exclude(
action=LoginACL.ActionChoices.confirm
).first()
if not acl:
return True, ''
ip_group = acl.rules.get('ip_group')
@ -99,7 +102,7 @@ class LoginACL(BaseACL):
login_ip = get_request_ip(request) if request else ''
login_ip = login_ip or '0.0.0.0'
login_city = get_ip_city(login_ip)
login_datetime = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
login_datetime = local_now_display()
ticket_meta = {
'apply_login_ip': login_ip,
'apply_login_city': login_city,

15
apps/tickets/serializers/ticket/meta/ticket_type/apply_asset.py

@ -63,12 +63,11 @@ class ApplySerializer(serializers.Serializer):
'Permission named `{}` already exists'.format(permission_name)
))
def validate_apply_date_expired(self, value):
date_start = self.root.initial_data['meta'].get('apply_date_start')
date_start = datetime.strptime(date_start, '%Y-%m-%dT%H:%M:%S.%fZ')
date_expired = self.root.initial_data['meta'].get('apply_date_expired')
date_expired = datetime.strptime(date_expired, '%Y-%m-%dT%H:%M:%S.%fZ')
if date_expired <= date_start:
def validate(self, attrs):
apply_date_start = attrs['apply_date_start']
apply_date_expired = attrs['apply_date_expired']
if apply_date_expired <= apply_date_start:
error = _('The expiration date should be greater than the start date')
raise serializers.ValidationError(error)
return value
raise serializers.ValidationError({'apply_date_expired': error})
return attrs

Loading…
Cancel
Save