Class: TodoService

Inherits:
Object
  • Object
show all
Defined in:
app/services/todo_service.rb

Overview

TodoService class

Used for creating todos after certain user actions

Ex.

TodoService.new.new_issue(issue, current_user)

Instance Method Summary collapse

Instance Method Details

#close_issue(issue, current_user) ⇒ Object

When close an issue we should:

* mark all pending todos related to the target for the current user as done

30
31
32
# File 'app/services/todo_service.rb', line 30

def close_issue(issue, current_user)
  mark_pending_todos_as_done(issue, current_user)
end

#close_merge_request(merge_request, current_user) ⇒ Object

When close a merge request we should:

* mark all pending todos related to the target for the current user as done

63
64
65
# File 'app/services/todo_service.rb', line 63

def close_merge_request(merge_request, current_user)
  mark_pending_todos_as_done(merge_request, current_user)
end

#mark_pending_todos_as_done(target, user) ⇒ Object

When marking pending todos as done we should:

* mark all pending todos related to the target for the current user as done

105
106
107
108
# File 'app/services/todo_service.rb', line 105

def mark_pending_todos_as_done(target, user)
  attributes = attributes_for_target(target)
  pending_todos(user, attributes).update_all(state: :done)
end

#merge_merge_request(merge_request, current_user) ⇒ Object

When merge a merge request we should:

* mark all pending todos related to the target for the current user as done

79
80
81
# File 'app/services/todo_service.rb', line 79

def merge_merge_request(merge_request, current_user)
  mark_pending_todos_as_done(merge_request, current_user)
end

#new_issue(issue, current_user) ⇒ Object

When create an issue we should:

* create a todo for assignee if issue is assigned
* create a todo for each mentioned user on issue

14
15
16
# File 'app/services/todo_service.rb', line 14

def new_issue(issue, current_user)
  new_issuable(issue, current_user)
end

#new_merge_request(merge_request, current_user) ⇒ Object

When create a merge request we should:

* creates a pending todo for assignee if merge request is assigned
* create a todo for each mentioned user on merge request

47
48
49
# File 'app/services/todo_service.rb', line 47

def new_merge_request(merge_request, current_user)
  new_issuable(merge_request, current_user)
end

#new_note(note, current_user) ⇒ Object

When create a note we should:

* mark all pending todos related to the noteable for the note author as done
* create a todo for each mentioned user on note

88
89
90
# File 'app/services/todo_service.rb', line 88

def new_note(note, current_user)
  handle_note(note, current_user)
end

#reassigned_issue(issue, current_user) ⇒ Object

When we reassign an issue we should:

* create a pending todo for new assignee if issue is assigned

38
39
40
# File 'app/services/todo_service.rb', line 38

def reassigned_issue(issue, current_user)
  create_assignment_todo(issue, current_user)
end

#reassigned_merge_request(merge_request, current_user) ⇒ Object

When we reassign a merge request we should:

* creates a pending todo for new assignee if merge request is assigned

71
72
73
# File 'app/services/todo_service.rb', line 71

def reassigned_merge_request(merge_request, current_user)
  create_assignment_todo(merge_request, current_user)
end

#update_issue(issue, current_user) ⇒ Object

When update an issue we should:

* mark all pending todos related to the issue for the current user as done

22
23
24
# File 'app/services/todo_service.rb', line 22

def update_issue(issue, current_user)
  create_mention_todos(issue.project, issue, current_user)
end

#update_merge_request(merge_request, current_user) ⇒ Object

When update a merge request we should:

* create a todo for each mentioned user on merge request

55
56
57
# File 'app/services/todo_service.rb', line 55

def update_merge_request(merge_request, current_user)
  create_mention_todos(merge_request.project, merge_request, current_user)
end

#update_note(note, current_user) ⇒ Object

When update a note we should:

* mark all pending todos related to the noteable for the current user as done
* create a todo for each new user mentioned on note

97
98
99
# File 'app/services/todo_service.rb', line 97

def update_note(note, current_user)
  handle_note(note, current_user)
end