Skip to content

Commit 05de157

Browse files
Add authorization for toggle_favorite and rename route
1 parent 860a848 commit 05de157

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
@@ -87,7 +88,8 @@ def update
8788
render action: 'edit'
8889
end
8990
end
90-
def toogle_favorite
91+
92+
def toggle_favorite
9193
user = User.find(params[:favourite_user_id])
9294
users = @event.favourite_users
9395
if users.include? user

app/models/ability.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def signed_in(user)
110110
event.users.include?(user)
111111
end
112112

113+
can :toggle_favorite, Event do |event|
114+
event.scheduled?
115+
end
116+
113117
# can manage the commercials of their own events
114118
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
115119

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
@@ -174,7 +174,7 @@
174174
patch '/withdraw' => 'proposals#withdraw'
175175
patch '/confirm' => 'proposals#confirm'
176176
patch '/restart' => 'proposals#restart'
177-
patch :toogle_favorite
177+
patch :toggle_favorite
178178
end
179179
end
180180
resources :tracks, except: :destroy do

0 commit comments

Comments
 (0)