Skip to content

Commit

Permalink
处理管理员指定工单提交人时异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed Oct 7, 2022
1 parent 4afae1e commit 813a16e
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions sql_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,6 @@ def validate_group_id(group_id):
raise serializers.ValidationError({"errors": f"不存在该资源组:{group_id}"})
return group_id

def validate_engineer(self, engineer):
"""仅管理员做engineer校验"""
user = self.context["request"].user
if user.is_superuser:
try:
Users.objects.get(username=engineer)
except Users.DoesNotExist:
raise serializers.ValidationError({"errors": f"不存在用户:{engineer}"})
return engineer

class Meta:
model = SqlWorkflow
fields = "__all__"
Expand Down Expand Up @@ -361,8 +351,11 @@ def create(self, validated_data):
engineer = workflow_data.get("engineer")

# 管理员可以指定提交人信息
if self.context["request"].user.is_superuser:
user = Users.objects.get(username=engineer)
if self.context["request"].user.is_superuser and engineer:
try:
user = Users.objects.get(username=engineer)
except Users.DoesNotExist:
raise serializers.ValidationError({"errors": f"不存在用户:{engineer}"})
# 提交人只能是自己
else:
user = self.context["request"].user
Expand Down

0 comments on commit 813a16e

Please sign in to comment.