scinote-web/app/controllers/client_api/users/invitations_controller.rb

43 lines
1.3 KiB
Ruby
Raw Normal View History

2017-09-20 17:31:07 +08:00
module ClientApi
2017-09-21 16:36:09 +08:00
module Users
class InvitationsController < Devise::InvitationsController
before_action :check_invite_users_permission, only: :invite_users
2017-09-20 17:31:07 +08:00
2017-09-21 16:36:09 +08:00
def invite_users
invite_service =
ClientApi::InvitationsService.new(user: current_user,
team: @team,
role: params['user_role'],
emails: params[:emails])
invite_results = invite_service.invitation
success_response(invite_results)
rescue => error
respond_to do |format|
format.json do
render json: { message: error }, status: :unprocessable_entity
end
end
2017-09-21 16:36:09 +08:00
end
2017-09-20 17:31:07 +08:00
2017-09-28 20:49:33 +08:00
private
2017-09-21 16:36:09 +08:00
def success_response(invite_results)
respond_to do |format|
format.json do
render template: '/client_api/users/invite_users',
status: :ok,
locals: { invite_results: invite_results, team: @team }
end
2017-09-20 17:31:07 +08:00
end
end
2017-09-21 16:36:09 +08:00
def check_invite_users_permission
@team = Team.find_by_id(params[:team_id])
2018-01-05 22:15:50 +08:00
if @team && !can_manage_team_users?(@team)
respond_422(t('client_api.invite_users.permission_error'))
2017-09-21 22:42:56 +08:00
end
2017-09-21 16:36:09 +08:00
end
2017-09-20 17:31:07 +08:00
end
end
end