Class: IssuesFinder

Inherits:
IssuableFinder show all
Defined in:
app/finders/issues_finder.rb,
app/finders/issues_finder/params.rb

Overview

Finders::Issues class

Used to filter Issues collections by set of params

Arguments:

current_user - which user use
params:
  scope: 'created_by_me' or 'assigned_to_me' or 'all'
  state: 'opened' or 'closed' or 'all'
  group_id: integer
  project_id: integer
  milestone_title: string (cannot be simultaneously used with milestone_wildcard_id)
  milestone_wildcard_id: 'none', 'any', 'upcoming', 'started' (cannot be simultaneously used with milestone_title)
  assignee_id: integer
  search: string
  in: 'title', 'description', or a string joining them with comma
  label_name: string
  sort: string
  my_reaction_emoji: string
  public_only: boolean
  due_date: date or '0', '', 'overdue', 'week', or 'month'
  created_after: datetime
  created_before: datetime
  updated_after: datetime
  updated_before: datetime
  confidential: boolean
  issue_types: array of strings (one of WorkItems::Type.base_types)

Direct Known Subclasses

WorkItems::WorkItemsFinder

Defined Under Namespace

Classes: Params

Constant Summary collapse

CONFIDENTIAL_ACCESS_LEVEL =
Gitlab::Access::REPORTER

Constants inherited from IssuableFinder

IssuableFinder::FULL_TEXT_SEARCH_TERM_REGEX, IssuableFinder::NEGATABLE_PARAMS_HELPER_KEYS

Instance Attribute Summary

Attributes inherited from IssuableFinder

#current_user, #original_params, #params

Attributes included from FinderWithCrossProjectAccess

#should_skip_cross_project_check

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IssuableFinder

array_params, #count_by_state, #execute, #initialize, negatable_array_params, negatable_params, negatable_scalar_params, #parent_param, #parent_param=, #row_count, #search, #should_filter_negated_args?, #use_cte_for_search?, valid_params

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from CreatedAtFilter

#by_created_at

Methods included from FinderMethods

#find, #find_by, #find_by!

Methods included from FinderWithCrossProjectAccess

#can_read_cross_project?, #can_read_project?, #execute, #find, #find_by, #find_by!, #skip_cross_project_check

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Constructor Details

This class inherits a constructor from IssuableFinder

Class Method Details

.scalar_paramsObject


34
35
36
# File 'app/finders/issues_finder.rb', line 34

def self.scalar_params
  @scalar_params ||= super + [:due_date]
end

Instance Method Details

#klassObject

rubocop: disable CodeReuse/ActiveRecord


39
40
41
# File 'app/finders/issues_finder.rb', line 39

def klass
  model_class.includes(:author)
end

#params_classObject

rubocop: enable CodeReuse/ActiveRecord


44
45
46
# File 'app/finders/issues_finder.rb', line 44

def params_class
  self.class.const_get(:Params, false)
end

#with_confidentiality_access_checkObject

rubocop: disable CodeReuse/ActiveRecord


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/finders/issues_finder.rb', line 49

def with_confidentiality_access_check
  return model_class.all if params.user_can_see_all_issues?

  # Only admins can see hidden issues, so for non-admins, we filter out any hidden issues
  issues = model_class.without_hidden

  return issues.all if params.user_can_see_all_confidential_issues?

  # If already filtering by assignee we can skip confidentiality since a user
  # can always see confidential issues assigned to them. This is just an
  # optimization since a very common usecase of this Finder is to load the
  # count of issues assigned to the user for the header bar.
  return issues.all if current_user && assignee_filter.includes_user?(current_user)

  return issues.where('issues.confidential IS NOT TRUE') if params.user_cannot_see_confidential_issues?

  issues.where('
    issues.confidential IS NOT TRUE
    OR (issues.confidential = TRUE
      AND (issues.author_id = :user_id
        OR EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = :user_id AND issue_id = issues.id)
        OR EXISTS (:authorizations)))',
    user_id: current_user.id,
    authorizations: current_user.authorizations_for_projects(min_access_level: CONFIDENTIAL_ACCESS_LEVEL, related_project_column: "issues.project_id"))
end