make user and org lookup by login case insensitive
This commit is contained in:
parent
92864ed007
commit
d9f5e1e736
|
@ -50,7 +50,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-core.git
|
||||
revision: 4834399048b8c9cff4882d435f770826930665f6
|
||||
revision: 48366d360d910ea038850249e1361f831b3dc6dd
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
actionmailer (~> 3.2.19)
|
||||
|
|
|
@ -7,7 +7,6 @@ module Travis::API::V3
|
|||
has_many :repositories, through: :permissions
|
||||
has_many :organizations, through: :memberships
|
||||
|
||||
|
||||
serialize :github_oauth_token, Extensions::EncryptedColumn.new(disable: true)
|
||||
|
||||
def token
|
||||
|
|
|
@ -3,8 +3,8 @@ module Travis::API::V3
|
|||
params :id, :login
|
||||
|
||||
def find
|
||||
return Models::Organization.find_by_id(id) if id
|
||||
return Models::Organization.find_by_login(login) if login
|
||||
return Models::Organization.find_by_id(id) if id
|
||||
return Models::Organization.where('lower(login) = ?'.freeze, login.downcase).first if login
|
||||
raise WrongParams, 'missing organization.id or organization.login'.freeze
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ module Travis::API::V3
|
|||
params :id, :login
|
||||
|
||||
def find
|
||||
return Models::User.find_by_id(id) if id
|
||||
return Models::User.find_by_login(login) if login
|
||||
return Models::User.find_by_id(id) if id
|
||||
return Models::User.where('lower(login) = ?'.freeze, login.downcase).first if login
|
||||
raise WrongParams, 'missing user.id or user.login'.freeze
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,19 @@ describe Travis::API::V3::Services::Account::Find do
|
|||
}}
|
||||
end
|
||||
|
||||
describe 'it is not case sensitive' do
|
||||
before { get("/v3/account/example-ORG") }
|
||||
example { expect(last_response).to be_ok }
|
||||
example { expect(JSON.load(body)).to be == {
|
||||
"@type" => "organization",
|
||||
"@href" => "/v3/org/#{org.id}",
|
||||
"id" => org.id,
|
||||
"login" => "example-org",
|
||||
"name" => nil,
|
||||
"github_id" => nil
|
||||
}}
|
||||
end
|
||||
|
||||
describe "does not allow overriding org id" do
|
||||
let(:other) { Organization.new(login: 'other-org') }
|
||||
before { other.save! }
|
||||
|
@ -57,6 +70,21 @@ describe Travis::API::V3::Services::Account::Find do
|
|||
}}
|
||||
end
|
||||
|
||||
describe 'it is not case sensitive' do
|
||||
before { get("/v3/account/example-USER") }
|
||||
example { expect(last_response).to be_ok }
|
||||
example { expect(JSON.load(body)).to be == {
|
||||
"@type" => "user",
|
||||
"@href" => "/v3/user/#{user.id}",
|
||||
"id" => user.id,
|
||||
"login" => "example-user",
|
||||
"name" => nil,
|
||||
"github_id" => nil,
|
||||
"is_syncing"=> nil,
|
||||
"synced_at" => nil
|
||||
}}
|
||||
end
|
||||
|
||||
describe "does not allow overriding user id" do
|
||||
let(:other) { User.new(login: 'other-user') }
|
||||
before { other.save! }
|
||||
|
|
Loading…
Reference in New Issue
Block a user