Commit 39e82f60 authored by Sean Arnold's avatar Sean Arnold

Merge branch '345109-timeline-event-system-note-on-delete' into 'master'

Add system note when timeline event deleted

See merge request gitlab-org/gitlab!83406
parents 37213c92 95ca5eb7
......@@ -124,6 +124,10 @@ module EE
incidents_service(timeline_event.incident).add_timeline_event(timeline_event)
end
def delete_timeline_event(noteable, author)
incidents_service(noteable).delete_timeline_event(author)
end
private
def issuables_service(noteable, project, author)
......
......@@ -9,12 +9,15 @@ module IncidentManagement
@timeline_event = timeline_event
@user = user
@incident = timeline_event.incident
@project = @incident.project
end
def execute
return error_no_permissions unless allowed?
if timeline_event.destroy
add_system_note(incident, user)
success(timeline_event)
else
error_in_save(timeline_event)
......@@ -23,7 +26,13 @@ module IncidentManagement
private
attr_reader :timeline_event, :user, :incident
attr_reader :project, :timeline_event, :user, :incident
def add_system_note(incident, user)
return unless Feature.enabled?(:incident_timeline, project, default_enabled: :yaml)
SystemNoteService.delete_timeline_event(incident, user)
end
end
end
end
......@@ -15,5 +15,11 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: 'timeline_event'))
end
def delete_timeline_event(author)
body = 'deleted an incident timeline event'
create_note(NoteSummary.new(noteable, project, author, body, action: 'timeline_event'))
end
end
end
......@@ -68,5 +68,25 @@ RSpec.describe IncidentManagement::TimelineEvents::DestroyService do
expect(result).to be_a(::IncidentManagement::TimelineEvent)
expect(result.id).to eq(timeline_event.id)
end
context 'when incident_timeline feature flag is enabled' do
before do
stub_feature_flags(incident_timeline: project)
end
it 'creates a system note' do
expect { execute }.to change { incident.notes.reload.count }.by(1)
end
end
context 'when incident_timeline feature flag is disabled' do
before do
stub_feature_flags(incident_timeline: false)
end
it 'does not create a system note' do
expect { execute }.not_to change { incident.notes.reload.count }
end
end
end
end
......@@ -185,4 +185,14 @@ RSpec.describe SystemNoteService do
described_class.add_timeline_event(timeline_event)
end
end
describe '.delete_timeline_event' do
it 'calls IncidentsService' do
expect_next_instance_of(::SystemNotes::IncidentsService) do |service|
expect(service).to receive(:delete_timeline_event).with(author)
end
described_class.delete_timeline_event(noteable, author)
end
end
end
......@@ -11,7 +11,7 @@ RSpec.describe SystemNotes::IncidentsService do
let_it_be(:incident) { create(:incident, project: project, author: user) }
let_it_be(:timeline_event) { create(:incident_management_timeline_event, project: project, incident: incident, author: author) }
describe "#add_timeline_event" do
describe '#add_timeline_event' do
subject { described_class.new(noteable: incident).add_timeline_event(timeline_event) }
it_behaves_like 'a system note' do
......@@ -19,9 +19,22 @@ RSpec.describe SystemNotes::IncidentsService do
let(:action) { 'timeline_event' }
end
it 'poses the correct text to the system note' do
it 'posts the correct text to the system note' do
path = project_issues_incident_path(project, incident, anchor: "timeline_event_#{timeline_event.id}")
expect(subject.note).to match("added an [incident timeline event](#{path})")
end
end
describe '#delete_timeline_event' do
subject { described_class.new(noteable: incident).delete_timeline_event(author) }
it_behaves_like 'a system note' do
let(:noteable) { incident }
let(:action) { 'timeline_event' }
end
it 'posts the correct text to the system note' do
expect(subject.note).to match('deleted an incident timeline event')
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