Separate admin roles from the MemberRoles table
# Summary Admin roles are created by using the `Users::UserMemberRole` table to point to a `MemberRole` record. This naming convention is confusing and due to the differences between `MemberRoles` and admin/instance roles we are overloading the `MemberRole` class. Additionally, since the `member_roles` table uses `namespace_id` as a [sharding key](https://gitlab.com/gitlab-org/gitlab/-/blob/ia-pre-select-abilities-frontend/db/docs/member_roles.yml) for cells we are breaking things be [requiring](https://gitlab.com/gitlab-org/gitlab/-/blob/ia-pre-select-abilities-frontend/ee/app/models/members/member_role.rb#L26) the `namespace_id` to be nil for admin roles. This has also added complexity to our spec factories which has led to bugs. This issue is a proposal to create a new model, such as `Authz::InstanceMemberRole` which will look similar to the `MemberRole` table but with attributes that are associated with instance-wide roles, such as admin roles. ## Opportunities * Given we know that we’ll also want to introduce a instance_member_roles table that will be very similar to this extraction, we should be thoughtful of providing a good pattern for this. * … ## Potential Problems * Existing code will churn while refactored code will fall behind, how do we ensure it doesn't? * Code review for these files should insist that changes be made in both areas? # Steps to refactor/extract: 1. Prepare new codebase * First we need to prepare the new code. This is an extraction. Extracting a class from an existing class. We can approach this in layers, Models and DB, Service layers, APIs, Billing, Other, and Finally Front-end 2. Switch to new codebase * Switching to the new code will involve migrating existing data and enabling the code 3. Remove old codebase * Removing the existing code, and the feature flag ## Prepare new codebase See sub-epics listed below for breakdown of work. ## Switch to new codebase ``` * Backfill admin_member_roles to admin_roles * Switching to the new code will involve migrating existing data and enabling the code ``` ## Remove old codebase ``` * Remove admin roles concept from member roles * Replace MemberRole.non_admin with MemberRole.all ? * Removing feature flag ```
epic