[BE]Modify member_approvals factory to create members for the passed namespace

Currently the factory creates members for any namespace, not necessarily for the namespace that is passed. We need to fix that.

=> FactoryBot.create(:gitlab_subscription_member_management_member_approval)

=> #<GitlabSubscriptions::MemberManagement::MemberApproval:0x0000000325770510
 id: 16,
 reviewed_at: nil,
 created_at: Fri, 04 Apr 2025 08:07:12.087022000 UTC +00:00,
 updated_at: Fri, 04 Apr 2025 08:07:12.087022000 UTC +00:00,
 member_id: 117,
 member_namespace_id: 105,
 requested_by_id: 81,
 reviewed_by_id: 82,
 new_access_level: 30,
 old_access_level: 10,
 status: "pending",
 user_id: 83,
 member_role_id: nil,
 metadata: {"access_level"=>30}>
[7] pry(main)> m.member
=> #<ProjectMember:0x0000000321837448
 id: 117,
 access_level: 40,
 source_id: 11,
 source_type: "Project",
 user_id: 83,
 notification_level: 3,
 type: "ProjectMember",
 created_at: Fri, 04 Apr 2025 08:07:11.862886000 UTC +00:00,
 updated_at: Fri, 04 Apr 2025 08:07:11.862886000 UTC +00:00,
 created_by_id: nil,
 invite_email: nil,
 invite_token: nil,
 invite_accepted_at: nil,
 requested_at: nil,
 expires_at: nil,
 ldap: false,
 override: false,
 state: 0,
 invite_email_success: true,
 member_namespace_id: 104,
 member_role_id: nil,
 expiry_notified_at: nil,
 request_accepted_at: nil,
 is_source_accessible_to_current_user: true>
[8] pry(main)> m.member_namespace
=> #<Namespaces::UserNamespace id:105 @namespace4>

As can be seen the member_approval.member.member_namespace_id is 104, whereas the member_approval.member_namespace_id is 105.

Similarly even when we pass a member_namespace the member object that gets created is for a totally different member_namespace

=> grp = FactoryBot.create(:group)
=> m = FactoryBot.create(:gitlab_subscription_member_management_member_approval, member_namespace: grp)
=> #<GitlabSubscriptions::MemberManagement::MemberApproval:0x000000031037b550
 id: 17,
 reviewed_at: nil,
 created_at: Fri, 04 Apr 2025 08:12:03.481595000 UTC +00:00,
 updated_at: Fri, 04 Apr 2025 08:12:03.481595000 UTC +00:00,
 member_id: 119,
 member_namespace_id: 106,
 requested_by_id: 86,
 reviewed_by_id: 87,
 new_access_level: 30,
 old_access_level: 10,
 status: "pending",
 user_id: 88,
 member_role_id: nil,
 metadata: {"access_level"=>30}>
[12] pry(main)> grp.id
=> 106
[13] pry(main)> m.member_namespace
=> #<Group id:106 @group1>
[14] pry(main)> m.member.member_namespace
  Namespace Load (1.4ms)  SELECT "namespaces"."id", "namespaces"."name", "namespaces"."path", "namespaces"."owner_id", "namespaces"."created_at", "namespaces"."updated_at", "namespaces"."type", "namespaces"."description", "namespaces"."avatar", "namespaces"."membership_lock", "namespaces"."share_with_group_lock", "namespaces"."visibility_level", "namespaces"."request_access_enabled", "namespaces"."ldap_sync_status", "namespaces"."ldap_sync_error", "namespaces"."ldap_sync_last_update_at", "namespaces"."ldap_sync_last_successful_update_at", "namespaces"."ldap_sync_last_sync_at", "namespaces"."description_html", "namespaces"."lfs_enabled", "namespaces"."parent_id", "namespaces"."shared_runners_minutes_limit", "namespaces"."repository_size_limit", "namespaces"."require_two_factor_authentication", "namespaces"."two_factor_grace_period", "namespaces"."cached_markdown_version", "namespaces"."project_creation_level", "namespaces"."runners_token", "namespaces"."file_template_project_id", "namespaces"."saml_discovery_token", "namespaces"."runners_token_encrypted", "namespaces"."custom_project_templates_group_id", "namespaces"."auto_devops_enabled", "namespaces"."extra_shared_runners_minutes_limit", "namespaces"."last_ci_minutes_notification_at", "namespaces"."last_ci_minutes_usage_notification_level", "namespaces"."subgroup_creation_level", "namespaces"."max_pages_size", "namespaces"."max_artifacts_size", "namespaces"."mentions_disabled", "namespaces"."default_branch_protection", "namespaces"."max_personal_access_token_lifetime", "namespaces"."push_rule_id", "namespaces"."shared_runners_enabled", "namespaces"."allow_descendants_override_disabled_shared_runners", "namespaces"."traversal_ids", "namespaces"."organization_id" FROM "namespaces" WHERE "namespaces"."id" = 111 LIMIT 1 /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:stripathi--20250123-YQ6WT,console_username:surajtripathi,line:(pry):14:in `__pry__'*/
  Route Load (0.6ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 111 AND "routes"."source_type" = 'Namespaces::ProjectNamespace' LIMIT 1 /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:stripathi--20250123-YQ6WT,console_username:surajtripathi,line:/app/models/concerns/routable.rb:155:in `block in full_attribute'*/
  Namespace Load (0.4ms)  SELECT "namespaces"."id", "namespaces"."name", "namespaces"."path", "namespaces"."owner_id", "namespaces"."created_at", "namespaces"."updated_at", "namespaces"."type", "namespaces"."description", "namespaces"."avatar", "namespaces"."membership_lock", "namespaces"."share_with_group_lock", "namespaces"."visibility_level", "namespaces"."request_access_enabled", "namespaces"."ldap_sync_status", "namespaces"."ldap_sync_error", "namespaces"."ldap_sync_last_update_at", "namespaces"."ldap_sync_last_successful_update_at", "namespaces"."ldap_sync_last_sync_at", "namespaces"."description_html", "namespaces"."lfs_enabled", "namespaces"."parent_id", "namespaces"."shared_runners_minutes_limit", "namespaces"."repository_size_limit", "namespaces"."require_two_factor_authentication", "namespaces"."two_factor_grace_period", "namespaces"."cached_markdown_version", "namespaces"."project_creation_level", "namespaces"."runners_token", "namespaces"."file_template_project_id", "namespaces"."saml_discovery_token", "namespaces"."runners_token_encrypted", "namespaces"."custom_project_templates_group_id", "namespaces"."auto_devops_enabled", "namespaces"."extra_shared_runners_minutes_limit", "namespaces"."last_ci_minutes_notification_at", "namespaces"."last_ci_minutes_usage_notification_level", "namespaces"."subgroup_creation_level", "namespaces"."max_pages_size", "namespaces"."max_artifacts_size", "namespaces"."mentions_disabled", "namespaces"."default_branch_protection", "namespaces"."max_personal_access_token_lifetime", "namespaces"."push_rule_id", "namespaces"."shared_runners_enabled", "namespaces"."allow_descendants_override_disabled_shared_runners", "namespaces"."traversal_ids", "namespaces"."organization_id" FROM "namespaces" WHERE "namespaces"."id" = 110 LIMIT 1 /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:stripathi--20250123-YQ6WT,console_username:surajtripathi,line:/app/models/concerns/routable.rb:138:in `build_full_path'*/
  Route Load (0.2ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 110 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:stripathi--20250123-YQ6WT,console_username:surajtripathi,line:/app/models/concerns/routable.rb:155:in `block in full_attribute'*/
=> #<Namespaces::ProjectNamespace id:111 @namespace5/project-3>

As can be seen the member_approval.member.member_namespace_id is 106 which was the id of the grp that was passed, whereas the member_approval.member_namespace_id is 111 which is a totally different namespace.

Edited by Suraj Tripathi