Skip to content

Commit

Permalink
Ruff: fix Q004
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jun 14, 2024
1 parent 77a075f commit 2fec1ea
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
28 changes: 14 additions & 14 deletions dojo/api_v2/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def has_permission(self, request, view):
)
elif engagement_id := converted_dict.get("engagement_id"):
# engagement_id doesn't exist
msg = f"Engagement \"{engagement_id}\" does not exist"
msg = f'Engagement "{engagement_id}" does not exist'
raise serializers.ValidationError(msg)

if not converted_dict.get("auto_create_context"):
Expand Down Expand Up @@ -492,7 +492,7 @@ def has_permission(self, request, view):
)
elif product_id := converted_dict.get("product_id"):
# product_id doesn't exist
msg = f"Product \"{product_id}\" does not exist"
msg = f'Product "{product_id}" does not exist'
raise serializers.ValidationError(msg)
else:
msg = "Need product_id or product_name to perform import"
Expand Down Expand Up @@ -633,7 +633,7 @@ def has_permission(self, request, view):
)
elif test_id := converted_dict.get("test_id"):
# test_id doesn't exist
msg = f"Test \"{test_id}\" does not exist"
msg = f'Test "{test_id}" does not exist'
raise serializers.ValidationError(msg)

if not converted_dict.get("auto_create_context"):
Expand Down Expand Up @@ -927,28 +927,28 @@ def raise_no_auto_create_import_validation_error(
raise ValidationError(msg)

if product_type_name and not product_type:
msg = f"Product Type \"{product_type_name}\" does not exist"
msg = f'Product Type "{product_type_name}" does not exist'
raise serializers.ValidationError(msg)

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

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

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

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

raise ValidationError(error_message)
Expand Down Expand Up @@ -995,28 +995,28 @@ def check_auto_create_permission(

if product and product_name and engagement_name:
if not user_has_permission(user, product, Permissions.Engagement_Add):
msg = f"No permission to create engagements in product \"{product_name}\""
msg = f'No permission to create engagements in product "{product_name}"'
raise PermissionDenied(msg)

if not user_has_permission(
user, product, Permissions.Import_Scan_Result
):
msg = f"No permission to import scans into product \"{product_name}\""
msg = f'No permission to import scans into product "{product_name}"'
raise PermissionDenied(msg)

# all good
return True

if not product and product_name:
if not product_type_name:
msg = f"Product \"{product_name}\" does not exist and no product_type_name provided to create the new product in"
msg = f'Product "{product_name}" does not exist and no product_type_name provided to create the new product in'
raise serializers.ValidationError(msg)

if not product_type:
if not user_has_global_permission(
user, Permissions.Product_Type_Add
):
msg = f"No permission to create product_type \"{product_type_name}\""
msg = f'No permission to create product_type "{product_type_name}"'
raise PermissionDenied(msg)
# new product type can be created with current user as owner, so
# all objects in it can be created as well
Expand All @@ -1025,7 +1025,7 @@ def check_auto_create_permission(
if not user_has_permission(
user, product_type, Permissions.Product_Type_Add_Product
):
msg = f"No permission to create products in product_type \"{product_type}\""
msg = f'No permission to create products in product_type "{product_type}"'
raise PermissionDenied(msg)

# product can be created, so objects in it can be created as well
Expand Down
2 changes: 1 addition & 1 deletion dojo/importers/base_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def sanitize_severity(
# Ensure the final severity is one of the supported options
if finding.severity not in SEVERITIES:
msg = (
f"Finding severity \"{finding.severity}\" is not supported. "
f'Finding severity "{finding.severity}" is not supported. '
f"Any of the following are supported: {SEVERITIES}."
)
raise ValidationError(msg)
Expand Down
2 changes: 1 addition & 1 deletion dojo/importers/default_reimporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def match_new_finding_to_existing_finding(
severity=unsaved_finding.severity,
numerical_severity=Finding.get_numerical_severity(unsaved_finding.severity)).order_by('id')
else:
logger.error(f"Internal error: unexpected deduplication_algorithm: \"{self.deduplication_algorithm}\"")
logger.error(f'Internal error: unexpected deduplication_algorithm: "{self.deduplication_algorithm}"')
return None

def process_matched_finding(
Expand Down
2 changes: 1 addition & 1 deletion dojo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class System_Settings(models.Model):
default=True,
blank=False,
verbose_name=_("Password must contain one special character"),
help_text=_("Requires user passwords to contain at least one special character (()[]{}|\\`~!@#$%^&*_-+=;:\'\",<>./?)."))
help_text=_("Requires user passwords to contain at least one special character (()[]{}|\\`~!@#$%^&*_-+=;:'\",<>./?)."))
lowercase_character_required = models.BooleanField(
default=True,
blank=False,
Expand Down
8 changes: 4 additions & 4 deletions dojo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2059,11 +2059,11 @@ def get_current_request():


def create_bleached_link(url, title):
link = '<a href=\"'
link = '<a href="'
link += url
link += '\" target=\"_blank\" title=\"'
link += '" target="_blank" title="'
link += title
link += '\">'
link += '">'
link += title
link += '</a>'
return bleach.clean(link, tags={'a'}, attributes={'a': ['href', 'target', 'title']})
Expand Down Expand Up @@ -2399,7 +2399,7 @@ def get_password_requirements_string():
if bool(get_system_setting('number_character_required')):
s += ', one number (0-9)'
if bool(get_system_setting('special_character_required')):
s += ', one special character (()[]{}|\\`~!@#$%^&*_-+=;:\'\",<>./?)'
s += ', one special character (()[]{}|\\`~!@#$%^&*_-+=;:\'",<>./?)'

if s.count(', ') == 1:
password_requirements_string = s.rsplit(', ', 1)[0] + ' and ' + s.rsplit(', ', 1)[1]
Expand Down
2 changes: 1 addition & 1 deletion unittests/test_apiv2_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_endpoint_missing_host_product(self):
"host": "FOO.BAR"
}, format='json')
self.assertEqual(r.status_code, 400, r.content[:1000])
self.assertIn("Attribute \'product\' is required", r.content.decode("utf-8"))
self.assertIn("Attribute 'product' is required", r.content.decode("utf-8"))

r = self.client.post(reverse('endpoint-list'), {
"product": 1
Expand Down
Loading

0 comments on commit 2fec1ea

Please sign in to comment.