2018-07-05 10:18:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
# TodoService class
|
2016-02-15 18:13:52 +00:00
|
|
|
#
|
2016-06-02 13:46:58 +00:00
|
|
|
# Used for creating/updating todos after certain user actions
|
2016-02-15 18:13:52 +00:00
|
|
|
#
|
|
|
|
# Ex.
|
2016-02-20 13:59:59 +00:00
|
|
|
# TodoService.new.new_issue(issue, current_user)
|
2016-02-15 18:13:52 +00:00
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
class TodoService
|
2020-09-10 21:08:28 +00:00
|
|
|
include Gitlab::Utils::UsageData
|
2016-02-15 18:13:52 +00:00
|
|
|
# When create an issue we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * create a todo for assignee if issue is assigned
|
|
|
|
# * create a todo for each mentioned user on issue
|
2016-02-15 18:13:52 +00:00
|
|
|
#
|
|
|
|
def new_issue(issue, current_user)
|
2016-02-16 23:01:14 +00:00
|
|
|
new_issuable(issue, current_user)
|
2016-02-15 18:13:52 +00:00
|
|
|
end
|
|
|
|
|
2016-02-17 22:04:14 +00:00
|
|
|
# When update an issue we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * mark all pending todos related to the issue for the current user as done
|
2016-02-17 22:04:14 +00:00
|
|
|
#
|
2017-03-28 06:25:43 +00:00
|
|
|
def update_issue(issue, current_user, skip_users = [])
|
|
|
|
update_issuable(issue, current_user, skip_users)
|
2016-02-17 22:04:14 +00:00
|
|
|
end
|
|
|
|
|
2016-02-16 20:31:40 +00:00
|
|
|
# When close an issue we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * mark all pending todos related to the target for the current user as done
|
2016-02-16 20:31:40 +00:00
|
|
|
#
|
|
|
|
def close_issue(issue, current_user)
|
2020-05-28 18:08:37 +00:00
|
|
|
resolve_todos_for_target(issue, current_user)
|
2016-02-16 20:31:40 +00:00
|
|
|
end
|
|
|
|
|
2017-12-08 12:17:22 +00:00
|
|
|
# When we destroy a todo target we should:
|
2016-09-01 22:12:05 +00:00
|
|
|
#
|
2017-12-08 12:17:22 +00:00
|
|
|
# * refresh the todos count cache for all users with todos on the target
|
2016-09-01 22:12:05 +00:00
|
|
|
#
|
2017-12-08 12:17:22 +00:00
|
|
|
# This needs to yield back to the caller to destroy the target, because it
|
|
|
|
# collects the todo users before the todos themselves are deleted, then
|
|
|
|
# updates the todo counts for those users.
|
|
|
|
#
|
|
|
|
def destroy_target(target)
|
2021-04-23 12:09:52 +00:00
|
|
|
todo_user_ids = target.todos.distinct_user_ids
|
2017-12-08 12:17:22 +00:00
|
|
|
|
|
|
|
yield target
|
|
|
|
|
2021-04-23 12:09:52 +00:00
|
|
|
Users::UpdateTodoCountCacheService.new(todo_user_ids).execute if todo_user_ids.present?
|
2016-09-01 22:12:05 +00:00
|
|
|
end
|
|
|
|
|
2020-08-17 09:10:08 +00:00
|
|
|
# When we reassign an assignable object (issuable, alert) we should:
|
2016-02-15 18:13:52 +00:00
|
|
|
#
|
2020-08-17 09:10:08 +00:00
|
|
|
# * create a pending todo for new assignee if object is assigned
|
2016-02-15 18:13:52 +00:00
|
|
|
#
|
2020-08-17 09:10:08 +00:00
|
|
|
def reassigned_assignable(issuable, current_user, old_assignees = [])
|
2019-04-07 18:35:16 +00:00
|
|
|
create_assignment_todo(issuable, current_user, old_assignees)
|
2016-02-16 23:01:14 +00:00
|
|
|
end
|
|
|
|
|
2020-09-09 12:08:22 +00:00
|
|
|
# When we reassign an reviewable object (merge request) we should:
|
|
|
|
#
|
|
|
|
# * create a pending todo for new reviewer if object is assigned
|
|
|
|
#
|
|
|
|
def reassigned_reviewable(issuable, current_user, old_reviewers = [])
|
|
|
|
create_reviewer_todo(issuable, current_user, old_reviewers)
|
|
|
|
end
|
|
|
|
|
2016-02-16 23:01:14 +00:00
|
|
|
# When create a merge request we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * creates a pending todo for assignee if merge request is assigned
|
|
|
|
# * create a todo for each mentioned user on merge request
|
2016-02-16 23:01:14 +00:00
|
|
|
#
|
|
|
|
def new_merge_request(merge_request, current_user)
|
|
|
|
new_issuable(merge_request, current_user)
|
|
|
|
end
|
|
|
|
|
2016-02-17 22:04:14 +00:00
|
|
|
# When update a merge request we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * create a todo for each mentioned user on merge request
|
2016-02-17 22:04:14 +00:00
|
|
|
#
|
2017-03-28 06:25:43 +00:00
|
|
|
def update_merge_request(merge_request, current_user, skip_users = [])
|
|
|
|
update_issuable(merge_request, current_user, skip_users)
|
2016-02-17 22:04:14 +00:00
|
|
|
end
|
|
|
|
|
2016-02-16 23:47:33 +00:00
|
|
|
# When close a merge request we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * mark all pending todos related to the target for the current user as done
|
2016-02-16 23:47:33 +00:00
|
|
|
#
|
|
|
|
def close_merge_request(merge_request, current_user)
|
2020-05-28 18:08:37 +00:00
|
|
|
resolve_todos_for_target(merge_request, current_user)
|
2016-02-16 23:47:33 +00:00
|
|
|
end
|
|
|
|
|
2016-02-17 01:54:10 +00:00
|
|
|
# When merge a merge request we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * mark all pending todos related to the target for the current user as done
|
2016-02-17 01:54:10 +00:00
|
|
|
#
|
|
|
|
def merge_merge_request(merge_request, current_user)
|
2020-05-28 18:08:37 +00:00
|
|
|
resolve_todos_for_target(merge_request, current_user)
|
2016-02-17 01:54:10 +00:00
|
|
|
end
|
|
|
|
|
2016-03-08 18:22:50 +00:00
|
|
|
# When a build fails on the HEAD of a merge request we should:
|
|
|
|
#
|
2018-05-09 09:55:00 +00:00
|
|
|
# * create a todo for each merge participant
|
2016-03-08 18:22:50 +00:00
|
|
|
#
|
|
|
|
def merge_request_build_failed(merge_request)
|
2018-05-09 09:55:00 +00:00
|
|
|
merge_request.merge_participants.each do |user|
|
|
|
|
create_build_failed_todo(merge_request, user)
|
|
|
|
end
|
2016-03-08 18:22:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# When a new commit is pushed to a merge request we should:
|
|
|
|
#
|
|
|
|
# * mark all pending todos related to the merge request for that user as done
|
|
|
|
#
|
|
|
|
def merge_request_push(merge_request, current_user)
|
2020-05-28 18:08:37 +00:00
|
|
|
resolve_todos_for_target(merge_request, current_user)
|
2016-03-08 18:22:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# When a build is retried to a merge request we should:
|
|
|
|
#
|
2018-05-09 09:55:00 +00:00
|
|
|
# * mark all pending todos related to the merge request as done for each merge participant
|
2016-03-08 18:22:50 +00:00
|
|
|
#
|
|
|
|
def merge_request_build_retried(merge_request)
|
2018-05-09 09:55:00 +00:00
|
|
|
merge_request.merge_participants.each do |user|
|
2020-05-28 18:08:37 +00:00
|
|
|
resolve_todos_for_target(merge_request, user)
|
2018-05-09 09:55:00 +00:00
|
|
|
end
|
2016-03-08 18:22:50 +00:00
|
|
|
end
|
2017-03-28 06:25:43 +00:00
|
|
|
|
2018-05-09 09:55:00 +00:00
|
|
|
# When a merge request could not be merged due to its unmergeable state we should:
|
2016-12-14 14:37:31 +00:00
|
|
|
#
|
2018-05-09 09:55:00 +00:00
|
|
|
# * create a todo for each merge participant
|
2016-12-14 14:37:31 +00:00
|
|
|
#
|
|
|
|
def merge_request_became_unmergeable(merge_request)
|
2018-05-09 09:55:00 +00:00
|
|
|
merge_request.merge_participants.each do |user|
|
|
|
|
create_unmergeable_todo(merge_request, user)
|
|
|
|
end
|
2016-12-14 14:37:31 +00:00
|
|
|
end
|
2017-03-28 06:25:43 +00:00
|
|
|
|
2016-02-16 21:29:11 +00:00
|
|
|
# When create a note we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * mark all pending todos related to the noteable for the note author as done
|
|
|
|
# * create a todo for each mentioned user on note
|
2016-02-16 21:29:11 +00:00
|
|
|
#
|
2016-02-18 21:12:52 +00:00
|
|
|
def new_note(note, current_user)
|
|
|
|
handle_note(note, current_user)
|
2016-02-16 21:29:11 +00:00
|
|
|
end
|
|
|
|
|
2016-02-16 22:21:24 +00:00
|
|
|
# When update a note we should:
|
|
|
|
#
|
2016-02-20 13:59:59 +00:00
|
|
|
# * mark all pending todos related to the noteable for the current user as done
|
|
|
|
# * create a todo for each new user mentioned on note
|
2016-02-16 22:21:24 +00:00
|
|
|
#
|
2017-03-28 06:25:43 +00:00
|
|
|
def update_note(note, current_user, skip_users = [])
|
|
|
|
handle_note(note, current_user, skip_users)
|
2016-02-18 21:12:52 +00:00
|
|
|
end
|
|
|
|
|
2016-04-16 19:09:08 +00:00
|
|
|
# When an emoji is awarded we should:
|
|
|
|
#
|
|
|
|
# * mark all pending todos related to the awardable for the current user as done
|
|
|
|
#
|
|
|
|
def new_award_emoji(awardable, current_user)
|
2020-05-28 18:08:37 +00:00
|
|
|
resolve_todos_for_target(awardable, current_user)
|
2016-04-16 19:09:08 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 00:09:37 +00:00
|
|
|
# When user marks a target as todo
|
|
|
|
def mark_todo(target, current_user)
|
|
|
|
attributes = attributes_for_todo(target.project, target, current_user, Todo::MARKED)
|
2020-05-28 18:08:37 +00:00
|
|
|
create_todos(current_user, attributes)
|
2016-06-02 13:46:58 +00:00
|
|
|
end
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
def todo_exist?(issuable, current_user)
|
|
|
|
TodosFinder.new(current_user).any_for_target?(issuable, :pending)
|
2016-08-16 20:10:37 +00:00
|
|
|
end
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
# Resolves all todos related to target
|
|
|
|
def resolve_todos_for_target(target, current_user)
|
|
|
|
attributes = attributes_for_target(target)
|
2016-06-02 13:46:58 +00:00
|
|
|
|
2021-03-31 03:09:00 +00:00
|
|
|
resolve_todos(pending_todos([current_user], attributes), current_user)
|
2019-11-21 18:06:26 +00:00
|
|
|
end
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
def resolve_todos(todos, current_user, resolution: :done, resolved_by_action: :system_done)
|
|
|
|
todos_ids = todos.batch_update(state: resolution, resolved_by_action: resolved_by_action)
|
2019-12-03 18:06:49 +00:00
|
|
|
|
|
|
|
current_user.update_todos_count_cache
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
todos_ids
|
2017-01-16 13:11:08 +00:00
|
|
|
end
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
def resolve_todo(todo, current_user, resolution: :done, resolved_by_action: :system_done)
|
|
|
|
return if todo.done?
|
2016-02-18 21:12:52 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
todo.update(state: resolution, resolved_by_action: resolved_by_action)
|
2016-06-07 08:44:01 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
current_user.update_todos_count_cache
|
2016-08-11 17:00:06 +00:00
|
|
|
end
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
def restore_todos(todos, current_user)
|
|
|
|
todos_ids = todos.batch_update(state: :pending)
|
2016-02-18 21:12:52 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
current_user.update_todos_count_cache
|
|
|
|
|
|
|
|
todos_ids
|
2017-04-21 09:36:34 +00:00
|
|
|
end
|
2017-01-16 13:11:08 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
def restore_todo(todo, current_user)
|
|
|
|
return if todo.pending?
|
2018-09-20 15:05:26 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
todo.update(state: :pending)
|
2018-09-20 15:05:26 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
current_user.update_todos_count_cache
|
2017-01-16 13:11:08 +00:00
|
|
|
end
|
|
|
|
|
2021-02-02 12:10:15 +00:00
|
|
|
def create_request_review_todo(target, author, reviewers)
|
|
|
|
attributes = attributes_for_todo(target.project, target, author, Todo::REVIEW_REQUESTED)
|
|
|
|
create_todos(reviewers, attributes)
|
|
|
|
end
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
private
|
|
|
|
|
2016-03-16 23:31:30 +00:00
|
|
|
def create_todos(users, attributes)
|
2021-03-31 03:09:00 +00:00
|
|
|
users = Array(users)
|
2017-11-14 09:02:39 +00:00
|
|
|
|
2021-03-31 03:09:00 +00:00
|
|
|
return if users.empty?
|
|
|
|
|
2021-04-23 12:09:52 +00:00
|
|
|
users_with_pending_todos = pending_todos(users, attributes).distinct_user_ids
|
2021-03-31 03:09:00 +00:00
|
|
|
users.reject! { |user| users_with_pending_todos.include?(user.id) && Feature.disabled?(:multiple_todos, user) }
|
|
|
|
|
2021-04-19 12:09:04 +00:00
|
|
|
todos = users.map do |user|
|
2020-09-10 21:08:28 +00:00
|
|
|
issue_type = attributes.delete(:issue_type)
|
|
|
|
track_todo_creation(user, issue_type)
|
|
|
|
|
2021-04-19 12:09:04 +00:00
|
|
|
Todo.create(attributes.merge(user_id: user.id))
|
2016-02-18 21:12:52 +00:00
|
|
|
end
|
2021-04-19 12:09:04 +00:00
|
|
|
|
2021-04-23 12:09:52 +00:00
|
|
|
Users::UpdateTodoCountCacheService.new(users.map(&:id)).execute
|
2021-04-19 12:09:04 +00:00
|
|
|
|
|
|
|
todos
|
2016-02-18 21:12:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new_issuable(issuable, author)
|
2016-02-20 13:59:59 +00:00
|
|
|
create_assignment_todo(issuable, author)
|
2020-09-09 12:08:22 +00:00
|
|
|
create_reviewer_todo(issuable, author) if issuable.allows_reviewers?
|
2016-02-20 13:59:59 +00:00
|
|
|
create_mention_todos(issuable.project, issuable, author)
|
2016-02-18 21:12:52 +00:00
|
|
|
end
|
|
|
|
|
2017-03-28 06:25:43 +00:00
|
|
|
def update_issuable(issuable, author, skip_users = [])
|
2016-06-09 17:07:58 +00:00
|
|
|
# Skip toggling a task list item in a description
|
2016-06-17 14:34:11 +00:00
|
|
|
return if toggling_tasks?(issuable)
|
2016-06-09 17:07:58 +00:00
|
|
|
|
2017-03-28 06:25:43 +00:00
|
|
|
create_mention_todos(issuable.project, issuable, author, nil, skip_users)
|
2016-06-09 17:07:58 +00:00
|
|
|
end
|
|
|
|
|
2016-06-17 14:34:11 +00:00
|
|
|
def toggling_tasks?(issuable)
|
|
|
|
issuable.previous_changes.include?('description') &&
|
|
|
|
issuable.tasks? && issuable.updated_tasks.any?
|
|
|
|
end
|
|
|
|
|
2017-03-28 06:25:43 +00:00
|
|
|
def handle_note(note, author, skip_users = [])
|
2018-02-28 07:48:23 +00:00
|
|
|
return unless note.can_create_todo?
|
2016-02-17 22:04:14 +00:00
|
|
|
|
2016-02-18 19:26:52 +00:00
|
|
|
project = note.project
|
2020-05-28 18:08:37 +00:00
|
|
|
target = note.noteable
|
2016-02-17 22:04:14 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
resolve_todos_for_target(target, author)
|
2017-03-28 06:25:43 +00:00
|
|
|
create_mention_todos(project, target, author, note, skip_users)
|
2016-02-18 21:12:52 +00:00
|
|
|
end
|
2016-02-17 22:04:14 +00:00
|
|
|
|
2020-06-08 18:08:27 +00:00
|
|
|
def create_assignment_todo(target, author, old_assignees = [])
|
|
|
|
if target.assignees.any?
|
|
|
|
assignees = target.assignees - old_assignees
|
|
|
|
attributes = attributes_for_todo(target.project, target, author, Todo::ASSIGNED)
|
2017-10-04 16:24:23 +00:00
|
|
|
create_todos(assignees, attributes)
|
2016-02-16 22:21:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-09 12:08:22 +00:00
|
|
|
def create_reviewer_todo(target, author, old_reviewers = [])
|
|
|
|
if target.reviewers.any?
|
|
|
|
reviewers = target.reviewers - old_reviewers
|
2021-02-02 12:10:15 +00:00
|
|
|
create_request_review_todo(target, author, reviewers)
|
2020-09-09 12:08:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-16 13:35:19 +00:00
|
|
|
def create_mention_todos(parent, target, author, note = nil, skip_users = [])
|
2016-12-05 12:12:22 +00:00
|
|
|
# Create Todos for directly addressed users
|
2018-07-16 13:35:19 +00:00
|
|
|
directly_addressed_users = filter_directly_addressed_users(parent, note || target, author, skip_users)
|
|
|
|
attributes = attributes_for_todo(parent, target, author, Todo::DIRECTLY_ADDRESSED, note)
|
2016-12-05 12:12:22 +00:00
|
|
|
create_todos(directly_addressed_users, attributes)
|
|
|
|
|
|
|
|
# Create Todos for mentioned users
|
2020-12-23 03:10:22 +00:00
|
|
|
mentioned_users = filter_mentioned_users(parent, note || target, author, skip_users + directly_addressed_users)
|
2018-07-16 13:35:19 +00:00
|
|
|
attributes = attributes_for_todo(parent, target, author, Todo::MENTIONED, note)
|
2016-03-16 23:31:30 +00:00
|
|
|
create_todos(mentioned_users, attributes)
|
|
|
|
end
|
|
|
|
|
2016-12-12 21:55:33 +00:00
|
|
|
def create_build_failed_todo(merge_request, todo_author)
|
|
|
|
attributes = attributes_for_todo(merge_request.project, merge_request, todo_author, Todo::BUILD_FAILED)
|
|
|
|
create_todos(todo_author, attributes)
|
2016-03-08 18:22:50 +00:00
|
|
|
end
|
|
|
|
|
2018-05-09 09:55:00 +00:00
|
|
|
def create_unmergeable_todo(merge_request, todo_author)
|
|
|
|
attributes = attributes_for_todo(merge_request.project, merge_request, todo_author, Todo::UNMERGEABLE)
|
|
|
|
create_todos(todo_author, attributes)
|
2016-12-14 14:37:31 +00:00
|
|
|
end
|
|
|
|
|
2016-03-16 23:31:30 +00:00
|
|
|
def attributes_for_target(target)
|
|
|
|
attributes = {
|
2017-04-27 10:41:26 +00:00
|
|
|
project_id: target&.project&.id,
|
2016-03-16 23:31:30 +00:00
|
|
|
target_id: target.id,
|
|
|
|
target_type: target.class.name,
|
|
|
|
commit_id: nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if target.is_a?(Commit)
|
|
|
|
attributes.merge!(target_id: nil, commit_id: target.id)
|
2020-09-10 21:08:28 +00:00
|
|
|
elsif target.is_a?(Issue)
|
|
|
|
attributes[:issue_type] = target.issue_type
|
2021-06-14 21:10:22 +00:00
|
|
|
elsif target.is_a?(Discussion)
|
|
|
|
attributes.merge!(target_type: nil, target_id: nil, discussion: target)
|
2016-03-16 23:31:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
def attributes_for_todo(project, target, author, action, note = nil)
|
|
|
|
attributes_for_target(target).merge!(
|
2018-07-16 13:35:19 +00:00
|
|
|
project_id: project&.id,
|
2016-03-16 23:31:30 +00:00
|
|
|
author_id: author.id,
|
|
|
|
action: action,
|
|
|
|
note: note
|
|
|
|
)
|
2016-02-15 18:13:52 +00:00
|
|
|
end
|
2016-02-16 02:26:33 +00:00
|
|
|
|
2018-07-16 13:35:19 +00:00
|
|
|
def filter_todo_users(users, parent, target)
|
|
|
|
reject_users_without_access(users, parent, target).uniq
|
2016-12-05 12:12:22 +00:00
|
|
|
end
|
|
|
|
|
2018-07-16 13:35:19 +00:00
|
|
|
def filter_mentioned_users(parent, target, author, skip_users = [])
|
2017-03-28 06:25:43 +00:00
|
|
|
mentioned_users = target.mentioned_users(author) - skip_users
|
2018-07-16 13:35:19 +00:00
|
|
|
filter_todo_users(mentioned_users, parent, target)
|
2016-12-05 12:12:22 +00:00
|
|
|
end
|
|
|
|
|
2018-07-16 13:35:19 +00:00
|
|
|
def filter_directly_addressed_users(parent, target, author, skip_users = [])
|
2017-03-28 06:25:43 +00:00
|
|
|
directly_addressed_users = target.directly_addressed_users(author) - skip_users
|
2018-07-16 13:35:19 +00:00
|
|
|
filter_todo_users(directly_addressed_users, parent, target)
|
2016-02-17 17:46:26 +00:00
|
|
|
end
|
|
|
|
|
2018-07-16 13:35:19 +00:00
|
|
|
def reject_users_without_access(users, parent, target)
|
2019-08-22 15:05:07 +00:00
|
|
|
target = target.noteable if target.is_a?(Note)
|
2016-03-30 21:41:21 +00:00
|
|
|
|
2019-08-22 15:05:07 +00:00
|
|
|
if target.respond_to?(:to_ability_name)
|
2016-10-04 12:52:08 +00:00
|
|
|
select_users(users, :"read_#{target.to_ability_name}", target)
|
2016-03-30 21:41:21 +00:00
|
|
|
else
|
2018-07-16 13:35:19 +00:00
|
|
|
select_users(users, :read_project, parent)
|
2016-03-30 21:41:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def select_users(users, ability, subject)
|
|
|
|
users.select do |user|
|
|
|
|
user.can?(ability.to_sym, subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-31 03:09:00 +00:00
|
|
|
def pending_todos(users, criteria = {})
|
|
|
|
PendingTodosFinder.new(users, criteria).execute
|
2016-02-16 23:01:14 +00:00
|
|
|
end
|
2020-09-10 21:08:28 +00:00
|
|
|
|
|
|
|
def track_todo_creation(user, issue_type)
|
|
|
|
return unless issue_type == 'incident'
|
|
|
|
|
2020-09-18 03:09:28 +00:00
|
|
|
track_usage_event(:incident_management_incident_todo, user.id)
|
2020-09-10 21:08:28 +00:00
|
|
|
end
|
2016-02-15 18:13:52 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
TodoService.prepend_mod_with('TodoService')
|