User's paid_namespaces only accounts for root namespaces
Background
The current implementation of User#paid_namespaces
only accounts for direct memberships with the root namespaces. This is not correct though because a user can have multiple ways how they belong to a namespace and are paid for:
- Membership via a sub-group
- Membership via a project
- Membership via an invite to a sub-group via another Group
- Membership via an invite to a project via another group
Problem
Some callers of the User#paid_namespaces
method expect it to include memberships of any paid groups, to inform certain actions such as whether or not a user can be immediately deleted, or banned.
Proposal
In #416651 (comment 1514718261) it was proposed and agreed that the method should be refactored to:
- Create a new method that better explains the response (
belongs_to_paid_namespace?
) - Use
owns_paid_namespace?
where appropriate - Update
paid_namespaces
to include the associated memberships as listed above
Status
Work has been carried towards this goal:
- The method was renamed in: !130863 (merged)
- An attempt to change the returned result of
paid_namespaces
was made in !130954 (closed) but had to be abandoned due to performance problems
This issue is now blocked from progressing due to those performance problems, which should hopefully be addressed as part of https://gitlab.com/gitlab-org/customers-gitlab-com/-/issues/7130.
Remaining work
Once the blocking issue is resolved, we should be able to continue to expand the scope of User#belongs_to_paid_namespace?
(via paid_namespaces
) to include all the edges (such as group invites).
Notes
Callers of the method have and should continue to be considered, see #416651 (comment 1545903827) for a breakdown and reasoning around whether to change to owns_paid_namespace?
.