Skip to content

Commit

Permalink
Merge pull request #1268 from codidact/art/show-previous-flags
Browse files Browse the repository at this point in the history
Display existing flags in flag dialog
  • Loading branch information
ArtOfCode- authored Dec 18, 2023
2 parents 42e8813 + eba7000 commit 2624ea4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ def show
return not_found
end

# @post = @post.includes(:flags, flags: :post_flag_type)
@children = if current_user&.privilege?('flag_curate')
Post.where(parent_id: @post.id)
else
Post.where(parent_id: @post.id).undeleted
.or(Post.where(parent_id: @post.id, user_id: current_user&.id).where.not(user_id: nil))
end.includes(:votes, :user, :comments, :license, :post_type)
end.includes(:votes, :user, :comments, :license, :post_type, :flags, flags: :post_flag_type)
.order(Post.arel_table[:id].not_eq(params[:answer]))
.user_sort({ term: params[:sort], default: Arel.sql('deleted ASC, score DESC, RAND()') },
score: Arel.sql('deleted ASC, score DESC, RAND()'), active: :last_activity,
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def exec_sql(sql_array)
end

def verify_tag_editor
unless user_signed_in? && (current_user.privilege?(:edit_tags) || current_user.is_moderator || current_user.is_admin)
unless user_signed_in? &&
(current_user.privilege?(:edit_tags) || current_user.is_moderator || current_user.is_admin)
respond_to do |format|
format.html do
render 'errors/not_found', layout: 'without_sidebar', status: :not_found
Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,13 @@ def validate_prefs!
def preference(name, community: false)
preferences[community ? :community : :global][name]
end

def has_active_flags?(post)
!post.flags.where(user: self, status: nil).empty?
end

def active_flags(post)
post.flags.where(user: self, status: nil)
end
# rubocop:enable Naming/PredicateName
end
47 changes: 32 additions & 15 deletions app/views/posts/_expanded.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,25 @@
<div class="post--action-dialog js-flag-box">
<div class="widget">
<div class="widget--header">Why does this post require moderator attention?</div>
<% if current_user&.has_active_flags?(post) %>
<div class="widget--body">
<div class="notice is-warning">
You already have active flags on this post:
<ul>
<% current_user.active_flags(post).each do |flag| %>
<li>
<strong><%= flag.post_flag_type&.name || 'other' %></strong>
<% unless flag.reason.nil? %>
<span class="has-color-tertiary-600"><%= flag.reason %></span>
<% end %>
</li>
<% end %>
</ul>
</div>
</div>
<% end %>
<% unless post.locked? %>
<% PostFlagType.where(post_type_id: [post.post_type.id, nil]).where(active: 1).each do |reason| %>
<% PostFlagType.where(post_type_id: [post.post_type.id, nil]).where(active: 1).each do |reason| %>
<div class="widget--body">
<div class="grid">
<div class="grid--cell">
Expand Down Expand Up @@ -345,22 +362,22 @@
</div>
<% end %>
<% end %>
<div class="widget--body">
<div class="grid">
<div class="grid--cell">
<input class="form-radio-element" type="radio" name="flag-reason" value="-1" id="flag-reason-other_<%= post.id %>"
data-requires-details="true" />
</div>
<div class="grid--cell is-flexible">
<label class="form-element has-margin-0" for="flag-reason-other_<%= post.id %>">
other reason
<span class="form-caption">
Please elaborate in the details field below.
</span>
</label>
</div>
<div class="widget--body">
<div class="grid">
<div class="grid--cell">
<input class="form-radio-element" type="radio" name="flag-reason" value="-1" id="flag-reason-other_<%= post.id %>"
data-requires-details="true" />
</div>
<div class="grid--cell is-flexible">
<label class="form-element has-margin-0" for="flag-reason-other_<%= post.id %>">
other reason
<span class="form-caption">
Please elaborate in the details field below.
</span>
</label>
</div>
</div>
</div>
<div class="widget--body">
<label class="form-element" for="flag-post-<%= post.id %>">
Details?
Expand Down

0 comments on commit 2624ea4

Please sign in to comment.