/app/services/boards/issues/list_service.rb

https://gitlab.com/jamedjo/gitlab-ce · Ruby · 73 lines · 58 code · 15 blank · 0 comment · 5 complexity · be3644c242aeff5e531f26e502c18784 MD5 · raw file

  1. module Boards
  2. module Issues
  3. class ListService < BaseService
  4. def execute
  5. issues = IssuesFinder.new(current_user, filter_params).execute
  6. issues = without_board_labels(issues) unless movable_list?
  7. issues = with_list_label(issues) if movable_list?
  8. issues
  9. end
  10. private
  11. def board
  12. @board ||= project.boards.find(params[:board_id])
  13. end
  14. def list
  15. return @list if defined?(@list)
  16. @list = board.lists.find(params[:id]) if params.key?(:id)
  17. end
  18. def movable_list?
  19. @movable_list ||= list.present? && list.movable?
  20. end
  21. def filter_params
  22. set_default_scope
  23. set_default_sort
  24. set_project
  25. set_state
  26. params
  27. end
  28. def set_default_scope
  29. params[:scope] = 'all'
  30. end
  31. def set_default_sort
  32. params[:sort] = 'priority'
  33. end
  34. def set_project
  35. params[:project_id] = project.id
  36. end
  37. def set_state
  38. params[:state] = list && list.done? ? 'closed' : 'opened'
  39. end
  40. def board_label_ids
  41. @board_label_ids ||= board.lists.movable.pluck(:label_id)
  42. end
  43. def without_board_labels(issues)
  44. return issues unless board_label_ids.any?
  45. issues.where.not(
  46. LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
  47. .where(label_id: board_label_ids).limit(1).arel.exists
  48. )
  49. end
  50. def with_list_label(issues)
  51. issues.where(
  52. LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
  53. .where("label_links.label_id = ?", list.label_id).limit(1).arel.exists
  54. )
  55. end
  56. end
  57. end
  58. end