You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.9 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class InstancesController < BaseController
  4. before_action :set_instances, only: :index
  5. before_action :set_instance, except: :index
  6. before_action :set_exhausted_deliveries_days, only: :show
  7. def index
  8. authorize :instance, :index?
  9. end
  10. def show
  11. authorize :instance, :show?
  12. end
  13. def clear_delivery_errors
  14. authorize :delivery, :clear_delivery_errors?
  15. @instance.delivery_failure_tracker.clear_failures!
  16. redirect_to admin_instance_path(@instance.domain)
  17. end
  18. def restart_delivery
  19. authorize :delivery, :restart_delivery?
  20. last_unavailable_domain = unavailable_domain
  21. if last_unavailable_domain.present?
  22. @instance.delivery_failure_tracker.track_success!
  23. log_action :destroy, last_unavailable_domain
  24. end
  25. redirect_to admin_instance_path(@instance.domain)
  26. end
  27. def stop_delivery
  28. authorize :delivery, :stop_delivery?
  29. UnavailableDomain.create(domain: @instance.domain)
  30. log_action :create, unavailable_domain
  31. redirect_to admin_instance_path(@instance.domain)
  32. end
  33. private
  34. def set_instance
  35. @instance = Instance.find(params[:id])
  36. end
  37. def set_exhausted_deliveries_days
  38. @exhausted_deliveries_days = @instance.delivery_failure_tracker.exhausted_deliveries_days
  39. end
  40. def set_instances
  41. @instances = filtered_instances.page(params[:page])
  42. warning_domains_map = DeliveryFailureTracker.warning_domains_map
  43. @instances.each do |instance|
  44. instance.failure_days = warning_domains_map[instance.domain]
  45. end
  46. end
  47. def unavailable_domain
  48. UnavailableDomain.find_by(domain: @instance.domain)
  49. end
  50. def filtered_instances
  51. InstanceFilter.new(whitelist_mode? ? { allowed: true } : filter_params).results
  52. end
  53. def filter_params
  54. params.slice(*InstanceFilter::KEYS).permit(*InstanceFilter::KEYS)
  55. end
  56. end
  57. end