docbrown/app/controllers/admin/organizations_controller.rb
yheuhtozr ef290a5120
controllers/admin i18n (#17085)
* admin controllers i18n

* remove ja.yml

* fix for spec

* fix for spec 2

* Apply suggestions from code review

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

* Update config/locales/controllers/admin/fr.yml

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>

Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>
2022-04-26 09:40:09 -06:00

49 lines
1.1 KiB
Ruby

module Admin
class OrganizationsController < Admin::ApplicationController
layout "admin"
CREDIT_ACTIONS = {
add: :add_to,
remove: :remove_from
}.with_indifferent_access.freeze
def index
@organizations = Organization.order(name: :desc).page(params[:page]).per(50)
return if params[:search].blank?
@organizations = @organizations.where(
"name ILIKE ?",
"%#{params[:search].strip}%",
)
end
def show
@organization = Organization.find(params[:id])
end
def update_org_credits
org = Organization.find(params[:id])
amount = params[:credits].to_i
update_action = CREDIT_ACTIONS.fetch(params[:credit_action])
Credit.public_send(update_action, org, amount)
add_note(org)
flash[:notice] = I18n.t("admin.organizations_controller.credit_updated")
redirect_to admin_organization_path(org)
end
private
def add_note(org)
Note.create(
author_id: current_user.id,
noteable_id: org.id,
noteable_type: "Organization",
reason: "misc_note",
content: params[:note],
)
end
end
end