2018-08-21 19:56:14 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class UsersController < BaseController
|
2022-12-02 21:54:05 +08:00
|
|
|
before_action :load_team, only: :index
|
2018-08-21 19:56:14 +08:00
|
|
|
before_action :load_user, only: :show
|
|
|
|
|
2022-12-02 21:54:05 +08:00
|
|
|
def index
|
2023-07-31 18:21:40 +08:00
|
|
|
users = timestamps_filter(@team.users).page(params.dig(:page, :number))
|
|
|
|
.per(params.dig(:page, :size))
|
2022-12-02 21:54:05 +08:00
|
|
|
render jsonapi: users, each_serializer: UserSerializer
|
|
|
|
end
|
|
|
|
|
2018-08-21 19:56:14 +08:00
|
|
|
def show
|
2018-08-24 22:41:26 +08:00
|
|
|
render jsonapi: @user, serializer: UserSerializer
|
2018-08-21 19:56:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_user
|
2022-05-13 21:45:24 +08:00
|
|
|
@user = User.joins(:teams)
|
|
|
|
.where(user_assignments: { assignable: current_user.teams })
|
|
|
|
.find_by(id: params[:id])
|
2018-11-07 22:43:44 +08:00
|
|
|
raise PermissionError.new(User, :read) unless @user
|
2018-08-21 19:56:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|