2017-04-18 15:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class InstancesController < BaseController
|
2020-12-14 03:06:34 -05:00
|
|
|
before_action :set_instances, only: :index
|
2021-05-05 17:39:02 -04:00
|
|
|
before_action :set_instance, except: :index
|
|
|
|
before_action :set_exhausted_deliveries_days, only: :show
|
2019-07-30 05:10:46 -04:00
|
|
|
|
2017-04-18 15:09:07 -04:00
|
|
|
def index
|
2017-11-11 14:23:33 -05:00
|
|
|
authorize :instance, :index?
|
2017-04-18 15:09:07 -04:00
|
|
|
end
|
|
|
|
|
2019-01-08 07:39:49 -05:00
|
|
|
def show
|
|
|
|
authorize :instance, :show?
|
2017-07-20 17:07:13 -04:00
|
|
|
end
|
|
|
|
|
2021-05-05 17:39:02 -04: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?
|
|
|
|
|
|
|
|
last_unavailable_domain = unavailable_domain
|
|
|
|
|
|
|
|
if last_unavailable_domain.present?
|
|
|
|
@instance.delivery_failure_tracker.track_success!
|
|
|
|
log_action :destroy, last_unavailable_domain
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to admin_instance_path(@instance.domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_delivery
|
|
|
|
authorize :delivery, :stop_delivery?
|
|
|
|
|
|
|
|
UnavailableDomain.create(domain: @instance.domain)
|
|
|
|
log_action :create, unavailable_domain
|
|
|
|
redirect_to admin_instance_path(@instance.domain)
|
|
|
|
end
|
|
|
|
|
2017-04-18 15:09:07 -04:00
|
|
|
private
|
|
|
|
|
2019-07-30 05:10:46 -04:00
|
|
|
def set_instance
|
2020-12-14 03:06:34 -05:00
|
|
|
@instance = Instance.find(params[:id])
|
|
|
|
end
|
2019-07-30 05:10:46 -04:00
|
|
|
|
2021-05-05 17:39:02 -04:00
|
|
|
def set_exhausted_deliveries_days
|
|
|
|
@exhausted_deliveries_days = @instance.delivery_failure_tracker.exhausted_deliveries_days
|
|
|
|
end
|
|
|
|
|
2020-12-14 03:06:34 -05:00
|
|
|
def set_instances
|
|
|
|
@instances = filtered_instances.page(params[:page])
|
2021-05-05 17:39:02 -04:00
|
|
|
warning_domains_map = DeliveryFailureTracker.warning_domains_map
|
|
|
|
|
|
|
|
@instances.each do |instance|
|
|
|
|
instance.failure_days = warning_domains_map[instance.domain]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unavailable_domain
|
|
|
|
UnavailableDomain.find_by(domain: @instance.domain)
|
2019-07-30 05:10:46 -04:00
|
|
|
end
|
|
|
|
|
2017-09-13 06:30:07 -04:00
|
|
|
def filtered_instances
|
2019-07-30 05:10:46 -04:00
|
|
|
InstanceFilter.new(whitelist_mode? ? { allowed: true } : filter_params).results
|
2017-09-13 06:30:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
2020-01-20 09:55:03 -05:00
|
|
|
params.slice(*InstanceFilter::KEYS).permit(*InstanceFilter::KEYS)
|
2017-09-13 06:30:07 -04:00
|
|
|
end
|
2017-04-18 15:09:07 -04:00
|
|
|
end
|
|
|
|
end
|