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_resource :program, through: :conference, singleton: true
|
||||||
load_and_authorize_resource :event, parent: false, through: :program
|
load_and_authorize_resource :event, parent: false, through: :program
|
||||||
# We authorize manually in these actions
|
# 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
|
def index
|
||||||
@event = @program.events.new
|
@event = @program.events.new
|
||||||
|
|
@ -68,8 +68,6 @@ class ProposalsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
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])
|
track = Track.find_by(id: params[:event][:track_id])
|
||||||
|
|
@ -87,18 +85,16 @@ class ProposalsController < ApplicationController
|
||||||
render action: 'edit'
|
render action: 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
format.json do
|
def toogle_favorite
|
||||||
user = User.find(params[:favourite_user_id])
|
user = User.find(params[:favourite_user_id])
|
||||||
users = @event.favourite_users
|
users = @event.favourite_users
|
||||||
if users.include? user
|
if users.include? user
|
||||||
@event.favourite_users.delete(user)
|
@event.favourite_users.delete(user)
|
||||||
else
|
else
|
||||||
@event.favourite_users << User.find(params[:favourite_user_id])
|
@event.favourite_users << user
|
||||||
end
|
end
|
||||||
render json: {}
|
render json: {}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def withdraw
|
def withdraw
|
||||||
authorize! :update, @event
|
authorize! :update, @event
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
= link_to('#', onClick: 'starClicked();') do
|
= link_to('#', onClick: 'starClicked();') do
|
||||||
%span#star-events{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
|
%span#star-events{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
|
||||||
"aria-hidden" => "true", |
|
"aria-hidden" => "true", |
|
||||||
"data-url" => conference_program_proposal_path(@conference.short_title, event.id), |
|
"data-url" => toogle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
|
||||||
"data-user" => current_user.id }
|
"data-user" => current_user.id }
|
||||||
%span.h3
|
%span.h3
|
||||||
= event.title
|
= event.title
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
= link_to('#', onClick: 'starClicked();') do
|
= link_to('#', onClick: 'starClicked();') do
|
||||||
%span#star{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
|
%span#star{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
|
||||||
"aria-hidden" =>"true", |
|
"aria-hidden" =>"true", |
|
||||||
"data-url" => conference_program_proposal_path(@conference.short_title, event.id), |
|
"data-url" => toogle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
|
||||||
"data-user" => current_user.id }
|
"data-user" => current_user.id }
|
||||||
= event.title
|
= event.title
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,7 @@ Osem::Application.routes.draw do
|
||||||
patch '/withdraw' => 'proposals#withdraw'
|
patch '/withdraw' => 'proposals#withdraw'
|
||||||
patch '/confirm' => 'proposals#confirm'
|
patch '/confirm' => 'proposals#confirm'
|
||||||
patch '/restart' => 'proposals#restart'
|
patch '/restart' => 'proposals#restart'
|
||||||
|
patch :toogle_favorite
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :tracks, except: :destroy do
|
resources :tracks, except: :destroy do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue