Skip to content

Commit 7068bbc

Browse files
Add authorization for toggle_favorite and rename route
1 parent b4c66fc commit 7068bbc

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

app/controllers/proposals_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class ProposalsController < ApplicationController
66
load_resource :program, through: :conference, singleton: true
77
load_and_authorize_resource :event, parent: false, through: :program
88
# We authorize manually in these actions
9-
skip_authorize_resource :event, only: [:confirm, :restart, :toogle_favorite, :withdraw]
9+
skip_authorize_resource :event, only: [:confirm, :restart, :withdraw]
10+
1011

1112
def index
1213
@event = @program.events.new
@@ -88,7 +89,8 @@ def update
8889
render action: 'edit'
8990
end
9091
end
91-
def toogle_favorite
92+
93+
def toggle_favorite
9294
user = User.find(params[:favourite_user_id])
9395
users = @event.favourite_users
9496
if users.include? user

app/models/ability.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def signed_in(user)
103103
event.users.include?(user)
104104
end
105105

106+
can :toggle_favorite, Event do |event|
107+
event.scheduled?
108+
end
109+
106110
# can manage the commercials of their own events
107111
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
108112

app/views/schedules/_event.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
= link_to('#', onClick: 'starClicked();') do
1212
%span#star-events{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
1313
"aria-hidden" => "true", |
14-
"data-url" => toogle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
14+
"data-url" => toggle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
1515
"data-user" => current_user.id }
1616
%span.h3
1717
= event.title

app/views/schedules/_schedule_item.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
= link_to('#', onClick: 'starClicked();') do
1212
%span#star{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
1313
"aria-hidden" =>"true", |
14-
"data-url" => toogle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
14+
"data-url" => toggle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
1515
"data-user" => current_user.id }
1616
= event.title
1717

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
patch '/withdraw' => 'proposals#withdraw'
183183
patch '/confirm' => 'proposals#confirm'
184184
patch '/restart' => 'proposals#restart'
185-
patch :toogle_favorite
185+
patch :toggle_favorite
186186
end
187187
end
188188
resources :tracks, except: :destroy do

0 commit comments

Comments
 (0)