webhooks_controller.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # frozen_string_literal: true
  2. module Admin
  3. class WebhooksController < BaseController
  4. before_action :set_webhook, except: [:index, :new, :create]
  5. def index
  6. authorize :webhook, :index?
  7. @webhooks = Webhook.page(params[:page])
  8. end
  9. def new
  10. authorize :webhook, :create?
  11. @webhook = Webhook.new
  12. end
  13. def create
  14. authorize :webhook, :create?
  15. @webhook = Webhook.new(resource_params)
  16. if @webhook.save
  17. redirect_to admin_webhook_path(@webhook)
  18. else
  19. render :new
  20. end
  21. end
  22. def show
  23. authorize @webhook, :show?
  24. end
  25. def edit
  26. authorize @webhook, :update?
  27. end
  28. def update
  29. authorize @webhook, :update?
  30. if @webhook.update(resource_params)
  31. redirect_to admin_webhook_path(@webhook)
  32. else
  33. render :show
  34. end
  35. end
  36. def enable
  37. authorize @webhook, :enable?
  38. @webhook.enable!
  39. redirect_to admin_webhook_path(@webhook)
  40. end
  41. def disable
  42. authorize @webhook, :disable?
  43. @webhook.disable!
  44. redirect_to admin_webhook_path(@webhook)
  45. end
  46. def destroy
  47. authorize @webhook, :destroy?
  48. @webhook.destroy!
  49. redirect_to admin_webhooks_path
  50. end
  51. private
  52. def set_webhook
  53. @webhook = Webhook.find(params[:id])
  54. end
  55. def resource_params
  56. params.require(:webhook).permit(:url, events: [])
  57. end
  58. end
  59. end