refector: user is_active用is_deleted统一处理
This commit is contained in:
parent
6d1c9e03c9
commit
9b0de2e011
|
@ -99,7 +99,7 @@ class WxmpLogin(CreateAPIView):
|
|||
openid = info['openid']
|
||||
session_key = info['session_key']
|
||||
try:
|
||||
user = User.objects.get(wxmp_openid=openid, is_active=True)
|
||||
user = User.objects.get(wxmp_openid=openid)
|
||||
ret = get_tokens_for_user(user)
|
||||
ret['wxmp_session_key'] = session_key
|
||||
ret['wxmp_openid'] = openid
|
||||
|
@ -124,7 +124,7 @@ class WxLogin(CreateAPIView):
|
|||
openid = info['openid']
|
||||
access = info['access_token']
|
||||
try:
|
||||
user = User.objects.get(wx_openid=openid, is_active=True)
|
||||
user = User.objects.get(wx_openid=openid)
|
||||
ret = get_tokens_for_user(user)
|
||||
ret['wx_token'] = access
|
||||
ret['wx_openid'] = openid
|
||||
|
|
|
@ -174,7 +174,7 @@ def create_remind(event: Event, params: dict):
|
|||
'can_handle': i.can_handle,
|
||||
})
|
||||
elif i.post and area_level >= i.filter_area_level:
|
||||
qs = User.objects.filter(posts=i.post, is_active=True)
|
||||
qs = User.objects.filter(posts=i.post)
|
||||
if i.filter_recipient == 20: # 当事人所在部门以上
|
||||
if event.employee and event.employee.user:
|
||||
qs = qs.filter(depts__in=get_parent_queryset(event.employee.user.belong_dept))
|
||||
|
|
|
@ -79,8 +79,8 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
|
|||
elif instance.type in ['visitor', 'driver']: # 如果是访客或司机
|
||||
from apps.vm.services import sync_to_visitor
|
||||
sync_to_visitor(instance)
|
||||
if instance.job_state in [20, 30] and instance.user: # 如果离职了关闭账户
|
||||
instance.user.is_active = False
|
||||
if instance.job_state in [20, 30] and instance.user: # 如果离职了删除账户
|
||||
instance.user.is_deleted = True
|
||||
instance.user.save()
|
||||
# 同时去除门禁授权
|
||||
# 如果是正式员工或相关方且有门禁权限:
|
||||
|
|
|
@ -75,7 +75,7 @@ def rpj_member_leave(i: Rpjmember):
|
|||
ep.save()
|
||||
HrmService.sync_dahua_employee(ep, ep.photo, rpj.come_time, timezone.now() + timedelta(hours=8))
|
||||
if ep.user:
|
||||
ep.user.is_active = False
|
||||
ep.user.is_deleted = True
|
||||
ep.user.save()
|
||||
|
||||
def rpj_member_come(i: Rpjmember):
|
||||
|
@ -116,7 +116,6 @@ def rpj_member_come(i: Rpjmember):
|
|||
else:
|
||||
user_e = User.objects.get_queryset(all=True).filter(phone=rep.phone).first() # 看看有没有存在的账户
|
||||
if user_e:
|
||||
user_e.is_active = True
|
||||
user_e.is_deleted = False
|
||||
else:
|
||||
user_e = User()
|
||||
|
|
|
@ -8,7 +8,7 @@ class UserFilterSet(filters.FilterSet):
|
|||
model = User
|
||||
fields = {
|
||||
'name': ['exact', 'contains'],
|
||||
'is_active': ['exact'],
|
||||
'is_deleted': ['exact'],
|
||||
'posts': ['exact'],
|
||||
'post': ['exact'],
|
||||
'belong_dept': ['exact'],
|
||||
|
|
|
@ -320,7 +320,7 @@ class UserUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'name', 'avatar', 'is_active', 'phone', 'type']
|
||||
fields = ['username', 'name', 'avatar', 'phone', 'type', 'is_deleted']
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
if User.objects.filter(username=validated_data['username']
|
||||
|
@ -338,7 +338,7 @@ class UserCreateSerializer(CustomModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'name', 'avatar', 'is_active', 'phone', 'type']
|
||||
fields = ['username', 'name', 'avatar', 'phone', 'type']
|
||||
|
||||
|
||||
class PasswordChangeSerializer(serializers.Serializer):
|
||||
|
|
|
@ -417,7 +417,7 @@ class UserPostViewSet(CreateModelMixin, DestroyModelMixin, ListModelMixin, Custo
|
|||
|
||||
|
||||
class UserViewSet(CustomModelViewSet):
|
||||
queryset = User.objects.all()
|
||||
queryset = User.objects.get_queryset(all=True)
|
||||
serializer_class = UserListSerializer
|
||||
create_serializer_class = UserCreateSerializer
|
||||
update_serializer_class = UserUpdateSerializer
|
||||
|
|
|
@ -192,7 +192,7 @@ class WfService(object):
|
|||
# user_queryset = user_queryset.filter(depts__in=depts)
|
||||
destination_participant = list(user_queryset.values_list('id', flat=True))
|
||||
elif destination_participant_type == State.PARTICIPANT_TYPE_ROLE: # 角色
|
||||
user_queryset = User.objects.filter(roles__in=destination_participant)
|
||||
user_queryset = User.objects.filter(roles__in=destination_participant, is_active=True, is_deleted=False)
|
||||
# 如果选择了角色, 需要走过滤策略
|
||||
if state.filter_dept not in [0, '0', None]:
|
||||
# if not new_ticket_data.get(state.filter_dept, None):
|
||||
|
|
|
@ -24,11 +24,11 @@ def send_ticket_notice(ticket_id):
|
|||
if ticket:
|
||||
if ticket.participant_type == 1:
|
||||
# 发送短信通知
|
||||
pt = User.objects.filter(id=ticket.participant, is_active=True).first()
|
||||
pt = User.objects.filter(id=ticket.participant).first()
|
||||
if pt and pt.phone:
|
||||
send_sms(pt.phone, 1002, params)
|
||||
elif ticket.participant_type == 2:
|
||||
pts = User.objects.filter(id__in=ticket.participant, is_active=True)
|
||||
pts = User.objects.filter(id__in=ticket.participant)
|
||||
for i in pts:
|
||||
if i.phone:
|
||||
send_sms(i.phone, 1002, params)
|
||||
|
|
Loading…
Reference in New Issue