Files
nairobi/app/helpers/flags_helper.rb
2015-09-03 01:29:46 +02:00

30 lines
598 B
Ruby

module FlagsHelper
def show_flag_action?(flaggable)
current_user && !own_flaggable?(flaggable) && !flagged?(flaggable)
end
def show_unflag_action?(flaggable)
current_user && !own_flaggable?(flaggable) && flagged?(flaggable)
end
private
def flagged?(flaggable)
if flaggable.is_a? Comment
@comment_flags[flaggable.id]
else
Flag.flagged?(current_user, flaggable)
end
end
def own_flaggable?(flaggable)
if flaggable.is_a? Comment
flaggable.user_id == current_user.id
else
flaggable.author_id == current_user.id
end
end
end