Files
nairobi/app/controllers/admin/tenants_controller.rb
Javi Martín 25435b0297 Make it possible to disable tenants
Note we could use `acts_as_paranoid` with the `without_default_scope`
option, but we aren't doing so because it isn't possible to consider
deleted records in uniqueness validations with the paranoia gem [1].
I've added tests for these cases so we don't accidentally add
`acts_as_paranoid` in the future.

Also note we're extracting a `RowComponent` because, when
enabling/disabling a tenant, we're also enabling/disabling the link
pointing to its URL, and so we need to update the URL column after the
AJAX call.

[1] See issues 285 and 319 in https://github.com/rubysherpas/paranoia/
2022-12-28 14:34:00 +01:00

54 lines
1.1 KiB
Ruby

class Admin::TenantsController < Admin::BaseController
load_and_authorize_resource
def index
@tenants = @tenants.order(:name)
end
def new
end
def edit
end
def create
if @tenant.save
redirect_to admin_tenants_path, notice: t("admin.tenants.create.notice")
else
render :new
end
end
def update
if @tenant.update(tenant_params)
redirect_to admin_tenants_path, notice: t("admin.tenants.update.notice")
else
render :edit
end
end
def hide
@tenant.hide
respond_to do |format|
format.html { redirect_to admin_tenants_path, notice: t("admin.tenants.hide.notice") }
format.js { render template: "admin/tenants/toggle_enabled" }
end
end
def restore
@tenant.restore
respond_to do |format|
format.html { redirect_to admin_tenants_path, notice: t("admin.tenants.restore.notice") }
format.js { render template: "admin/tenants/toggle_enabled" }
end
end
private
def tenant_params
params.require(:tenant).permit(:name, :schema, :schema_type)
end
end