houdini/app/controllers/roles_controller.rb

34 lines
1,002 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2020-06-12 20:03:43 +00:00
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
class RolesController < ApplicationController
include Controllers::Nonprofit::Current
include Controllers::Nonprofit::Authorization
before_action :authenticate_nonprofit_admin!
def create
2019-08-06 14:07:55 +00:00
role = Role.create_for_nonprofit(role_params[:name].to_sym, role_params[:email], FetchNonprofit.with_params(params))
json_saved role, 'User successfully added!'
end
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
2019-08-06 14:07:55 +00:00
private
def role_params
params.require(:role).permit(:name, :email)
end
end