Skip to content

Commit

Permalink
Merge pull request #426 from /issues/425
Browse files Browse the repository at this point in the history
Remove feedback from post comment (partially)
  • Loading branch information
ArtOfCode- committed May 15, 2018
2 parents 3559911 + 2d76040 commit 5748abe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/models/post_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ class PostComment < ApplicationRecord
belongs_to :post
belongs_to :user

before_create :remove_feedbacks

def self.scrubber
CommentScrubber.new
end

def remove_feedbacks
_feedback_type, comment = text.scan(/(fp|tp|why)?\W*(.*)/i).flatten
self.text = comment.to_s
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def api_token
encryption_key = AppConfig['stack_exchange']['token_aes_key']
begin
return AESCrypt.decrypt(encrypted_api_token, encryption_key, salt, iv)
rescue OpenSSL::Cipher::CipherError
rescue OpenSSL::Cipher::CipherError, ArgumentError
# Since dev environments don't have the proper keys to perform
# decryption on a prod data dump, we allow this error in dev
return encrypted_api_token if Rails.env.development? || Rails.env.test?
Expand Down
5 changes: 4 additions & 1 deletion app/views/post_comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<div class="panel panel-primary post-comment" data-cid="<%= comment.id %>">
<div class="panel-heading">
<strong><%= comment.user.username %></strong>
<% if feedback %>
<span style="<%= "font-weight:normal" if feedback.is_naa? %>" data-toggle="tooltip" data-placement="top" title="<%= (feedback.user.present? || feedback.api_key_id.present?) ? "#{feedback.user.try(:username)} (From #{feedback.api_key.try(:app_name) || "Review"})" : feedback.user_name %>: <%= feedback.feedback_type %>" class="text-white">(<%= element_symbol_for_feedback(feedback).html_safe %>)</span>
<% end %>
<span title="<%= comment.created_at %>"><%= time_ago_in_words comment.created_at %> ago</span>
<% if current_user == comment.user || current_user&.has_role?(:admin) %>
<span class="comment-control">
Expand All @@ -16,4 +19,4 @@
<div class="panel-body">
<%= raw(sanitize(PostCommentsController.renderer.render(comment.text), scrubber: PostComment.scrubber)) %>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<% end %>
<% @post.comments.each do |c| %>
<%= render 'post_comments/comment', comment: c %>
<%= render 'post_comments/comment', comment: c, feedback: Feedback.find_by(post: @post, user: c.user) %>
<% end %>

<p><a href="#" class="new-comment"><span class="glyphicon glyphicon-plus"></span> Add a comment</a></p>
Expand Down

0 comments on commit 5748abe

Please sign in to comment.