Commit 8028a59d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '51913-api-getting-projects-for-users-with-dot-gets-404' into 'master'

API: Support username with dots

Closes #51913

See merge request gitlab-org/gitlab-ce!24395
parents d7a3f875 a612bd07
---
title: 'API: Support username with dots'
merge_request: 24395
author: Robert Schilling
type: fixed
...@@ -9,6 +9,7 @@ module API ...@@ -9,6 +9,7 @@ module API
NO_SLASH_URL_PART_REGEX = %r{[^/]+} NO_SLASH_URL_PART_REGEX = %r{[^/]+}
NAMESPACE_OR_PROJECT_REQUIREMENTS = { id: NO_SLASH_URL_PART_REGEX }.freeze NAMESPACE_OR_PROJECT_REQUIREMENTS = { id: NO_SLASH_URL_PART_REGEX }.freeze
COMMIT_ENDPOINT_REQUIREMENTS = NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(sha: NO_SLASH_URL_PART_REGEX).freeze COMMIT_ENDPOINT_REQUIREMENTS = NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(sha: NO_SLASH_URL_PART_REGEX).freeze
USER_REQUIREMENTS = { user_id: NO_SLASH_URL_PART_REGEX }.freeze
insert_before Grape::Middleware::Error, insert_before Grape::Middleware::Error,
GrapeLogging::Middleware::RequestLogger, GrapeLogging::Middleware::RequestLogger,
......
...@@ -128,7 +128,7 @@ module API ...@@ -128,7 +128,7 @@ module API
end end
end end
resource :users, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :users, requirements: API::USER_REQUIREMENTS do
desc 'Get a user projects' do desc 'Get a user projects' do
success Entities::BasicProjectDetails success Entities::BasicProjectDetails
end end
......
...@@ -133,10 +133,10 @@ module API ...@@ -133,10 +133,10 @@ module API
desc "Get the status of a user" desc "Get the status of a user"
params do params do
requires :id_or_username, type: String, desc: 'The ID or username of the user' requires :user_id, type: String, desc: 'The ID or username of the user'
end end
get ":id_or_username/status" do get ":user_id/status", requirements: API::USER_REQUIREMENTS do
user = find_user(params[:id_or_username]) user = find_user(params[:user_id])
not_found!('User') unless user && can?(current_user, :read_user, user) not_found!('User') unless user && can?(current_user, :read_user, user)
present user.status || {}, with: Entities::UserStatus present user.status || {}, with: Entities::UserStatus
......
...@@ -21,7 +21,7 @@ describe API::Projects do ...@@ -21,7 +21,7 @@ describe API::Projects do
let(:project) { create(:project, :repository, namespace: user.namespace) } let(:project) { create(:project, :repository, namespace: user.namespace) }
let(:project2) { create(:project, namespace: user.namespace) } let(:project2) { create(:project, namespace: user.namespace) }
let(:project_member) { create(:project_member, :developer, user: user3, project: project) } let(:project_member) { create(:project_member, :developer, user: user3, project: project) }
let(:user4) { create(:user) } let(:user4) { create(:user, username: 'user.with.dot') }
let(:project3) do let(:project3) do
create(:project, create(:project,
:private, :private,
...@@ -724,7 +724,7 @@ describe API::Projects do ...@@ -724,7 +724,7 @@ describe API::Projects do
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns projects filtered by user' do it 'returns projects filtered by user id' do
get api("/users/#{user4.id}/projects/", user) get api("/users/#{user4.id}/projects/", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
...@@ -733,6 +733,15 @@ describe API::Projects do ...@@ -733,6 +733,15 @@ describe API::Projects do
expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id) expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id)
end end
it 'returns projects filtered by username' do
get api("/users/#{user4.username}/projects/", user)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id)
end
it 'returns projects filtered by minimal access level' do it 'returns projects filtered by minimal access level' do
private_project1 = create(:project, :private, name: 'private_project1', creator_id: user4.id, namespace: user4.namespace) private_project1 = create(:project, :private, name: 'private_project1', creator_id: user4.id, namespace: user4.namespace)
private_project2 = create(:project, :private, name: 'private_project2', creator_id: user4.id, namespace: user4.namespace) private_project2 = create(:project, :private, name: 'private_project2', creator_id: user4.id, namespace: user4.namespace)
......
require 'spec_helper' require 'spec_helper'
describe API::Users do describe API::Users do
let(:user) { create(:user) } let(:user) { create(:user, username: 'user.with.dot') }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
let(:key) { create(:key, user: user) } let(:key) { create(:key, user: user) }
let(:gpg_key) { create(:gpg_key, user: user) } let(:gpg_key) { create(:gpg_key, user: user) }
......
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