Move update favorites to a separate action
Introduce a separate action `toggle_favorite` to update user favorites events. Otherwise users with permissions to update the event can have it as favorite.
This commit is contained in:
parent
059b5cbf84
commit
2485923319
4 changed files with 28 additions and 31 deletions
|
|
@ -6,7 +6,7 @@ class ProposalsController < ApplicationController
|
|||
load_resource :program, through: :conference, singleton: true
|
||||
load_and_authorize_resource :event, parent: false, through: :program
|
||||
# We authorize manually in these actions
|
||||
skip_authorize_resource :event, only: [:confirm, :restart, :withdraw]
|
||||
skip_authorize_resource :event, only: [:confirm, :restart, :toogle_favorite, :withdraw]
|
||||
|
||||
def index
|
||||
@event = @program.events.new
|
||||
|
|
@ -68,36 +68,32 @@ class ProposalsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
@url = conference_program_proposal_path(@conference.short_title, params[:id])
|
||||
@url = conference_program_proposal_path(@conference.short_title, params[:id])
|
||||
|
||||
track = Track.find_by(id: params[:event][:track_id])
|
||||
if track && !track.cfp_active
|
||||
flash.now[:error] = 'You have selected a track that doesn\'t accept proposals'
|
||||
render action: 'edit'
|
||||
return
|
||||
end
|
||||
|
||||
if @event.update(event_params)
|
||||
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
|
||||
notice: 'Proposal was successfully updated.'
|
||||
else
|
||||
flash[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}"
|
||||
render action: 'edit'
|
||||
end
|
||||
end
|
||||
format.json do
|
||||
user = User.find(params[:favourite_user_id])
|
||||
users = @event.favourite_users
|
||||
if users.include? user
|
||||
@event.favourite_users.delete(user)
|
||||
else
|
||||
@event.favourite_users << User.find(params[:favourite_user_id])
|
||||
end
|
||||
render json: {}
|
||||
end
|
||||
track = Track.find_by(id: params[:event][:track_id])
|
||||
if track && !track.cfp_active
|
||||
flash.now[:error] = 'You have selected a track that doesn\'t accept proposals'
|
||||
render action: 'edit'
|
||||
return
|
||||
end
|
||||
|
||||
if @event.update(event_params)
|
||||
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
|
||||
notice: 'Proposal was successfully updated.'
|
||||
else
|
||||
flash[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}"
|
||||
render action: 'edit'
|
||||
end
|
||||
end
|
||||
def toogle_favorite
|
||||
user = User.find(params[:favourite_user_id])
|
||||
users = @event.favourite_users
|
||||
if users.include? user
|
||||
@event.favourite_users.delete(user)
|
||||
else
|
||||
@event.favourite_users << user
|
||||
end
|
||||
render json: {}
|
||||
end
|
||||
|
||||
def withdraw
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue