[18.0][UPD] base_user_role: prevents deletion of roles in use #404
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this change do?
This PR implements a validation mechanism that prevents the deletion of user roles that are still assigned to active users.
The implementation adds a pre-deletion check to the
res.users.rolemodel'sunlink()method by searching for anyres.users.role.linerecords that link users to the roles being deleted.If such records are found, a
UserErroris raised with a descriptive message indicating which roles cannot be deleted because they are still in use.Technical Details:
unlink()method in theResUsersRolemodel to intercept deletion attemptsres.users.role.lineintermediary table before executing the deletionUserErrorwith role names for better user feedbacksuper().unlink()Why is this change being introduced?
Business Context:
Previously, user roles could be deleted even when they were actively assigned to users, leading to inconsistent states and confusion.
Compliance & Stability:
Which modules are affected?
models/role.py: Addedunlink()method override toResUsersRoleclassi18n/de.po: Added German translation for the error message