2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
class RolesController < ApplicationController
|
2019-07-30 21:29:24 +00:00
|
|
|
include Controllers::NonprofitHelper
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_nonprofit_admin!
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def create
|
|
|
|
role = Role.create_for_nonprofit(params[:role][:name].to_sym, params[:role][:email], FetchNonprofit.with_params(params))
|
|
|
|
json_saved role, 'User successfully added!'
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def destroy
|
|
|
|
role = Role.find(params[:id])
|
|
|
|
roles = role.user.roles.where(host_id: params[:nonprofit_id], name: role.name)
|
|
|
|
if roles.empty?
|
|
|
|
render json: { error: "We couldn't find that admin" }, status: :unprocessable_entity
|
|
|
|
else
|
|
|
|
roles.destroy_all
|
|
|
|
flash[:notice] = 'User successfully removed'
|
|
|
|
render json: {}
|
|
|
|
end
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|