Class: IssuableFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/issuable_finder.rb

Direct Known Subclasses

IssuesFinder, MergeRequestsFinder

Constant Summary collapse

NONE =
'0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, params) ⇒ IssuableFinder

Returns a new instance of IssuableFinder


26
27
28
29
# File 'app/finders/issuable_finder.rb', line 26

def initialize(current_user, params)
  @current_user = current_user
  @params = params
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user


24
25
26
# File 'app/finders/issuable_finder.rb', line 24

def current_user
  @current_user
end

#paramsObject

Returns the value of attribute params


24
25
26
# File 'app/finders/issuable_finder.rb', line 24

def params
  @params
end

Instance Method Details

#assigneeObject


142
143
144
145
146
147
148
149
150
151
# File 'app/finders/issuable_finder.rb', line 142

def assignee
  return @assignee if defined?(@assignee)

  @assignee =
    if assignee? && params[:assignee_id] != NONE
      User.find(params[:assignee_id])
    else
      nil
    end
end

#assignee?Boolean

Returns:

  • (Boolean)

138
139
140
# File 'app/finders/issuable_finder.rb', line 138

def assignee?
  params[:assignee_id].present?
end

#authorObject


157
158
159
160
161
162
163
164
165
166
# File 'app/finders/issuable_finder.rb', line 157

def author
  return @author if defined?(@author)

  @author =
    if author? && params[:author_id] != NONE
      User.find(params[:author_id])
    else
      nil
    end
end

#author?Boolean

Returns:

  • (Boolean)

153
154
155
# File 'app/finders/issuable_finder.rb', line 153

def author?
  params[:author_id].present?
end

#executeObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/finders/issuable_finder.rb', line 31

def execute
  items = init_collection
  items = by_scope(items)
  items = by_state(items)
  items = by_group(items)
  items = by_project(items)
  items = by_search(items)
  items = by_milestone(items)
  items = by_assignee(items)
  items = by_author(items)
  items = by_label(items)
  items = by_due_date(items)
  sort(items)
end

#filter_by_no_label?Boolean

Returns:

  • (Boolean)

120
121
122
# File 'app/finders/issuable_finder.rb', line 120

def filter_by_no_label?
  labels? && params[:label_name].include?(Label::None.title)
end

#filter_by_no_milestone?Boolean

Returns:

  • (Boolean)

99
100
101
# File 'app/finders/issuable_finder.rb', line 99

def filter_by_no_milestone?
  milestones? && params[:milestone_title] == Milestone::None.title
end

#groupObject


46
47
48
49
50
51
52
53
54
55
# File 'app/finders/issuable_finder.rb', line 46

def group
  return @group if defined?(@group)

  @group =
    if params[:group_id].present?
      Group.find(params[:group_id])
    else
      nil
    end
end

#labelsObject


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/finders/issuable_finder.rb', line 124

def labels
  return @labels if defined?(@labels)

  if labels? && !filter_by_no_label?
    @labels = Label.where(title: label_names)

    if projects
      @labels = @labels.where(project: projects)
    end
  else
    @labels = Label.none
  end
end

#labels?Boolean

Returns:

  • (Boolean)

116
117
118
# File 'app/finders/issuable_finder.rb', line 116

def labels?
  params[:label_name].present?
end

#milestonesObject


103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/finders/issuable_finder.rb', line 103

def milestones
  return @milestones if defined?(@milestones)

  @milestones =
    if milestones?
      scope = Milestone.where(project_id: projects)

      scope.where(title: params[:milestone_title])
    else
      nil
    end
end

#milestones?Boolean

Returns:

  • (Boolean)

95
96
97
# File 'app/finders/issuable_finder.rb', line 95

def milestones?
  params[:milestone_title].present?
end

#projectObject


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/finders/issuable_finder.rb', line 61

def project
  return @project if defined?(@project)

  if project?
    @project = Project.find(params[:project_id])

    unless Ability.abilities.allowed?(current_user, :read_project, @project)
      @project = nil
    end
  else
    @project = nil
  end

  @project
end

#project?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'app/finders/issuable_finder.rb', line 57

def project?
  params[:project_id].present?
end

#projectsObject


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/finders/issuable_finder.rb', line 77

def projects
  return @projects if defined?(@projects)

  if project?
    @projects = project
  elsif current_user && params[:authorized_only].presence && !current_user_related?
    @projects = current_user.authorized_projects.reorder(nil)
  elsif group
    @projects = GroupProjectsFinder.new(group).execute(current_user).reorder(nil)
  else
    @projects = ProjectsFinder.new.execute(current_user).reorder(nil)
  end
end

#searchObject


91
92
93
# File 'app/finders/issuable_finder.rb', line 91

def search
  params[:search].presence
end