2021-10-27 15:23:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ErrorTracking
|
|
|
|
class ErrorsFinder
|
|
|
|
def initialize(current_user, project, params)
|
|
|
|
@current_user = current_user
|
|
|
|
@project = project
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return ErrorTracking::Error.none unless authorized?
|
|
|
|
|
|
|
|
collection = project.error_tracking_errors
|
|
|
|
collection = by_status(collection)
|
2021-11-11 11:23:49 +05:30
|
|
|
collection = sort(collection)
|
2021-10-27 15:23:28 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
collection.keyset_paginate(cursor: params[:cursor], per_page: limit)
|
2021-10-27 15:23:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :current_user, :project, :params
|
|
|
|
|
|
|
|
def by_status(collection)
|
|
|
|
if params[:status].present? && ErrorTracking::Error.statuses.key?(params[:status])
|
|
|
|
collection.for_status(params[:status])
|
|
|
|
else
|
|
|
|
collection
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized?
|
|
|
|
Ability.allowed?(current_user, :read_sentry_issue, project)
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
def sort(collection)
|
|
|
|
params[:sort] ? collection.sort_by_attribute(params[:sort]) : collection.order_id_desc
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
def limit
|
2021-11-11 11:23:49 +05:30
|
|
|
# Restrict the maximum limit at 100 records.
|
2021-11-18 22:05:49 +05:30
|
|
|
[(params[:limit] || 20).to_i, 100].min
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
end
|
|
|
|
end
|