Commit a612bd07 authored by Robert Schilling's avatar Robert Schilling

Unify user requirements for API slugs

parent 33200ed6
......@@ -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,
......
......@@ -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
......
......@@ -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
......
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