Commit 3b229bb6 authored by Pavel Shutsin's avatar Pavel Shutsin

Add invitation debug logging

parent 7dfd9546
......@@ -175,6 +175,8 @@ class Member < ApplicationRecord
after_update :post_update_hook, unless: [:pending?, :importing?], if: :hook_prerequisites_met?
after_destroy :destroy_notification_setting
after_destroy :post_destroy_hook, unless: :pending?, if: :hook_prerequisites_met?
after_save :log_invitation_token_cleanup
after_commit :refresh_member_authorized_projects
default_value_for :notification_level, NotificationSetting.levels[:global]
......@@ -449,6 +451,13 @@ class Member < ApplicationRecord
def project_bot?
user&.project_bot?
end
def log_invitation_token_cleanup
return true unless Gitlab.com? && invite? && invite_accepted_at?
error = StandardError.new("Invitation token is present but invite was already accepted!")
Gitlab::ErrorTracking.track_exception(error, attributes.slice(%w["invite_accepted_at created_at source_type source_id user_id id"]))
end
end
Member.prepend_mod_with('Member')
......@@ -749,4 +749,44 @@ RSpec.describe Member do
end
end
end
describe 'log_invitation_token_cleanup' do
let_it_be(:project) { create :project }
context 'when on gitlab.com' do
before do
allow(Gitlab).to receive(:com?).and_return true
end
it "doesn't log info for members without invitation or accepted invitation" do
expect(Gitlab::ErrorTracking).not_to receive(:track_exception)
create :project_member
create :project_member, :invited, invite_accepted_at: nil
create :project_member, invite_token: nil, invite_accepted_at: Time.zone.now
end
it 'logs error for accepted members with token and creates membership' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(kind_of(StandardError), kind_of(Hash))
expect do
create :project_member, :invited, source: project, invite_accepted_at: Time.zone.now
end.to change { Member.count }.by(1)
end
end
context 'when not on gitlab.com' do
before do
allow(Gitlab).to receive(:com?).and_return false
end
it 'does not log error for accepted members with token and creates membership' do
expect(Gitlab::ErrorTracking).not_to receive(:track_exception)
expect do
create :project_member, :invited, source: project, invite_accepted_at: Time.zone.now
end.to change { Member.count }.by(1)
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