Commit ba2bce61 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'alert-todo-final' into 'master'

Add GitLab to-do for user when they are assigned to an alert

See merge request gitlab-org/gitlab!34104
parents 00477e9d 95ac8579
......@@ -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