summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2019-02-01 14:35:46 +0000
committerRémy Coutable <remy@rymai.me>2019-02-01 14:35:46 +0000
commit8028a59d7a89ca803902b5b5a206bcf1e83e8c51 (patch)
treec8bca02c1b8e2a8e070431a847d640f866f22699
parentd7a3f875d13b8d4a599a61232938f762d9c5e735 (diff)
parenta612bd070862097893103c4babc63df9ad45b214 (diff)
downloadgitlab-ce-8028a59d7a89ca803902b5b5a206bcf1e83e8c51.tar.gz
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
-rw-r--r--changelogs/unreleased/51913-api-getting-projects-for-users-with-dot-gets-404.yml5
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/projects.rb2
-rw-r--r--lib/api/users.rb6
-rw-r--r--spec/requests/api/projects_spec.rb13
-rw-r--r--spec/requests/api/users_spec.rb2
6 files changed, 22 insertions, 7 deletions
diff --git a/changelogs/unreleased/51913-api-getting-projects-for-users-with-dot-gets-404.yml b/changelogs/unreleased/51913-api-getting-projects-for-users-with-dot-gets-404.yml
new file mode 100644
index 00000000000..9d72efdd52a
--- /dev/null
+++ b/changelogs/unreleased/51913-api-getting-projects-for-users-with-dot-gets-404.yml
@@ -0,0 +1,5 @@
+---
+title: 'API: Support username with dots'
+merge_request: 24395
+author: Robert Schilling
+type: fixed
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 2b42e377c74..9cbfc0e35ff 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -9,6 +9,7 @@ module API
NO_SLASH_URL_PART_REGEX = %r{[^/]+}
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
+ USER_REQUIREMENTS = { user_id: NO_SLASH_URL_PART_REGEX }.freeze
insert_before Grape::Middleware::Error,
GrapeLogging::Middleware::RequestLogger,
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 9f3a1699146..3afa2d8a6b0 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -128,7 +128,7 @@ module API
end
end
- resource :users, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
+ resource :users, requirements: API::USER_REQUIREMENTS do
desc 'Get a user projects' do
success Entities::BasicProjectDetails
end
diff --git a/lib/api/users.rb b/lib/api/users.rb
index b41fce76df0..8ce09a8881b 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -133,10 +133,10 @@ module API
desc "Get the status of a user"
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
- get ":id_or_username/status" do
- user = find_user(params[:id_or_username])
+ get ":user_id/status", requirements: API::USER_REQUIREMENTS do
+ user = find_user(params[:user_id])
not_found!('User') unless user && can?(current_user, :read_user, user)
present user.status || {}, with: Entities::UserStatus
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 7248908b494..70686158b7d 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -21,7 +21,7 @@ describe API::Projects do
let(:project) { create(:project, :repository, namespace: user.namespace) }
let(:project2) { create(:project, namespace: user.namespace) }
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
create(:project,
:private,
@@ -724,7 +724,7 @@ describe API::Projects do
expect(json_response['message']).to eq('404 User Not Found')
end
- it 'returns projects filtered by user' do
+ it 'returns projects filtered by user id' do
get api("/users/#{user4.id}/projects/", user)
expect(response).to have_gitlab_http_status(200)
@@ -733,6 +733,15 @@ describe API::Projects do
expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id)
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
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)
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 89151021f90..b381431306d 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe API::Users do
- let(:user) { create(:user) }
+ let(:user) { create(:user, username: 'user.with.dot') }
let(:admin) { create(:admin) }
let(:key) { create(:key, user: user) }
let(:gpg_key) { create(:gpg_key, user: user) }