Commit 5912f3de authored by Dmitriy Zaporozhets (DZ)'s avatar Dmitriy Zaporozhets (DZ)

Merge branch '247910-invite-tokens-not-cleared-after-invite-is-accepted' into 'master'

Add invitation debug logging

See merge request gitlab-org/gitlab!66923
parents bd464195 3b229bb6
...@@ -175,6 +175,8 @@ class Member < ApplicationRecord ...@@ -175,6 +175,8 @@ class Member < ApplicationRecord
after_update :post_update_hook, unless: [:pending?, :importing?], if: :hook_prerequisites_met? after_update :post_update_hook, unless: [:pending?, :importing?], if: :hook_prerequisites_met?
after_destroy :destroy_notification_setting after_destroy :destroy_notification_setting
after_destroy :post_destroy_hook, unless: :pending?, if: :hook_prerequisites_met? after_destroy :post_destroy_hook, unless: :pending?, if: :hook_prerequisites_met?
after_save :log_invitation_token_cleanup
after_commit :refresh_member_authorized_projects after_commit :refresh_member_authorized_projects
default_value_for :notification_level, NotificationSetting.levels[:global] default_value_for :notification_level, NotificationSetting.levels[:global]
...@@ -449,6 +451,13 @@ class Member < ApplicationRecord ...@@ -449,6 +451,13 @@ class Member < ApplicationRecord
def project_bot? def project_bot?
user&.project_bot? user&.project_bot?
end 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 end
Member.prepend_mod_with('Member') Member.prepend_mod_with('Member')
...@@ -749,4 +749,44 @@ RSpec.describe Member do ...@@ -749,4 +749,44 @@ RSpec.describe Member do
end end
end 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 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