Skip to content

Commit 0e4ad16

Browse files
committed
Endpoint for multiple users basic info by usernames
1 parent fe2794c commit 0e4ad16

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

app/controllers/api/v8/apidocs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class ApidocsController < ActionController::Base
144144
# A list of all classes that have swagger_* declarations.
145145
# The order of the swagered_classes affects the order they are shown in swaggerUI
146146
SWAGGERED_CLASSES = [
147-
Api::V8::SubmissionsController,
148147
Api::V8::UsersController,
149148
Api::V8::CoursesController,
150149
Api::V8::Courses::PointsController,
@@ -164,6 +163,7 @@ class ApidocsController < ActionController::Base
164163
Api::V8::Organizations::Courses::Exercises::Users::PointsController,
165164
Api::V8::Organizations::Courses::Users::PointsController,
166165
Api::V8::Organizations::Courses::Users::SubmissionsController,
166+
Api::V8::Users::BasicInfoByUsernamesController,
167167
Api::V8::Core::CoursesController,
168168
Api::V8::Core::Courses::ReviewsController,
169169
Api::V8::Core::Courses::UnlocksController,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
module Api
4+
module V8
5+
module Users
6+
class BasicInfoByUsernamesController < Api::V8::BaseController
7+
include Swagger::Blocks
8+
9+
swagger_path '/api/v8/users/basic_info_by_usernames' do
10+
operation :post do
11+
key :description, 'Find all users\' basic infos with the posted json array of usernames'
12+
key :operationId, 'findUsersBasicInfoByUsernames'
13+
key :produces, [
14+
'application/json'
15+
]
16+
key :tags, [
17+
'user'
18+
]
19+
response 200 do
20+
key :description, 'Users\' username, email, and administrator status by usernames as json'
21+
schema do
22+
key :title, :user
23+
key :required, [:user]
24+
property :user do
25+
key :'$ref', :UsersBasicInfo
26+
end
27+
end
28+
end
29+
response 403, '$ref': '#/responses/error'
30+
response 404, '$ref': '#/responses/error'
31+
end
32+
end
33+
34+
35+
skip_authorization_check
36+
37+
def create
38+
respond_access_denied unless current_user.administrator?
39+
users = params[:usernames]
40+
41+
data = User.where(login: users).map do |u|
42+
{
43+
id: u.id,
44+
username: u.login,
45+
email: u.email,
46+
administrator: u.administrator
47+
}
48+
end
49+
render json: data
50+
end
51+
end
52+
end
53+
end
54+
end

config/routes.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
namespace :v8, defaults: {format: 'json'} do
4343
resources :apidocs, only: :index, path: 'documentation'
4444

45-
resources :users, only: [:show, :create, :update] do
46-
resources :request_deletion, only: [:create], module: :users
47-
end
48-
4945
namespace :users do
5046
resources :password_reset, only: [:create]
47+
resources :basic_info_by_usernames, only: :create
48+
end
49+
50+
resources :users, only: [:show, :create, :update] do
51+
resources :request_deletion, only: [:create], module: :users
5152
end
5253

5354
resources :organizations, param: :slug, path: 'org', only: %i{index show} do

0 commit comments

Comments
 (0)