glitchier-soc/app/controllers/admin/instances_controller.rb

76 lines
2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module Admin
class InstancesController < BaseController
before_action :set_instances, only: :index
before_action :set_instance, except: :index
2019-07-30 12:10:46 +03:00
def index
authorize :instance, :index?
preload_delivery_failures!
end
2019-01-08 14:39:49 +02:00
def show
authorize :instance, :show?
@time_period = (6.days.ago.to_date...Time.now.utc.to_date)
end
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
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?
if @instance.unavailable?
@instance.delivery_failure_tracker.track_success!
log_action :destroy, @instance.unavailable_domain
end
redirect_to admin_instance_path(@instance.domain)
end
def stop_delivery
authorize :delivery, :stop_delivery?
unavailable_domain = UnavailableDomain.create!(domain: @instance.domain)
log_action :create, unavailable_domain
redirect_to admin_instance_path(@instance.domain)
end
private
2019-07-30 12:10:46 +03:00
def set_instance
@instance = Instance.find(params[:id])
end
2019-07-30 12:10:46 +03:00
def set_instances
@instances = filtered_instances.page(params[:page])
end
def preload_delivery_failures!
warning_domains_map = DeliveryFailureTracker.warning_domains_map
@instances.each do |instance|
instance.failure_days = warning_domains_map[instance.domain]
end
end
2017-09-13 13:30:07 +03:00
def filtered_instances
2019-07-30 12:10:46 +03:00
InstanceFilter.new(whitelist_mode? ? { allowed: true } : filter_params).results
2017-09-13 13:30:07 +03:00
end
def filter_params
params.slice(*InstanceFilter::KEYS).permit(*InstanceFilter::KEYS)
2017-09-13 13:30:07 +03:00
end
end
end