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/
29 lines
437 B
Ruby
29 lines
437 B
Ruby
class Admin::Tenants::ToggleHiddenComponent < ApplicationComponent
|
|
attr_reader :tenant
|
|
|
|
def initialize(tenant)
|
|
@tenant = tenant
|
|
end
|
|
|
|
private
|
|
|
|
def action
|
|
if enabled?
|
|
:hide
|
|
else
|
|
:restore
|
|
end
|
|
end
|
|
|
|
def options
|
|
{
|
|
method: :put,
|
|
"aria-label": t("admin.tenants.index.enable", tenant: tenant.name)
|
|
}
|
|
end
|
|
|
|
def enabled?
|
|
!tenant.hidden?
|
|
end
|
|
end
|