Skip to content

Commit

Permalink
fix hakiri issue and added authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
shlok007 committed Apr 30, 2017
1 parent c07fd30 commit 360a764
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/controllers/rater_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
class RaterController < ApplicationController
load_and_authorize_resource :rate

def create
if user_signed_in?
obj = params[:klass].classify.constantize.find(params[:id])
votable_type = ''
VotableField::VALID_VOTABLE_TYPES.each do |valid_votable_type|
votable_type = valid_votable_type
break if params[:klass] == votable_type
end
obj = votable_type.classify.constantize.find(params[:id])
obj.rate params[:score].to_f, current_user, params[:dimension]

render json: true
Expand Down
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def signed_in_with_organizer_role(user)
# ids of all the conferences for which the user has the 'organizer' role
conf_ids_for_organizer = Conference.with_role(:organizer, user).pluck(:id)

can :manage, Rate, conference_id: conf_ids_for_organizer
can :manage, VotableField, conference_id: conf_ids_for_organizer
can :manage, Resource, conference_id: conf_ids_for_organizer
can [:new, :create], Conference if user.has_role?(:organizer, :any)
Expand Down Expand Up @@ -193,6 +194,7 @@ def signed_in_with_cfp_role(user)
# ids of all the conferences for which the user has the 'cfp' role
conf_ids_for_cfp = Conference.with_role(:cfp, user).pluck(:id)

can :manage, Rate, conference_id: conf_ids_for_cfp
can :manage, VotableField, conference_id: conf_ids_for_cfp
can [:index, :show, :update], Resource, conference_id: conf_ids_for_cfp
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
Expand Down

0 comments on commit 360a764

Please sign in to comment.