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.

63 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class RelaysController < BaseController
  4. before_action :set_relay, except: [:index, :new, :create]
  5. before_action :require_signatures_enabled!, only: [:new, :create, :enable]
  6. def index
  7. authorize :relay, :update?
  8. @relays = Relay.all
  9. end
  10. def new
  11. authorize :relay, :update?
  12. @relay = Relay.new
  13. end
  14. def create
  15. authorize :relay, :update?
  16. @relay = Relay.new(resource_params)
  17. if @relay.save
  18. @relay.enable!
  19. redirect_to admin_relays_path
  20. else
  21. render action: :new
  22. end
  23. end
  24. def destroy
  25. authorize :relay, :update?
  26. @relay.destroy
  27. redirect_to admin_relays_path
  28. end
  29. def enable
  30. authorize :relay, :update?
  31. @relay.enable!
  32. redirect_to admin_relays_path
  33. end
  34. def disable
  35. authorize :relay, :update?
  36. @relay.disable!
  37. redirect_to admin_relays_path
  38. end
  39. private
  40. def set_relay
  41. @relay = Relay.find(params[:id])
  42. end
  43. def resource_params
  44. params.require(:relay).permit(:inbox_url)
  45. end
  46. def require_signatures_enabled!
  47. redirect_to admin_relays_path, alert: I18n.t('admin.relays.signatures_not_enabled') if authorized_fetch_mode?
  48. end
  49. end
  50. end