|
@@ -12,6 +12,8 @@ from rest_framework.views import APIView
|
|
|
from apps.staff.serializers import UserSerializer
|
|
|
from apps.staff.filters import UserFilter
|
|
|
from apps.system.models import SysLog
|
|
|
+from apps.examination.exam.models import ExamLog
|
|
|
+
|
|
|
User = get_user_model()
|
|
|
|
|
|
class UserViewSet(CustomModelViewSet):
|
|
@@ -35,6 +37,18 @@ class UserViewSet(CustomModelViewSet):
|
|
|
validated_data = serializer.validated_data
|
|
|
SysLog.objects.addnew(self.request.user, SysLog.UPDATE, u'修改账户[%s],id=%d' % (instance.username, instance.id), validated_data)
|
|
|
|
|
|
+ def destroy(self, request, *args, **kwargs):
|
|
|
+ with transaction.atomic():
|
|
|
+ instance = self.get_object()
|
|
|
+ log_count = SysLog.objects.filter(user_id=instance.id).count()
|
|
|
+ exam_log_count = ExamLog.objects.filter(user_id=instance.id).count()
|
|
|
+ if log_count > 0 or exam_log_count > 0:
|
|
|
+ raise CustomError(u'该账号有使用记录,禁止删除!')
|
|
|
+
|
|
|
+ SysLog.objects.addnew(self.request.user, SysLog.DELETE, u'删除用户[%s],id=%d' % (instance.name, instance.id))
|
|
|
+ instance.delete()
|
|
|
+ return response_ok()
|
|
|
+
|
|
|
|
|
|
class ChangePasswordView(APIView):
|
|
|
permission_classes = [IsAdministrator, ]
|