2017-04-18 21:09:07 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class InstancesController < BaseController
|
2020-12-14 09:06:34 +01:00
|
|
|
before_action :set_instances, only: :index
|
2021-05-05 23:39:02 +02:00
|
|
|
before_action :set_instance, except: :index
|
2019-07-30 11:10:46 +02:00
|
|
|
|
2024-11-18 10:23:38 +01:00
|
|
|
LOGS_LIMIT = 5
|
|
|
|
|
2017-04-18 21:09:07 +02:00
|
|
|
def index
|
2017-11-11 20:23:33 +01:00
|
|
|
authorize :instance, :index?
|
2022-03-09 08:52:32 +01:00
|
|
|
preload_delivery_failures!
|
2017-04-18 21:09:07 +02:00
|
|
|
end
|
|
|
|
|
2019-01-08 13:39:49 +01:00
|
|
|
def show
|
|
|
|
authorize :instance, :show?
|
2022-03-09 08:52:32 +01:00
|
|
|
@time_period = (6.days.ago.to_date...Time.now.utc.to_date)
|
2024-11-18 10:23:38 +01:00
|
|
|
@action_logs = Admin::ActionLogFilter.new(target_domain: @instance.domain).results.limit(LOGS_LIMIT)
|
2017-07-20 23:07:13 +02:00
|
|
|
end
|
|
|
|
|
2021-12-17 23:01:21 +01:00
|
|
|
def destroy
|
|
|
|
authorize :instance, :destroy?
|
|
|
|
Admin::DomainPurgeWorker.perform_async(@instance.domain)
|
|
|
|
log_action :destroy, @instance
|
|
|
|
redirect_to admin_instances_path, notice: I18n.t('admin.instances.destroyed_msg', domain: @instance.domain)
|
|
|
|
end
|
|
|
|
|
2021-05-05 23:39:02 +02:00
|
|
|
def clear_delivery_errors
|
|
|
|
authorize :delivery, :clear_delivery_errors?
|
|
|
|
@instance.delivery_failure_tracker.clear_failures!
|
|
|
|
redirect_to admin_instance_path(@instance.domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def restart_delivery
|
|
|
|
authorize :delivery, :restart_delivery?
|
|
|
|
|
2022-03-09 08:52:32 +01:00
|
|
|
if @instance.unavailable?
|
2021-05-05 23:39:02 +02:00
|
|
|
@instance.delivery_failure_tracker.track_success!
|
2022-03-09 08:52:32 +01:00
|
|
|
log_action :destroy, @instance.unavailable_domain
|
2021-05-05 23:39:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to admin_instance_path(@instance.domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_delivery
|
|
|
|
authorize :delivery, :stop_delivery?
|
2022-03-09 08:52:32 +01:00
|
|
|
unavailable_domain = UnavailableDomain.create!(domain: @instance.domain)
|
2021-05-05 23:39:02 +02:00
|
|
|
log_action :create, unavailable_domain
|
|
|
|
redirect_to admin_instance_path(@instance.domain)
|
|
|
|
end
|
|
|
|
|
2017-04-18 21:09:07 +02:00
|
|
|
private
|
|
|
|
|
2019-07-30 11:10:46 +02:00
|
|
|
def set_instance
|
2023-10-23 14:27:57 +02:00
|
|
|
@instance = Instance.find_or_initialize_by(domain: TagManager.instance.normalize_domain(params[:id]&.strip))
|
2020-12-14 09:06:34 +01:00
|
|
|
end
|
2019-07-30 11:10:46 +02:00
|
|
|
|
2020-12-14 09:06:34 +01:00
|
|
|
def set_instances
|
|
|
|
@instances = filtered_instances.page(params[:page])
|
2022-03-09 08:52:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def preload_delivery_failures!
|
2022-12-01 10:32:10 +01:00
|
|
|
warning_domains_map = DeliveryFailureTracker.warning_domains_map(@instances.map(&:domain))
|
2021-05-05 23:39:02 +02:00
|
|
|
|
|
|
|
@instances.each do |instance|
|
|
|
|
instance.failure_days = warning_domains_map[instance.domain]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-13 12:30:07 +02:00
|
|
|
def filtered_instances
|
2023-08-02 19:32:48 +02:00
|
|
|
InstanceFilter.new(limited_federation_mode? ? { allowed: true } : filter_params).results
|
2017-09-13 12:30:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
2020-01-20 15:55:03 +01:00
|
|
|
params.slice(*InstanceFilter::KEYS).permit(*InstanceFilter::KEYS)
|
2017-09-13 12:30:07 +02:00
|
|
|
end
|
2017-04-18 21:09:07 +02:00
|
|
|
end
|
|
|
|
end
|