webhooks_controller.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. @webhook.current_account = current_account
  17. if @webhook.save
  18. redirect_to admin_webhook_path(@webhook)
  19. else
  20. render :new
  21. end
  22. end
  23. def show
  24. authorize @webhook, :show?
  25. end
  26. def edit
  27. authorize @webhook, :update?
  28. end
  29. def update
  30. authorize @webhook, :update?
  31. @webhook.current_account = current_account
  32. if @webhook.update(resource_params)
  33. redirect_to admin_webhook_path(@webhook)
  34. else
  35. render :edit
  36. end
  37. end
  38. def enable
  39. authorize @webhook, :enable?
  40. @webhook.enable!
  41. redirect_to admin_webhook_path(@webhook)
  42. end
  43. def disable
  44. authorize @webhook, :disable?
  45. @webhook.disable!
  46. redirect_to admin_webhook_path(@webhook)
  47. end
  48. def destroy
  49. authorize @webhook, :destroy?
  50. @webhook.destroy!
  51. redirect_to admin_webhooks_path
  52. end
  53. private
  54. def set_webhook
  55. @webhook = Webhook.find(params[:id])
  56. end
  57. def resource_params
  58. params.require(:webhook).permit(:url, events: [])
  59. end
  60. end
  61. end