a52b6f1c87
* Add explicit wrap_parameters to controllers for flat JSON API support Virtual attributes (has_rich_text, has_one_attached, delegated setters, ActiveModel attrs) are not in Model.attribute_names, so wrap_parameters auto-detection silently drops them from flat JSON requests. Add explicit include: lists matching each controller's permitted params. * Convert short-form wrap_parameters to explicit include: lists Defense-in-depth: these controllers only have real-column params today, so auto-detection works, but explicit lists prevent future regressions if virtual attributes are added. * Add flat JSON param tests for all wrap_parameters controllers 17 new tests covering every controller with wrap_parameters, verifying that flat (unwrapped) JSON payloads are correctly wrapped and processed. Focuses on virtual attributes that would be silently dropped without explicit include: lists.
73 lines
1.7 KiB
Ruby
73 lines
1.7 KiB
Ruby
class WebhooksController < ApplicationController
|
|
wrap_parameters :webhook, include: %i[ name url subscribed_actions ]
|
|
|
|
include BoardScoped
|
|
|
|
before_action :ensure_admin
|
|
before_action :set_webhook, except: %i[ index new create ]
|
|
|
|
def index
|
|
set_page_and_extract_portion_from @board.webhooks.ordered
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
@webhook = @board.webhooks.new
|
|
end
|
|
|
|
def create
|
|
@webhook = @board.webhooks.new(webhook_params)
|
|
|
|
if @webhook.save
|
|
respond_to do |format|
|
|
format.html { redirect_to @webhook }
|
|
format.json { render :show, status: :created, location: board_webhook_url(@webhook.board, @webhook, format: :json) }
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
format.html { render :new, status: :unprocessable_entity }
|
|
format.json { render json: @webhook.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if @webhook.update(webhook_params.except(:url))
|
|
respond_to do |format|
|
|
format.html { redirect_to @webhook }
|
|
format.json { render :show }
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
format.html { render :edit, status: :unprocessable_entity }
|
|
format.json { render json: @webhook.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@webhook.destroy!
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to board_webhooks_path }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
def set_webhook
|
|
@webhook = @board.webhooks.find(params[:id])
|
|
end
|
|
|
|
def webhook_params
|
|
params
|
|
.expect(webhook: [ :name, :url, subscribed_actions: [] ])
|
|
.merge(board_id: @board.id)
|
|
end
|
|
end
|