Commit 78d9df93 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-deleted-user-in-audit-event' into 'master'

Fix deleted user in audit event

Closes gitlab-org/gitlab-ce#14425


See merge request !284
parents dcbbaffe ed82b804
......@@ -8,7 +8,7 @@ class AuditEventService
old_access_level = @details[:old_access_level]
author_name = @author.name
user_id = member.id
user_name = member.user.name
user_name = member.user ? member.user.name : 'Deleted User'
@details =
case action
......
require 'spec_helper'
describe AuditEventService, services: true do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:project_member) { create(:project_member, user: user) }
let(:service) { described_class.new(user, project, { action: :destroy }) }
describe '#for_member' do
it 'generates event' do
event = service.for_member(project_member).security_event
expect(event[:details][:target_details]).to eq(user.name)
end
it 'handles deleted users' do
expect(project_member).to receive(:user).and_return(nil)
event = service.for_member(project_member).security_event
expect(event[:details][:target_details]).to eq('Deleted User')
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