Commit e0f0c29b authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Support lowercase none / any

parent bf1ed85a
...@@ -35,8 +35,8 @@ class IssuableFinder ...@@ -35,8 +35,8 @@ class IssuableFinder
requires_cross_project_access unless: -> { project? } requires_cross_project_access unless: -> { project? }
# This is used as a common filter for None / Any # This is used as a common filter for None / Any
FILTER_NONE = 'None'.freeze FILTER_NONE = 'none'.freeze
FILTER_ANY = 'Any'.freeze FILTER_ANY = 'any'.freeze
# This is accepted as a deprecated filter and is also used in unassigning users # This is accepted as a deprecated filter and is also used in unassigning users
NONE = '0'.freeze NONE = '0'.freeze
...@@ -250,11 +250,11 @@ class IssuableFinder ...@@ -250,11 +250,11 @@ class IssuableFinder
def filter_by_no_assignee? def filter_by_no_assignee?
# Assignee_id takes precedence over assignee_username # Assignee_id takes precedence over assignee_username
[NONE, FILTER_NONE].include?(params[:assignee_id].to_s) || params[:assignee_username].to_s == NONE [NONE, FILTER_NONE].include?(params[:assignee_id].to_s.downcase) || params[:assignee_username].to_s == NONE
end end
def filter_by_any_assignee? def filter_by_any_assignee?
params[:assignee_id].to_s == FILTER_ANY params[:assignee_id].to_s.downcase == FILTER_ANY
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -16,7 +16,7 @@ module API ...@@ -16,7 +16,7 @@ module API
value = params[attr_name] value = params[attr_name]
return if value.is_a?(Integer) || return if value.is_a?(Integer) ||
[IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value) [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase)
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
message: "should be an integer, 'None' or 'Any'" message: "should be an integer, 'None' or 'Any'"
......
...@@ -57,17 +57,21 @@ describe IssuesFinder do ...@@ -57,17 +57,21 @@ describe IssuesFinder do
end end
context 'filtering by no assignee' do context 'filtering by no assignee' do
let(:params) { { assignee_id: 0 } } let(:params) { { assignee_id: 'None' } }
it 'returns issues not assigned to any assignee' do it 'returns issues not assigned to any assignee' do
expect(issues).to contain_exactly(issue4) expect(issues).to contain_exactly(issue4)
end end
end
context 'filtering by no assignee' do it 'returns issues not assigned to any assignee' do
let(:params) { { assignee_id: 'None' } } params[:assignee_id] = 0
expect(issues).to contain_exactly(issue4)
end
it 'returns issues not assigned to any assignee' do it 'returns issues not assigned to any assignee' do
params[:assignee_id] = 'none'
expect(issues).to contain_exactly(issue4) expect(issues).to contain_exactly(issue4)
end end
end end
...@@ -78,6 +82,12 @@ describe IssuesFinder do ...@@ -78,6 +82,12 @@ describe IssuesFinder do
it 'returns issues assigned to any assignee' do it 'returns issues assigned to any assignee' do
expect(issues).to contain_exactly(issue1, issue2, issue3) expect(issues).to contain_exactly(issue1, issue2, issue3)
end end
it 'returns issues assigned to any assignee' do
params[:assignee_id] = 'any'
expect(issues).to contain_exactly(issue1, issue2, issue3)
end
end end
context 'filtering by group_id' do context 'filtering by group_id' do
......
...@@ -38,6 +38,8 @@ describe API::Helpers::CustomValidators do ...@@ -38,6 +38,8 @@ describe API::Helpers::CustomValidators do
expect_no_validation_error({ 'test' => 100 }) expect_no_validation_error({ 'test' => 100 })
expect_no_validation_error({ 'test' => 'None' }) expect_no_validation_error({ 'test' => 'None' })
expect_no_validation_error({ 'test' => 'Any' }) expect_no_validation_error({ 'test' => 'Any' })
expect_no_validation_error({ 'test' => 'none' })
expect_no_validation_error({ 'test' => 'any' })
end end
end end
......
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