summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2019-01-31 11:13:23 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2019-01-31 11:13:23 +0100
commita612bd070862097893103c4babc63df9ad45b214 (patch)
treea16a646706d9a729badd836da0824eb0ba5121b5
parent33200ed6904b00fc6c24363e29f4a8de895fb6c1 (diff)
downloadgitlab-ce-a612bd070862097893103c4babc63df9ad45b214.tar.gz
Unify user requirements for API slugs
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/projects.rb2
-rw-r--r--lib/api/users.rb6
3 files changed, 5 insertions, 4 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 59b67c67f9d..8dd4e37ef7f 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 d76d5d822b1..3afa2d8a6b0 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -128,7 +128,7 @@ module API
end
end
- resource :users, requirements: { user_id: API::NO_SLASH_URL_PART_REGEX } 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 ff33e892ef8..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", requirements: { id_or_username: API::NO_SLASH_URL_PART_REGEX } 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