Commit 95ac8579 authored by allison.browne's avatar allison.browne

Alert Assignement Todo: auto add a todo assignment

Add an assignment todo automatically when an alert
is assigned via the sidebar.
parent 8e87e22d
......@@ -3,6 +3,8 @@
module AlertManagement
module Alerts
class UpdateService
include Gitlab::Utils::StrongMemoize
# @param alert [AlertManagement::Alert]
# @param current_user [User]
# @param params [Hash] Attributes of the alert
......@@ -19,6 +21,7 @@ module AlertManagement
filter_assignees
if alert.update(params)
assign_todo
success
else
error(alert.errors.full_messages.to_sentence)
......@@ -29,6 +32,12 @@ module AlertManagement
attr_reader :alert, :current_user, :params
def assign_todo
return unless assignee
todo_service.assign_alert(alert, assignee)
end
def allowed?
current_user.can?(:update_alert_management_alert, alert)
end
......@@ -36,8 +45,20 @@ module AlertManagement
def filter_assignees
return if params[:assignees].nil?
# Take first assignee while multiple are not currently supported
params[:assignees] = Array(params[:assignees].first)
params[:assignees] = Array(assignee)
end
def assignee
strong_memoize(:assignee) do
# Take first assignee while multiple are not currently supported
params[:assignees]&.first
end
end
def todo_service
strong_memoize(:todo_service) do
TodoService.new
end
end
def success
......
---
title: Add todo when alert is assigned to a user
merge_request: 34104
author:
type: added
......@@ -45,7 +45,7 @@ describe AlertManagement::Alerts::UpdateService do
end
end
context 'when a model attribute is included' do
context 'when a model attribute is included without assignees' do
let(:params) { { title: 'This is an updated alert.' } }
it 'updates the attribute' do
......@@ -54,6 +54,10 @@ describe AlertManagement::Alerts::UpdateService do
expect { response }.to change { alert.title }.from(original_title).to(params[:title])
expect(response).to be_success
end
it 'skips adding a todo' do
expect { response }.not_to change(Todo, :count)
end
end
context 'when assignees are included' do
......@@ -76,6 +80,10 @@ describe AlertManagement::Alerts::UpdateService do
expect(response).to be_success
end
end
it 'adds a todo' do
expect { response }.to change { Todo.where(user: user_with_permissions).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