mirror of https://github.com/jumpserver/jumpserver
pref: 优化工单验证
parent
631f802961
commit
6cf2bc4baf
|
@ -1,11 +1,10 @@
|
||||||
from django.db import models
|
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 django.utils.translation import ugettext_lazy as _
|
||||||
from .base import BaseACL, BaseACLQuerySet
|
from .base import BaseACL, BaseACLQuerySet
|
||||||
from common.utils import get_request_ip, get_ip_city
|
from common.utils import get_request_ip, get_ip_city
|
||||||
from common.utils.ip import contains_ip
|
from common.utils.ip import contains_ip
|
||||||
from common.utils.time_period import contains_time_period
|
from common.utils.time_period import contains_time_period
|
||||||
|
from common.utils.timezone import local_now_display
|
||||||
|
|
||||||
|
|
||||||
class ACLManager(models.Manager):
|
class ACLManager(models.Manager):
|
||||||
|
@ -59,7 +58,9 @@ class LoginACL(BaseACL):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def allow_user_confirm_if_need(user, ip):
|
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
|
acl = acl if acl and acl.reviewers.exists() else None
|
||||||
if not acl:
|
if not acl:
|
||||||
return False, acl
|
return False, acl
|
||||||
|
@ -71,7 +72,9 @@ class LoginACL(BaseACL):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def allow_user_to_login(user, ip):
|
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:
|
if not acl:
|
||||||
return True, ''
|
return True, ''
|
||||||
ip_group = acl.rules.get('ip_group')
|
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 = get_request_ip(request) if request else ''
|
||||||
login_ip = login_ip or '0.0.0.0'
|
login_ip = login_ip or '0.0.0.0'
|
||||||
login_city = get_ip_city(login_ip)
|
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 = {
|
ticket_meta = {
|
||||||
'apply_login_ip': login_ip,
|
'apply_login_ip': login_ip,
|
||||||
'apply_login_city': login_city,
|
'apply_login_city': login_city,
|
||||||
|
|
|
@ -63,12 +63,11 @@ class ApplySerializer(serializers.Serializer):
|
||||||
'Permission named `{}` already exists'.format(permission_name)
|
'Permission named `{}` already exists'.format(permission_name)
|
||||||
))
|
))
|
||||||
|
|
||||||
def validate_apply_date_expired(self, value):
|
def validate(self, attrs):
|
||||||
date_start = self.root.initial_data['meta'].get('apply_date_start')
|
apply_date_start = attrs['apply_date_start']
|
||||||
date_start = datetime.strptime(date_start, '%Y-%m-%dT%H:%M:%S.%fZ')
|
apply_date_expired = attrs['apply_date_expired']
|
||||||
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 apply_date_expired <= apply_date_start:
|
||||||
if date_expired <= date_start:
|
|
||||||
error = _('The expiration date should be greater than the start date')
|
error = _('The expiration date should be greater than the start date')
|
||||||
raise serializers.ValidationError(error)
|
raise serializers.ValidationError({'apply_date_expired': error})
|
||||||
return value
|
return attrs
|
||||||
|
|
Loading…
Reference in New Issue