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

[17.0][FIX] base_tier_validation - fix 'false positive' raise #1024

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
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
60 changes: 35 additions & 25 deletions base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ def _get_fields_to_write_validation(self, vals, records_exception_function):
if not not_allowed_fields:
return []

not_allowed_field_names, allowed_field_names = [], []
not_allowed_field_names, allowed_field_names = {}, {}
for fld_name, fld_data in self.fields_get(
not_allowed_fields + exceptions
).items():
if fld_name in not_allowed_fields:
not_allowed_field_names.append(fld_data["string"])
not_allowed_field_names[fld_name] = fld_data["string"]
else:
allowed_field_names.append(fld_data["string"])
allowed_field_names[fld_name] = fld_data["string"]
return allowed_field_names, not_allowed_field_names

def _check_tier_state_transition(self, vals):
Expand Down Expand Up @@ -437,17 +437,22 @@ def _tier_validation_check_write_allowed(self, vals):
) = rec._get_fields_to_write_validation(
vals, rec._get_under_validation_exceptions
)
raise ValidationError(
_(
"You are not allowed to write those fields under validation.\n"
"- %(not_allowed_fields)s\n\n"
"Only those fields can be modified:\n- %(allowed_fields)s"
)
% {
"not_allowed_fields": "\n- ".join(not_allowed_fields),
"allowed_fields": "\n- ".join(allowed_fields),
}
)
for not_allowed_field in not_allowed_fields:
if vals[not_allowed_field] != rec[not_allowed_field]:
raise ValidationError(
_(
"You are not allowed to write this field under "
"validation.\n- %(not_allowed_field)s\n\n"
"Only those fields can be modified:\n"
"- %(allowed_fields)s"
)
% {
"not_allowed_field": not_allowed_fields[
not_allowed_field
],
"allowed_fields": "\n- ".join(allowed_fields),
}
)

# Write after validation. Check only if Tier Validation Exception is created
if (
Expand All @@ -464,17 +469,22 @@ def _tier_validation_check_write_allowed(self, vals):
) = rec._get_fields_to_write_validation(
vals, rec._get_after_validation_exceptions
)
raise ValidationError(
_(
"You are not allowed to write those fields after validation.\n"
"- %(not_allowed_fields)s\n\n"
"Only those fields can be modified:\n- %(allowed_fields)s"
)
% {
"not_allowed_fields": "\n- ".join(not_allowed_fields),
"allowed_fields": "\n- ".join(allowed_fields),
}
)
for not_allowed_field in not_allowed_fields:
if vals[not_allowed_field] != rec[not_allowed_field]:
raise ValidationError(
_(
"You are not allowed to write this field after "
"validation.\n- %(not_allowed_field)s\n\n"
"Only those fields can be modified:\n"
"- %(allowed_fields)s"
)
% {
"not_allowed_field": not_allowed_fields[
not_allowed_field
],
"allowed_fields": "\n- ".join(allowed_fields),
}
)

def _tier_validation_check_write_remove_reviews(self, vals):
for rec in self:
Expand Down