post approvals: add to post events page.

This commit is contained in:
evazion
2018-05-05 13:54:30 -05:00
parent 7c1d5e25fb
commit bfecbffb97
3 changed files with 34 additions and 22 deletions

View File

@@ -4,11 +4,11 @@ class PostEvent
include ActiveModel::Serializers::Xml include ActiveModel::Serializers::Xml
attr_accessor :event attr_accessor :event
delegate :creator, :creator_id, :reason, :is_resolved, :created_at, to: :event delegate :created_at, to: :event
def self.find_for_post(post_id) def self.find_for_post(post_id)
post = Post.find(post_id) post = Post.find(post_id)
(post.appeals + post.flags).sort_by(&:created_at).reverse.map { |e| new(event: e) } (post.appeals + post.flags + post.approvals).sort_by(&:created_at).reverse.map { |e| new(event: e) }
end end
def type_name def type_name
@@ -17,6 +17,8 @@ class PostEvent
"flag" "flag"
when PostAppeal when PostAppeal
"appeal" "appeal"
when PostApproval
"approval"
end end
end end
@@ -24,9 +26,25 @@ class PostEvent
type_name.first type_name.first
end end
def reason
event.try(:reason) || ""
end
def is_resolved
event.try(:is_resolved) || false
end
def creator_id
event.try(:creator_id) || event.try(:user_id)
end
def creator
event.try(:creator) || event.try(:user)
end
def is_creator_visible?(user = CurrentUser.user) def is_creator_visible?(user = CurrentUser.user)
case event case event
when PostAppeal when PostAppeal, PostApproval
true true
when PostFlag when PostFlag
flag = event flag = event

View File

@@ -1,15 +1,14 @@
<div id="c-post-events"> <div id="c-post-events">
<div id="a-index"> <div id="a-index">
<h1>Flags &amp; Appeals</h1> <h1>Post Events</h1>
<table width="100%" class="striped"> <table width="100%" class="striped autofit">
<thead> <thead>
<tr> <tr>
<th width="5%">Type</th> <th>Type</th>
<th width="10%">Creator</th> <th>User</th>
<th>Reason</th> <th>Description</th>
<th width="5%">Resolved?</th> <th>Resolved?</th>
<th width="15%">Date</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -22,16 +21,10 @@
<% else %> <% else %>
<i>hidden</i> <i>hidden</i>
<% end %> <% end %>
<br><%= time_ago_in_words_tagged event.created_at %>
</td> </td>
<td><%= format_text event.reason %></td> <td class="col-expand"><%= format_text event.reason %></td>
<td> <td><%= event.is_resolved %></td>
<% if event.is_resolved %>
yes
<% else %>
no
<% end %>
</td>
<td><%= compact_time event.created_at %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

@@ -9,8 +9,9 @@ class PostEventsControllerTest < ActionDispatch::IntegrationTest
as_user do as_user do
@post = create(:post) @post = create(:post)
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false) @post.flag!("aaa")
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa") @post.appeal!("aaa")
@post.approve!(@mod)
end end
end end