This is consistent to what we usually do. Also, we're applying the same
criteria mentioned in commit 72704d776:
> We're also making these actions idempotent, so sending many requests
> to the same action will get the same result, which wasn't the case
> with the `toggle` action. Although it's a low probability case, the
> `toggle` action could result in [selecting a proposal] when trying to
> [deselect] it if someone else has [deselected it] it between the time
> the page loaded and the time the admin clicked on the "[Selected]"
> button.
52 lines
895 B
Ruby
52 lines
895 B
Ruby
class Admin::ProposalsController < Admin::BaseController
|
|
include HasOrders
|
|
include CommentableActions
|
|
include FeatureFlags
|
|
feature_flag :proposals
|
|
|
|
has_orders %w[created_at]
|
|
|
|
before_action :load_proposal, except: :index
|
|
|
|
def show
|
|
end
|
|
|
|
def update
|
|
if @proposal.update(proposal_params)
|
|
redirect_to admin_proposal_path(@proposal), notice: t("admin.proposals.update.notice")
|
|
else
|
|
render :show
|
|
end
|
|
end
|
|
|
|
def select
|
|
@proposal.update!(selected: true)
|
|
|
|
render :toggle_selection
|
|
end
|
|
|
|
def deselect
|
|
@proposal.update!(selected: false)
|
|
|
|
render :toggle_selection
|
|
end
|
|
|
|
private
|
|
|
|
def resource_model
|
|
Proposal
|
|
end
|
|
|
|
def load_proposal
|
|
@proposal = Proposal.find(params[:id])
|
|
end
|
|
|
|
def proposal_params
|
|
params.require(:proposal).permit(allowed_params)
|
|
end
|
|
|
|
def allowed_params
|
|
[:selected]
|
|
end
|
|
end
|