Commit 8653c2df authored by Shinya Maeda's avatar Shinya Maeda

Add constant as ALLOWED_INDEXED_COLUMNS

parent 0a36bfa9
class PipelinesFinder class PipelinesFinder
attr_reader :project, :pipelines, :params attr_reader :project, :pipelines, :params
ALLOWED_INDEXED_COLUMNS = %w[id status ref user_id].freeze
def initialize(project, params = {}) def initialize(project, params = {})
@project = project @project = project
@pipelines = project.pipelines @pipelines = project.pipelines
...@@ -95,7 +97,7 @@ class PipelinesFinder ...@@ -95,7 +97,7 @@ class PipelinesFinder
end end
def sort_items(items) def sort_items(items)
order_by = if %w[id status ref user_id].include?(params[:order_by]) # Allow only indexed columns order_by = if ALLOWED_INDEXED_COLUMNS.include?(params[:order_by])
params[:order_by] params[:order_by]
else else
:id :id
......
...@@ -22,7 +22,7 @@ module API ...@@ -22,7 +22,7 @@ module API
optional :yaml_errors, type: Boolean, desc: 'If true, returns only yaml error pipelines' optional :yaml_errors, type: Boolean, desc: 'If true, returns only yaml error pipelines'
optional :name, type: String, desc: 'The name of user who triggered pipelines' optional :name, type: String, desc: 'The name of user who triggered pipelines'
optional :username, type: String, desc: 'The username of user who triggered pipelines' optional :username, type: String, desc: 'The username of user who triggered pipelines'
optional :order_by, type: String, values: %w[id status ref user_id], default: 'id', optional :order_by, type: String, values: PipelinesFinder::ALLOWED_INDEXED_COLUMNS, default: 'id',
desc: 'The order_by which is combined with a sort' desc: 'The order_by which is combined with a sort'
optional :sort, type: String, values: %w[asc desc], default: 'desc', optional :sort, type: String, values: %w[asc desc], default: 'desc',
desc: 'The sort method which is combined with an order_by' desc: 'The sort method which is combined with an order_by'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment