debian-mirror-gitlab/app/finders/issues_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

162 lines
5.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
# Finders::Issues class
#
# Used to filter Issues collections by set of params
#
# Arguments:
# current_user - which user use
# params:
2018-11-08 19:23:39 +05:30
# scope: 'created_by_me' or 'assigned_to_me' or 'all'
2020-11-24 15:15:51 +05:30
# state: 'opened' or 'closed' or 'all'
2014-09-02 18:07:02 +05:30
# group_id: integer
# project_id: integer
2021-10-27 15:23:28 +05:30
# 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)
2014-09-02 18:07:02 +05:30
# assignee_id: integer
# search: string
2019-03-02 22:35:43 +05:30
# in: 'title', 'description', or a string joining them with comma
2014-09-02 18:07:02 +05:30
# label_name: string
# sort: string
2018-03-17 18:26:18 +05:30
# my_reaction_emoji: string
# public_only: boolean
2018-03-27 19:54:05 +05:30
# due_date: date or '0', '', 'overdue', 'week', or 'month'
# created_after: datetime
# created_before: datetime
# updated_after: datetime
# updated_before: datetime
2020-07-28 23:09:34 +05:30
# confidential: boolean
2022-03-02 08:16:31 +05:30
# issue_types: array of strings (one of WorkItems::Type.base_types)
2014-09-02 18:07:02 +05:30
#
2015-04-26 12:48:37 +05:30
class IssuesFinder < IssuableFinder
2023-01-13 00:05:48 +05:30
extend ::Gitlab::Utils::Override
2017-09-10 17:25:29 +05:30
CONFIDENTIAL_ACCESS_LEVEL = Gitlab::Access::REPORTER
2018-03-27 19:54:05 +05:30
def self.scalar_params
@scalar_params ||= super + [:due_date]
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
def klass
2022-07-23 23:45:48 +05:30
model_class.includes(:author)
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-06-02 11:05:42 +05:30
2020-04-22 19:07:51 +05:30
def params_class
2020-11-24 15:15:51 +05:30
self.class.const_get(:Params, false)
2020-04-22 19:07:51 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
def with_confidentiality_access_check
2023-03-17 16:20:25 +05:30
return model_class.all if params.user_can_see_all_issuables?
2022-07-16 23:28:13 +05:30
2021-10-27 15:23:28 +05:30
# Only admins can see hidden issues, so for non-admins, we filter out any hidden issues
2022-07-23 23:45:48 +05:30
issues = model_class.without_hidden
2021-10-27 15:23:28 +05:30
return issues.all if params.user_can_see_all_confidential_issues?
2021-04-29 21:17:54 +05:30
# 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.
2021-10-27 15:23:28 +05:30
return issues.all if current_user && assignee_filter.includes_user?(current_user)
2021-04-29 21:17:54 +05:30
2022-10-11 01:57:18 +05:30
return issues.public_only if params.user_cannot_see_confidential_issues?
2017-09-10 17:25:29 +05:30
2021-10-27 15:23:28 +05:30
issues.where('
2022-10-11 01:57:18 +05:30
issues.confidential = FALSE
2017-09-10 17:25:29 +05:30
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)
2019-07-07 11:18:12 +05:30
OR EXISTS (:authorizations)))',
2017-09-10 17:25:29 +05:30
user_id: current_user.id,
2019-07-07 11:18:12 +05:30
authorizations: current_user.authorizations_for_projects(min_access_level: CONFIDENTIAL_ACCESS_LEVEL, related_project_column: "issues.project_id"))
2017-09-10 17:25:29 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
2016-06-02 11:05:42 +05:30
private
def init_collection
2022-07-16 23:28:13 +05:30
if params.public_only?
2022-07-23 23:45:48 +05:30
model_class.public_only
2018-03-17 18:26:18 +05:30
else
with_confidentiality_access_check
end
end
2018-03-27 19:54:05 +05:30
def filter_items(items)
2019-07-07 11:18:12 +05:30
issues = super
issues = by_due_date(issues)
issues = by_confidential(issues)
2021-04-29 21:17:54 +05:30
by_issue_types(issues)
2019-07-07 11:18:12 +05:30
end
2021-11-18 22:05:49 +05:30
# Negates all params found in `negatable_params`
def filter_negated_items(items)
issues = super
by_negated_issue_types(issues)
end
2023-01-13 00:05:48 +05:30
override :filter_by_full_text_search
def filter_by_full_text_search(items)
# This project condition is used as a hint to PG about the partitions that need searching
# because the search data is partitioned by project.
# In certain cases, like the recent items search, the query plan is much better without this condition.
return super if params[:skip_full_text_search_project_condition].present?
super.with_projects_matching_search_data
end
2019-07-07 11:18:12 +05:30
def by_confidential(items)
return items if params[:confidential].nil?
params[:confidential] ? items.confidential_only : items.public_only
2018-03-27 19:54:05 +05:30
end
def by_due_date(items)
2020-04-22 19:07:51 +05:30
return items unless params.due_date?
if params.filter_by_no_due_date?
items.without_due_date
2022-04-04 11:22:00 +05:30
elsif params.filter_by_any_due_date?
items.with_due_date
2020-04-22 19:07:51 +05:30
elsif params.filter_by_overdue?
items.due_before(Date.today)
2022-04-04 11:22:00 +05:30
elsif params.filter_by_due_today?
items.due_today
elsif params.filter_by_due_tomorrow?
items.due_tomorrow
2020-04-22 19:07:51 +05:30
elsif params.filter_by_due_this_week?
items.due_between(Date.today.beginning_of_week, Date.today.end_of_week)
elsif params.filter_by_due_this_month?
items.due_between(Date.today.beginning_of_month, Date.today.end_of_month)
elsif params.filter_by_due_next_month_and_previous_two_weeks?
items.due_between(Date.today - 2.weeks, (Date.today + 1.month).end_of_month)
2021-01-29 00:20:46 +05:30
else
items.none
2018-03-27 19:54:05 +05:30
end
2016-06-02 11:05:42 +05:30
end
2020-10-24 23:57:45 +05:30
def by_issue_types(items)
issue_type_params = Array(params[:issue_types]).map(&:to_s)
return items if issue_type_params.blank?
2022-07-23 23:45:48 +05:30
return model_class.none unless (WorkItems::Type.base_types.keys & issue_type_params).sort == issue_type_params.sort
2020-10-24 23:57:45 +05:30
items.with_issue_type(params[:issue_types])
end
2021-11-18 22:05:49 +05:30
def by_negated_issue_types(items)
2022-03-02 08:16:31 +05:30
issue_type_params = Array(not_params[:issue_types]).map(&:to_s) & WorkItems::Type.base_types.keys
2021-11-18 22:05:49 +05:30
return items if issue_type_params.blank?
items.without_issue_type(issue_type_params)
end
2022-07-23 23:45:48 +05:30
def model_class
Issue
end
2014-09-02 18:07:02 +05:30
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
IssuesFinder.prepend_mod_with('IssuesFinder')