diff --git a/app/helpers/flags_helper.rb b/app/helpers/flags_helper.rb new file mode 100644 index 000000000..3a8bfbc75 --- /dev/null +++ b/app/helpers/flags_helper.rb @@ -0,0 +1,23 @@ +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) + Flag.flagged?(current_user, flaggable) + 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 diff --git a/app/views/comments/_flag_actions.html.erb b/app/views/comments/_flag_actions.html.erb index f1557668c..c056204e7 100644 --- a/app/views/comments/_flag_actions.html.erb +++ b/app/views/comments/_flag_actions.html.erb @@ -1,4 +1,4 @@ -<% if can? :flag, comment %> +<% if show_flag_action? comment %>  |  @@ -9,7 +9,7 @@ <% end %> -<% if can? :unflag, debate %> +<% if show_unflag_action? debate %>