relays_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. module Admin
  3. class RelaysController < BaseController
  4. before_action :set_relay, except: [:index, :new, :create]
  5. before_action :warn_signatures_not_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 :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 warn_signatures_not_enabled!
  47. flash.now[:error] = I18n.t('admin.relays.signatures_not_enabled') if authorized_fetch_mode?
  48. end
  49. end
  50. end