Skip to content

Commit

Permalink
Add authorization for toggle_favorite and rename route
Browse files Browse the repository at this point in the history
  • Loading branch information
differentreality committed Sep 19, 2018
1 parent b4c66fc commit 7068bbc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ 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, :toogle_favorite, :withdraw]
skip_authorize_resource :event, only: [:confirm, :restart, :withdraw]


def index
@event = @program.events.new
Expand Down Expand Up @@ -88,7 +89,8 @@ def update
render action: 'edit'
end
end
def toogle_favorite

def toggle_favorite
user = User.find(params[:favourite_user_id])
users = @event.favourite_users
if users.include? user
Expand Down
4 changes: 4 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def signed_in(user)
event.users.include?(user)
end

can :toggle_favorite, Event do |event|
event.scheduled?
end

# can manage the commercials of their own events
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)

Expand Down
2 changes: 1 addition & 1 deletion app/views/schedules/_event.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
= link_to('#', onClick: 'starClicked();') do
%span#star-events{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
"aria-hidden" => "true", |
"data-url" => toogle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
"data-url" => toggle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
"data-user" => current_user.id }
%span.h3
= event.title
Expand Down
2 changes: 1 addition & 1 deletion app/views/schedules/_schedule_item.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
= link_to('#', onClick: 'starClicked();') do
%span#star{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", |
"aria-hidden" =>"true", |
"data-url" => toogle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
"data-url" => toggle_favorite_conference_program_proposal_path(@conference.short_title, event.id), |
"data-user" => current_user.id }
= event.title
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
patch '/withdraw' => 'proposals#withdraw'
patch '/confirm' => 'proposals#confirm'
patch '/restart' => 'proposals#restart'
patch :toogle_favorite
patch :toggle_favorite
end
end
resources :tracks, except: :destroy do
Expand Down

0 comments on commit 7068bbc

Please sign in to comment.