diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index cb65364a..9ed32c2f 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -1,10 +1,11 @@ class ProposalsController < ApplicationController + skip_authorization_check before_action :authenticate_user!, except: [:show, :new, :create] load_resource :conference, find_by: :short_title 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 @@ -63,31 +64,28 @@ 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]) - 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 + 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.find(params[:favourite_user_id]) + end + render json: {} + end + def withdraw authorize! :update, @event @url = conference_program_proposal_path(@conference.short_title, params[:id]) diff --git a/app/views/schedules/_event.html.haml b/app/views/schedules/_event.html.haml index c4bfadde..7afcac48 100644 --- a/app/views/schedules/_event.html.haml +++ b/app/views/schedules/_event.html.haml @@ -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" => 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 } %span.h3 = event.title diff --git a/app/views/schedules/_schedule_item.html.haml b/app/views/schedules/_schedule_item.html.haml index 027cfcc4..9d8ab42c 100644 --- a/app/views/schedules/_schedule_item.html.haml +++ b/app/views/schedules/_schedule_item.html.haml @@ -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" => 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 } = event.title diff --git a/config/routes.rb b/config/routes.rb index ba9228aa..64a3d522 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -115,6 +115,7 @@ Osem::Application.routes.draw do get :registrations patch '/confirm' => 'proposals#confirm' patch '/restart' => 'proposals#restart' + patch :toogle_favorite end end end