Commit 6840b554 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '215946-add-gitlab-to-do-for-user-when-they-are-assigned-to-an-alert' into 'master'

Allow For GitLab Todos Created From Alerts

See merge request gitlab-org/gitlab!33743
parents 9de9a747 413a73cc
......@@ -55,6 +55,7 @@ module TodosHelper
def todo_target_type_name(todo)
return _('design') if todo.for_design?
return _('alert') if todo.for_alert?
todo.target_type.titleize.downcase
end
......@@ -68,6 +69,8 @@ module TodosHelper
project_commit_path(todo.project, todo.target, path_options)
elsif todo.for_design?
todos_design_path(todo, path_options)
elsif todo.for_alert?
details_project_alert_management_path(todo.project, todo.target)
else
path = [todo.resource_parent, todo.target]
......
......@@ -4,6 +4,7 @@ require_dependency 'alert_management'
module AlertManagement
class Alert < ApplicationRecord
include IidRoutes
include AtomicInternalId
include ShaAttribute
include Sortable
......@@ -143,6 +144,12 @@ module AlertManagement
increment!(:events)
end
# required for todos (typically contains an identifier like issue iid)
# no-op; we could use iid, but we don't have a reference prefix
def to_reference(_from = nil, full: false)
''
end
private
def hosts_length
......
......@@ -189,6 +189,10 @@ class Todo < ApplicationRecord
target_type == DesignManagement::Design.name
end
def for_alert?
target_type == AlertManagement::Alert.name
end
# override to return commits, which are not active record
def target
if for_commit?
......
......@@ -25926,6 +25926,9 @@ msgstr ""
msgid "ago"
msgstr ""
msgid "alert"
msgstr ""
msgid "allowed to fail"
msgstr ""
......
......@@ -20,6 +20,10 @@ describe TodosHelper do
author: author,
note: note)
end
let_it_be(:alert_todo) do
alert = create(:alert_management_alert, iid: 1001)
create(:todo, target: alert)
end
describe '#todos_count_format' do
it 'shows fuzzy count for 100 or more items' do
......@@ -115,6 +119,18 @@ describe TodosHelper do
expect(path).to eq("#{issue_path}/designs/#{design.filename}##{dom_id(design_todo.note)}")
end
end
context 'when given an alert' do
let(:todo) { alert_todo }
it 'responds with an appropriate path' do
path = helper.todo_target_path(todo)
expect(path).to eq(
"/#{todo.project.full_path}/-/alert_management/#{todo.target.iid}/details"
)
end
end
end
describe '#todo_target_type_name' do
......@@ -127,6 +143,16 @@ describe TodosHelper do
expect(name).to eq('design')
end
end
context 'when given an alert todo' do
let(:todo) { alert_todo }
it 'responds with an appropriate target type name' do
name = helper.todo_target_type_name(todo)
expect(name).to eq('alert')
end
end
end
describe '#todo_types_options' do
......
......@@ -242,6 +242,12 @@ describe AlertManagement::Alert do
end
end
describe '#to_reference' do
let(:alert) { build(:alert_management_alert) }
it { expect(alert.to_reference).to eq('') }
end
describe '#trigger' do
subject { alert.trigger }
......
......@@ -100,6 +100,20 @@ describe Todo do
end
end
describe '#for_alert?' do
it 'returns true when target is a Alert' do
subject.target_type = 'AlertManagement::Alert'
expect(subject.for_alert?).to eq(true)
end
it 'returns false when target is not a Alert' do
subject.target_type = 'Issue'
expect(subject.for_alert?).to eq(false)
end
end
describe '#target' do
context 'for commits' do
let(:project) { create(:project, :repository) }
......
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