docbrown/app/controllers/admin/organizations_controller.rb
Ridhwana 272aea6127
Allow admins to delete an organization (#19699)
* feat: update the layout for organizations

* feat: update the layout for an organization

* feat: organization logos are square

* feat: change the text on the org visit button

* feat: initialize the dropdown menu

* feat: trigger the  modal

* feat: update the text in the model

* feat: tweak wording

* WIP/feat: hook up a route with an action that calls an organization delete worker.

* feat: redirect after showing the notice

* feat: update the authorization required to be super admin

* feat: add the notice to localization

* spec: integration test

* spec: fix

* spec: delete worker

* chore: update the link

* feat: add safe navigation

* feat: make sure that we show an error if the organization has credits

* fix: error message for modal unspent credits

* feat add the spec for the helper

* fix: remove rspec preface

* fix: small fixes to tests and I18n

* fix: updated the number of orgs

* feat: update the message

* feat: update the message

* chore: remove inclusion of helper

* feat: change the name of the parameter

* chore: newline
2023-07-17 12:09:24 +02:00

56 lines
1.6 KiB
Ruby

module Admin
class OrganizationsController < Admin::ApplicationController
layout "admin"
PER_PAGE_MAX = 50
CREDIT_ACTIONS = {
add: :add_to,
remove: :remove_from
}.with_indifferent_access.freeze
def index
@organizations = Organization.simple_name_match(params[:search].presence)
.page(params[:page]).per(PER_PAGE_MAX)
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
def destroy
organization = Organization.find_by(id: params[:id])
Organizations::DeleteWorker.perform_async(organization.id, current_user.id, false)
flash[:settings_notice] =
I18n.t("admin.organizations_controller.deletion_scheduled", organization_name: organization.name)
redirect_to admin_organization_url(params[:id])
rescue StandardError => e
flash[:error] = I18n.t("admin.organizations_controller.error", organization_name: organization.name, error: e)
redirect_to user_settings_path(:organization, id: organization.id)
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