[Backend] Handle project and group transfer events

Why are we doing this work

Security scan profiles are grouped under the top-level group in the hierarchy, and they are associated with projects.

If a project or one of its parent groups is transferred, the profile associated with that project may no longer be available for the project. In that case, we will need to remove the link between the profile and the project.

We should also reassign profiles when a top-level group is transferred, which means it's not a top-level group anymore.

Implementation plan

  • Subscribe to ::Projects::ProjectTransferedEvent, and ::Groups::GroupTransferedEvent.
  • Drop the links between profiles and projects when the profile is no longer available for the project.
  • Assign profiles of moving top-level group to new top-level group.

Verification steps

  • Verify that the previously associated profiles are no longer associated with the project when it moves to a different top-level group
  • Verify that the previously associated profiles are no longer associated with the projects under the group when it moves to a different top-level group
  • Verify that the profiles organized under a group move to the new top-level group as the group moves.
Edited by 🤖 GitLab Bot 🤖