Skip to content

Commit

Permalink
Ruff: add and fix EM rules (#9892)
Browse files Browse the repository at this point in the history
* Ruff: add and fix EM rules

Signed-off-by: kiblik <5609770+kiblik@users.noreply.github.com>

* Update dojo/tools/api_sonarqube/api_client.py

Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com>

* Update dojo/tools/factory.py

Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com>

* Clean newline

---------

Signed-off-by: kiblik <5609770+kiblik@users.noreply.github.com>
Co-authored-by: Charles Neill <1749665+cneill@users.noreply.github.com>
  • Loading branch information
kiblik and cneill authored Apr 30, 2024
1 parent b4605c9 commit 1c9c74e
Show file tree
Hide file tree
Showing 110 changed files with 651 additions and 540 deletions.
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

0 comments on commit 1c9c74e

Please sign in to comment.