Allow self_and_descendants to include project namespaces
What does this MR do and why?
Currently calling Group#self_and_descendants only includes namespaces of the same type. As a result, ProjectNamespace is always excluded. This change allows the caller to specify that the results should include project namespaces.
Use Case
Enable next iteration of Group Credentials Inventory Credentials inventory project and group access ... (#498333 - closed)
Project and Group Access Tokens have a project_bot user associated with them. The project_bot user is only allowed to be a member of a single group or project. Currently, the only association that indicates ownership is that sole membership. Not only is this ambiguous/opaque, but it makes performant queries hard. Especially for the feature is question where we need the ability to query for all project_bot users, and subsequently all project access tokens owned by a given group hierarchy.
Our plan is to add a new column to user_details called bot_namespace which will be a foreign key and indicate the group or project (namespace) that owns the bot. With the change in this merge request we will be able to use a query such as User.joins(:user_detail).where(user_detail: { bot_namespace: group.self_and_descendants(include_project_namespaces: true) }) to find all bot users.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
| Before | After |
|---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.