Sonar refactor: Roles Controller

What does this MR do and why?

Resolve all sonar issues in roles_controller.py. Improving the code and documentation in required areas.

roles_controller.py now generates no issues in Sonar, Pylint, Ruff, and Ty! Removes 2 high, 4 medium, and 2 info severity issues in Sonar cloud.

  • Replace Typing Union[str | int] with updated str | int style.
  • Update delete_roles_permission to accept a Collection rather than a Sequence. This resolves two Sonar warnings and better captures the use behavior see elsewhere in Crafty. The Collection allows a set to be passed, not just a list or tuple.
  • Isorted roles_controller.py and server_permissions.py
  • Resolved FIXME in and improve get_server_ids_and_perms_from_role. Request to db now only grabs needed information rather than the entire server objects. Modified output to better match what type checker Ty wanted.
  • Added missing type annotations and docstrings to touched functions.
  • Removes unused version of update_role.
  • Resolves todo related to tracking update time in the database rather than calculating this value in the python code.

How to set up and validate locally

Most changes are stylistic, some parts of code logic are touched.

  • Confirm that role behavior remains as expected
  • Test that removing servers from a role behaves as expected
  • Edit a role and confirm that update time for the role still shows time correctly.
  • Confirm removing a manager for a role behaves as expected.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • Have you checked this doesn't interfere/conflict/duplicate someone elses work?
  • Have you fully tested your changes?
  • Have you resolved any lint issues?
  • Have you assigned a reviewer?
  • Have you applied correct labels?
Edited by Wout Bouckaert

Merge request reports

Loading