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)
|
|
|
|
end
|
2017-09-20 17:31:07 +08:00
|
|
|
|
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
|
|
|
private
|
2017-09-20 17:31:07 +08:00
|
|
|
|
2017-09-21 16:36:09 +08:00
|
|
|
def check_invite_users_permission
|
|
|
|
@team = Team.find_by_id(params[:team_id])
|
2017-09-21 22:42:56 +08:00
|
|
|
if @team && !is_admin_of_team(@team)
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: t('client_api.invite_users.permission_error'),
|
|
|
|
status: 422
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-21 16:36:09 +08:00
|
|
|
end
|
2017-09-20 17:31:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|