Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff: add and fix EM rules #9892

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions dojo/api_v2/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
def check_post_permission(request, post_model, post_pk, post_permission):
if request.method == "POST":
if request.data.get(post_pk) is None:
raise ParseError(
f"Unable to check for permissions: Attribute '{post_pk}' is required"
)
msg = f"Unable to check for permissions: Attribute '{post_pk}' is required"
raise ParseError(msg)
object = get_object_or_404(post_model, pk=request.data.get(post_pk))
return user_has_permission(request.user, object, post_permission)
else:
Expand Down Expand Up @@ -516,9 +515,8 @@ def has_permission(self, request, view):
"product '%s' doesn''t exist" % product_id
)
else:
raise serializers.ValidationError(
"Need product_id or product_name to perform import"
)
msg = "Need product_id or product_name to perform import"
raise serializers.ValidationError(msg)


class UserHasProductPermission(permissions.BasePermission):
Expand Down Expand Up @@ -950,10 +948,12 @@ def raise_no_auto_create_import_validation_error(
):
# check for mandatory fields first
if not product_name:
raise ValidationError("product_name parameter missing")
msg = "product_name parameter missing"
raise ValidationError(msg)

if not engagement_name:
raise ValidationError("engagement_name parameter missing")
msg = "engagement_name parameter missing"
raise ValidationError(msg)

if product_type_name and not product_type:
raise serializers.ValidationError(
Expand All @@ -962,29 +962,25 @@ def raise_no_auto_create_import_validation_error(

if product_name and not product:
if product_type_name:
raise serializers.ValidationError(
f"Product '{product_name}' doesn't exist in Product_Type '{product_type_name}'"
)
msg = f"Product '{product_name}' doesn't exist in Product_Type '{product_type_name}'"
raise serializers.ValidationError(msg)
else:
raise serializers.ValidationError(
"Product '%s' doesn't exist" % product_name
)

if engagement_name and not engagement:
raise serializers.ValidationError(
f"Engagement '{engagement_name}' doesn't exist in Product '{product_name}'"
)
msg = f"Engagement '{engagement_name}' doesn't exist in Product '{product_name}'"
raise serializers.ValidationError(msg)

# these are only set for reimport
if test_title:
raise serializers.ValidationError(
f"Test '{test_title}' with scan_type '{scan_type}' doesn't exist in Engagement '{engagement_name}'"
)
msg = f"Test '{test_title}' with scan_type '{scan_type}' doesn't exist in Engagement '{engagement_name}'"
raise serializers.ValidationError(msg)

if scan_type:
raise serializers.ValidationError(
f"Test with scan_type '{scan_type}' doesn't exist in Engagement '{engagement_name}'"
)
msg = f"Test with scan_type '{scan_type}' doesn't exist in Engagement '{engagement_name}'"
raise serializers.ValidationError(msg)

raise ValidationError(error_message)

Expand Down Expand Up @@ -1015,10 +1011,12 @@ def check_auto_create_permission(
- User must have Product_Type_Add_Product permission for the Product_Type, or the user has the Product_Type_Add permission
"""
if not product_name:
raise ValidationError("product_name parameter missing")
msg = "product_name parameter missing"
raise ValidationError(msg)

if not engagement_name:
raise ValidationError("engagement_name parameter missing")
msg = "engagement_name parameter missing"
raise ValidationError(msg)

if engagement:
# existing engagement, nothing special to check
Expand Down
Loading
Loading