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

60 lines
1.4 KiB
Ruby
Raw Normal View History

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:
# scope: 'created-by-me' or 'assigned-to-me' or 'all'
# state: 'open' or 'closed' or 'all'
# group_id: integer
# project_id: integer
2017-08-17 22:00:37 +05:30
# milestone_title: string
2014-09-02 18:07:02 +05:30
# assignee_id: integer
# search: string
# label_name: string
# sort: string
#
2015-04-26 12:48:37 +05:30
class IssuesFinder < IssuableFinder
2014-09-02 18:07:02 +05:30
def klass
Issue
end
2016-06-02 11:05:42 +05:30
private
def init_collection
2017-01-15 13:20:01 +05:30
IssuesFinder.not_restricted_by_confidentiality(current_user)
2016-06-02 11:05:42 +05:30
end
2016-09-29 09:46:39 +05:30
2017-08-17 22:00:37 +05:30
def by_assignee(items)
if assignee
items.assigned_to(assignee)
elsif no_assignee?
items.unassigned
elsif assignee_id? || assignee_username? # assignee not found
items.none
else
items
end
2016-09-29 09:46:39 +05:30
end
2017-01-15 13:20:01 +05:30
def self.not_restricted_by_confidentiality(user)
2017-08-17 22:00:37 +05:30
return Issue.where('issues.confidential IS NOT TRUE') if user.blank?
2017-01-15 13:20:01 +05:30
return Issue.all if user.admin?
Issue.where('
2017-08-17 22:00:37 +05:30
issues.confidential IS NOT TRUE
2017-01-15 13:20:01 +05:30
OR (issues.confidential = TRUE
AND (issues.author_id = :user_id
2017-08-17 22:00:37 +05:30
OR EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = :user_id AND issue_id = issues.id)
2017-01-15 13:20:01 +05:30
OR issues.project_id IN(:project_ids)))',
user_id: user.id,
project_ids: user.authorized_projects(Gitlab::Access::REPORTER).select(:id))
end
2017-08-17 22:00:37 +05:30
def item_project_ids(items)
items&.reorder(nil)&.select(:project_id)
end
2014-09-02 18:07:02 +05:30
end