Commit 1647339d authored by Sean Arnold's avatar Sean Arnold Committed by Markus Koller

Resolve "Automatically mark To-do as done when an alert is resolved"

parent 3e2e2a8b
...@@ -18,6 +18,7 @@ module AlertManagement ...@@ -18,6 +18,7 @@ module AlertManagement
return error_invalid_status unless status_key return error_invalid_status unless status_key
if alert.update(status_event: status_event) if alert.update(status_event: status_event)
resolve_todos if resolved?
success success
else else
error(alert.errors.full_messages.to_sentence) error(alert.errors.full_messages.to_sentence)
...@@ -28,12 +29,16 @@ module AlertManagement ...@@ -28,12 +29,16 @@ module AlertManagement
attr_reader :alert, :user, :status attr_reader :alert, :user, :status
delegate :project, to: :alert delegate :project, :resolved?, to: :alert
def allowed? def allowed?
user.can?(:update_alert_management_alert, project) user.can?(:update_alert_management_alert, project)
end end
def resolve_todos
TodoService.new.resolve_todos_for_target(alert, user)
end
def status_key def status_key
strong_memoize(:status_key) do strong_memoize(:status_key) do
AlertManagement::Alert::STATUSES.key(status) AlertManagement::Alert::STATUSES.key(status)
......
---
title: Resolve user's todo when an alert is resolved
merge_request: 35700
author:
type: added
...@@ -25,7 +25,7 @@ RSpec.describe AlertManagement::UpdateAlertStatusService do ...@@ -25,7 +25,7 @@ RSpec.describe AlertManagement::UpdateAlertStatusService do
end end
end end
let(:new_status) { Types::AlertManagement::StatusEnum.values['ACKNOWLEDGED'].value } let(:new_status) { AlertManagement::Alert::STATUSES[:acknowledged] }
let(:can_update) { true } let(:can_update) { true }
subject(:response) { service.execute } subject(:response) { service.execute }
...@@ -45,6 +45,23 @@ RSpec.describe AlertManagement::UpdateAlertStatusService do ...@@ -45,6 +45,23 @@ RSpec.describe AlertManagement::UpdateAlertStatusService do
expect { response }.to change { alert.acknowledged? }.to(true) expect { response }.to change { alert.acknowledged? }.to(true)
end end
context 'resolving status' do
let(:new_status) { AlertManagement::Alert::STATUSES[:resolved] }
it 'updates the status' do
expect { response }.to change { alert.resolved? }.to(true)
end
context 'user has a pending todo' do
let(:user) { create(:user) }
let!(:todo) { create(:todo, :pending, target: alert, user: user, project: alert.project) }
it 'resolves the todo' do
expect { response }.to change { todo.reload.state }.from('pending').to('done')
end
end
end
context 'when user has no permissions' do context 'when user has no permissions' do
let(:can_update) { false } let(:can_update) { false }
......
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