1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-10 00:46:15 +01:00
fab-manager/app/controllers/api/users_controller.rb

36 lines
775 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# API Controller for resources of type Users with role :partner
2016-03-23 18:39:41 +01:00
class API::UsersController < API::ApiController
before_action :authenticate_user!
def index
if current_user.admin? && params[:role] == 'partner'
2016-03-23 18:39:41 +01:00
@users = User.with_role(:partner).includes(:profile)
else
head 403
end
end
def create
if current_user.admin?
res = UserService.create_partner(partner_params)
2016-03-23 18:39:41 +01:00
if res[:saved]
@user = res[:user]
2016-03-23 18:39:41 +01:00
render status: :created
else
render json: res[:user].errors.full_messages, status: :unprocessable_entity
2016-03-23 18:39:41 +01:00
end
else
head 403
end
end
private
2019-01-07 12:48:22 +01:00
2016-03-23 18:39:41 +01:00
def partner_params
params.require(:user).permit(:email, :first_name, :last_name)
end
end