Replaces can? :flag/:unflag by a helper function
This commit is contained in:
23
app/helpers/flags_helper.rb
Normal file
23
app/helpers/flags_helper.rb
Normal file
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
<% if can? :flag, comment %>
|
||||
<% if show_flag_action? comment %>
|
||||
<span class="divider"> | </span>
|
||||
<a id="flag-expand-comment-<%= comment.id %>" data-dropdown="flag-drop-comment-<%= comment.id %>" aria-controls="flag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.flag') %>">
|
||||
<i class="icon-flag flag-disable"></i>
|
||||
@@ -10,7 +10,7 @@
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if can? :unflag, comment %>
|
||||
<% if show_unflag_action? comment %>
|
||||
<span class="divider"> | </span>
|
||||
<a id="unflag-expand-comment-<%= comment.id %>" data-dropdown="unflag-drop-comment-<%= comment.id %>" aria-controls="unflag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.unflag') %>">
|
||||
<i class="icon-flag flag-active"></i>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% if can? :flag, debate %>
|
||||
<% if show_flag_action? debate %>
|
||||
<a id="flag-expand-debate-<%= debate.id %>" data-dropdown="flag-drop-debate-<%= debate.id %>" aria-controls="flag-drop-debate-<%= debate.id %>" aria-expanded="false" title="<%= t('shared.flag') %>">
|
||||
<i class="icon-flag flag-disable"></i>
|
||||
</a>
|
||||
@@ -9,7 +9,7 @@
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if can? :unflag, debate %>
|
||||
<% if show_unflag_action? debate %>
|
||||
<a id="unflag-expand-debate-<%= debate.id %>" data-dropdown="unflag-drop-debate-<%= debate.id %>" aria-controls="unflag-drop-debate-<%= debate.id %>" aria-expanded="false" title="<%= t('shared.unflag') %>">
|
||||
<i class="icon-flag flag-active"></i>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user