Commit ffa72325 authored by Valery Sizov's avatar Valery Sizov

[Multiple issue asignees] Fix spec/services/issues/update_service_spec.rb

parent 68791d0a
...@@ -48,13 +48,8 @@ class IssuableBaseService < BaseService ...@@ -48,13 +48,8 @@ class IssuableBaseService < BaseService
params.delete(:add_label_ids) params.delete(:add_label_ids)
params.delete(:remove_label_ids) params.delete(:remove_label_ids)
params.delete(:label_ids) params.delete(:label_ids)
params.delete(:assignee_ids)
if issuable.is_a?(Issue) params.delete(:assignee_id)
params.delete(:assignee_ids)
else
params.delete(:assignee_id)
end
params.delete(:due_date) params.delete(:due_date)
end end
...@@ -280,7 +275,7 @@ class IssuableBaseService < BaseService ...@@ -280,7 +275,7 @@ class IssuableBaseService < BaseService
end end
end end
def has_changes?(issuable, old_labels: []) def has_changes?(issuable, old_labels: [], old_assignees: [])
valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch] valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch]
attrs_changed = valid_attrs.any? do |attr| attrs_changed = valid_attrs.any? do |attr|
...@@ -289,7 +284,9 @@ class IssuableBaseService < BaseService ...@@ -289,7 +284,9 @@ class IssuableBaseService < BaseService
labels_changed = issuable.labels != old_labels labels_changed = issuable.labels != old_labels
attrs_changed || labels_changed assignees_changed = issuable.assignees != old_assignees
attrs_changed || labels_changed || assignees_changed
end end
def handle_common_system_notes(issuable, old_labels: []) def handle_common_system_notes(issuable, old_labels: [])
......
...@@ -9,9 +9,9 @@ module Issues ...@@ -9,9 +9,9 @@ module Issues
private private
def create_assignee_note(issue) def create_assignee_note(issue, old_assignees)
SystemNoteService.change_issue_assignees( SystemNoteService.change_issue_assignees(
issue, issue.project, current_user, issue.assignees) issue, issue.project, current_user, old_assignees)
end end
def execute_hooks(issue, action = 'open') def execute_hooks(issue, action = 'open')
...@@ -24,7 +24,15 @@ module Issues ...@@ -24,7 +24,15 @@ module Issues
def filter_assignee(issuable) def filter_assignee(issuable)
return if params[:assignee_ids].to_a.empty? return if params[:assignee_ids].to_a.empty?
params[:assignee_ids] = params[:assignee_ids].select{ |assignee_id| assignee_can_read?(issuable, assignee_id)} assignee_ids = params[:assignee_ids].select{ |assignee_id| assignee_can_read?(issuable, assignee_id)}
if params[:assignee_ids].map(&:to_s) == [IssuableFinder::NONE]
params[:assignee_ids] = []
elsif assignee_ids.any?
params[:assignee_ids] = assignee_ids
else
params.delete(:assignee_ids)
end
end end
end end
end end
...@@ -17,7 +17,7 @@ module Issues ...@@ -17,7 +17,7 @@ module Issues
old_mentioned_users = options[:old_mentioned_users] || [] old_mentioned_users = options[:old_mentioned_users] || []
old_assignees = options[:old_assignees] || [] old_assignees = options[:old_assignees] || []
if has_changes?(issue, old_labels: old_labels) if has_changes?(issue, old_labels: old_labels, old_assignees: old_assignees)
todo_service.mark_pending_todos_as_done(issue, current_user) todo_service.mark_pending_todos_as_done(issue, current_user)
end end
...@@ -31,7 +31,7 @@ module Issues ...@@ -31,7 +31,7 @@ module Issues
end end
if issue.assignees != old_assignees if issue.assignees != old_assignees
create_assignee_note(issue) create_assignee_note(issue, old_assignees)
notification_service.reassigned_issue(issue, current_user, old_assignees) notification_service.reassigned_issue(issue, current_user, old_assignees)
todo_service.reassigned_issue(issue, current_user) todo_service.reassigned_issue(issue, current_user)
end end
......
...@@ -67,18 +67,18 @@ module SystemNoteService ...@@ -67,18 +67,18 @@ module SystemNoteService
# "assigned to @user1 and @user2" # "assigned to @user1 and @user2"
# #
# Returns the created Note object # Returns the created Note object
def change_issue_assignees(issue, project, author, assignees) def change_issue_assignees(issue, project, author, old_assignees)
# TODO: basic implementation, should be improved before merging the MR # TODO: basic implementation, should be improved before merging the MR
body = body =
if issue.assignees.any? && assignees.any? if issue.assignees.any? && old_assignees.any?
unassigned_users = issue.assignees - assignees unassigned_users = old_assignees - issue.assignees
added_users = assignees - issue.assignees added_users = issue.assignees.to_a - old_assignees
"assigned to #{added_users.map(&:to_reference).to_sentence} and unassigned #{unassigned_users.map(&:to_reference).to_sentence}" "assigned to #{added_users.map(&:to_reference).to_sentence} and unassigned #{unassigned_users.map(&:to_reference).to_sentence}"
elsif issue.assignees.any? elsif old_assignees.any?
"removed all assignees" "removed all assignees"
elsif assignees.any? elsif issue.assignees.any?
"assigned to #{assignees.map(&:to_reference).to_sentence}" "assigned to #{issue.assignees.map(&:to_reference).to_sentence}"
end end
create_note(noteable: issue, project: project, author: author, note: body) create_note(noteable: issue, project: project, author: author, note: body)
......
...@@ -165,7 +165,7 @@ describe Issues::UpdateService, services: true do ...@@ -165,7 +165,7 @@ describe Issues::UpdateService, services: true do
non_member = create(:user) non_member = create(:user)
original_assignees = issue.assignees original_assignees = issue.assignees
update_issue(assignee_ids: non_member.id.to_s) update_issue(assignee_ids: [non_member.id])
expect(issue.reload.assignees).to eq(original_assignees) expect(issue.reload.assignees).to eq(original_assignees)
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