Class: API::Entities::Todo

Inherits:
Grape::Entity
  • Object
show all
Defined in:
lib/api/entities/todo.rb

Instance Method Summary collapse

Instance Method Details

#design_todo_target_url(todo) ⇒ Object


48
49
50
51
52
53
54
55
56
# File 'lib/api/entities/todo.rb', line 48

def design_todo_target_url(todo)
  design = todo.target
  path_options = {
    anchor: todo_target_anchor(todo),
    vueroute: design.filename
  }

  ::Gitlab::Routing.url_helpers.designs_project_issue_url(design.project, design.issue, path_options)
end

#todo_target_anchor(todo) ⇒ Object


44
45
46
# File 'lib/api/entities/todo.rb', line 44

def todo_target_anchor(todo)
  "note_#{todo.note_id}" if todo.note_id?
end

#todo_target_class(target_type) ⇒ Object


27
28
29
30
31
# File 'lib/api/entities/todo.rb', line 27

def todo_target_class(target_type)
  # false as second argument prevents looking up in module hierarchy
  # see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
  ::API::Entities.const_get(target_type, false)
end

#todo_target_url(todo) ⇒ Object


33
34
35
36
37
38
39
40
41
42
# File 'lib/api/entities/todo.rb', line 33

def todo_target_url(todo)
  return design_todo_target_url(todo) if todo.for_design?

  target_type = todo.target_type.underscore
  target_url = "#{todo.resource_parent.class.to_s.underscore}_#{target_type}_url"

  Gitlab::Routing
    .url_helpers
    .public_send(target_url, todo.resource_parent, todo.target, anchor: todo_target_anchor(todo)) # rubocop:disable GitlabSecurity/PublicSend
end