prevent authored awardable thumbs votes

This commit is contained in:
barthc 2016-08-30 20:57:47 +01:00
parent 7687237237
commit 29f818e616
2 changed files with 12 additions and 7 deletions

View file

@ -8,12 +8,14 @@ module ToggleAwardEmoji
def toggle_award_emoji
name = params.require(:name)
return render json: { ok: false } unless awardable.user_can_award?(current_user, name)
if awardable.user_can_award?(current_user, name)
awardable.toggle_award_emoji(name, current_user)
TodoService.new.new_award_emoji(to_todoable(awardable), current_user)
awardable.toggle_award_emoji(name, current_user)
TodoService.new.new_award_emoji(to_todoable(awardable), current_user)
render json: { ok: true }
render json: { ok: true }
else
render json: { ok: false }
end
end
private

View file

@ -64,8 +64,11 @@ module Awardable
end
def user_can_award?(current_user, name)
name = normalize_name(name)
!(self.user_authored?(current_user) && awardable_votes?(name))
if user_authored?(current_user)
!awardable_votes?(normalize_name(name))
else
true
end
end
def awarded_emoji?(emoji_name, current_user)