Commit 97dfd052 authored by Brett Walker's avatar Brett Walker

Set member_namespace_id when creating a Member

parent 810bd9cc
......@@ -181,6 +181,7 @@ class Member < ApplicationRecord
scope :on_project_and_ancestors, ->(project) { where(source: [project] + project.ancestors) }
before_validation :set_member_namespace_id, on: :create
before_validation :generate_invite_token, on: :create, if: -> (member) { member.invite_email.present? && !member.invite_accepted_at? }
after_create :send_invite, if: :invite?, unless: :importing?
......@@ -381,6 +382,12 @@ class Member < ApplicationRecord
private
# TODO: https://gitlab.com/groups/gitlab-org/-/epics/7054
# temporary until we can we properly remove the source columns
def set_member_namespace_id
self.member_namespace_id = self.source_id
end
def access_level_inclusion
return if access_level.in?(Gitlab::Access.all_values)
......
......@@ -118,6 +118,13 @@ class ProjectMember < Member
# rubocop:enable CodeReuse/ServiceClass
end
# TODO: https://gitlab.com/groups/gitlab-org/-/epics/7054
# temporary until we can we properly remove the source columns
override :set_member_namespace_id
def set_member_namespace_id
self.member_namespace_id = project&.project_namespace_id
end
def send_invite
run_after_commit_or_now { notification_service.invite_project_member(self, @raw_invite_token) }
......
......@@ -894,4 +894,15 @@ RSpec.describe Member do
end
end
end
describe '#set_member_namespace_id' do
let(:group) { create(:group) }
let(:member) { create(:group_member, group: group) }
describe 'on create' do
it 'sets the member_namespace_id' do
expect(member.member_namespace_id).to eq group.id
end
end
end
end
......@@ -257,4 +257,15 @@ RSpec.describe ProjectMember do
it_behaves_like 'calls AuthorizedProjectUpdate::UserRefreshFromReplicaWorker with a delay to update project authorizations'
end
end
describe '#set_member_namespace_id' do
let(:project) { create(:project) }
let(:member) { create(:project_member, project: project) }
context 'on create' do
it 'sets the member_namespace_id' do
expect(member.member_namespace_id).to eq project.project_namespace_id
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment