Use separate actions to select/deselect proposals
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.
This commit is contained in:
@@ -8,7 +8,11 @@ class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def action
|
||||
:toggle_selection
|
||||
if selected?
|
||||
:deselect
|
||||
else
|
||||
:select
|
||||
end
|
||||
end
|
||||
|
||||
def selected?
|
||||
|
||||
@@ -8,8 +8,15 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseControll
|
||||
@proposals = @proposals.send("sort_by_#{@current_order}").page(params[:page])
|
||||
end
|
||||
|
||||
def toggle_selection
|
||||
@proposal.toggle :selected
|
||||
@proposal.save!
|
||||
def select
|
||||
@proposal.update!(selected: true)
|
||||
|
||||
render :toggle_selection
|
||||
end
|
||||
|
||||
def deselect
|
||||
@proposal.update!(selected: false)
|
||||
|
||||
render :toggle_selection
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,9 +19,16 @@ class Admin::ProposalsController < Admin::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def toggle_selection
|
||||
@proposal.toggle :selected
|
||||
@proposal.save!
|
||||
def select
|
||||
@proposal.update!(selected: true)
|
||||
|
||||
render :toggle_selection
|
||||
end
|
||||
|
||||
def deselect
|
||||
@proposal.update!(selected: false)
|
||||
|
||||
render :toggle_selection
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -32,7 +32,11 @@ namespace :admin do
|
||||
resources :debates, only: [:index, :show]
|
||||
|
||||
resources :proposals, only: [:index, :show, :update] do
|
||||
member { patch :toggle_selection }
|
||||
member do
|
||||
patch :select
|
||||
patch :deselect
|
||||
end
|
||||
|
||||
resources :milestones, controller: "proposal_milestones"
|
||||
resources :progress_bars, except: :show, controller: "proposal_progress_bars"
|
||||
end
|
||||
@@ -232,7 +236,10 @@ namespace :admin do
|
||||
resources :processes do
|
||||
resources :questions
|
||||
resources :proposals do
|
||||
member { patch :toggle_selection }
|
||||
member do
|
||||
patch :select
|
||||
patch :deselect
|
||||
end
|
||||
end
|
||||
resources :draft_versions
|
||||
resources :milestones
|
||||
|
||||
Reference in New Issue
Block a user