diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 1c5696304..7b6dc8fa1 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -21,8 +21,8 @@ class DebatesController < ApplicationController @root_comments = @debate.comments.roots.recent.page(params[:page]).per(10).for_render @comments = @root_comments.inject([]){|all, root| all + root.descendants} - all_visible_comments = @root_comments + @comments - set_comment_flags(all_visible_comments) + @all_visible_comments = @root_comments + @comments + set_comment_flags(@all_visible_comments) end def new diff --git a/app/helpers/cache_keys_helper.rb b/app/helpers/cache_keys_helper.rb index 38445ae02..f75a21a59 100644 --- a/app/helpers/cache_keys_helper.rb +++ b/app/helpers/cache_keys_helper.rb @@ -12,6 +12,8 @@ module CacheKeysHelper user_status += ":signed" user_status += ":verified" if current_user.verified_at.present? user_status += ":org" if current_user.organization? + user_status += ":admin" if current_user.administrator? + user_status += ":moderator" if current_user.moderator? else user_status += ":visitor" end diff --git a/app/models/administrator.rb b/app/models/administrator.rb index 15715a328..8a34fa349 100644 --- a/app/models/administrator.rb +++ b/app/models/administrator.rb @@ -1,5 +1,5 @@ class Administrator < ActiveRecord::Base - belongs_to :user + belongs_to :user, touch: true delegate :name, :email, to: :user validates :user_id, presence: true, uniqueness: true diff --git a/app/models/comment.rb b/app/models/comment.rb index 8dd922714..efa9ec7a0 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -13,7 +13,7 @@ class Comment < ActiveRecord::Base belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true belongs_to :user, -> { with_hidden } - has_many :flags, :as => :flaggable + has_many :flags, as: :flaggable scope :recent, -> { order(id: :desc) } diff --git a/app/models/debate.rb b/app/models/debate.rb index 8471be20d..5e2864767 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -9,8 +9,8 @@ class Debate < ActiveRecord::Base include ActsAsParanoidAliases belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' - has_many :flags, :as => :flaggable has_many :comments, as: :commentable + has_many :flags, as: :flaggable validates :title, presence: true validates :description, presence: true diff --git a/app/models/flag.rb b/app/models/flag.rb index 2d13d26d9..02b16b385 100644 --- a/app/models/flag.rb +++ b/app/models/flag.rb @@ -22,6 +22,7 @@ class Flag < ActiveRecord::Base end def self.flagged?(user, flaggable) + return false unless user !! by_user_and_flaggable(user, flaggable).try(:first) end diff --git a/app/models/moderator.rb b/app/models/moderator.rb index 30d4f4394..6a5af7a52 100644 --- a/app/models/moderator.rb +++ b/app/models/moderator.rb @@ -1,5 +1,5 @@ class Moderator < ActiveRecord::Base - belongs_to :user + belongs_to :user, touch: true delegate :name, :email, to: :user validates :user_id, presence: true, uniqueness: true diff --git a/app/models/organization.rb b/app/models/organization.rb index fa991fc05..2962724a6 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,5 +1,5 @@ class Organization < ActiveRecord::Base - belongs_to :user + belongs_to :user, touch: true validates :name, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 71db4ee2e..0ae4d3290 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,6 +36,17 @@ class User < ActiveRecord::Base scope :officials, -> { where("official_level > 0") } scope :for_render, -> { includes(:organization) } + after_update :touch_debates, :touch_comments + after_touch :touch_debates, :touch_comments + + def touch_debates + debates.map(&:touch) + end + + def touch_comments + comments.map(&:touch) + end + def self.find_for_oauth(auth, signed_in_resource = nil) # Get the identity and user if they exist identity = Identity.find_for_oauth(auth) diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 3ee61e9f4..8bf07a8b3 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,101 +1,104 @@ -
<%= t("debates.comment.deleted") %>
-<%= t("debates.comment.deleted") %>
+
<%= comment.body %>
+ <% elsif comment.as_moderator? %> +<%= comment.body %>
+ <% elsif comment.user.official? && comment.user_id == @commentable.author_id %> +<%= comment.body %>
+ <% elsif comment.user.official? %> +<%= comment.body %>
+ <% elsif comment.user_id == @commentable.author_id %> +<%= comment.body %>
+ <% else %> +<%= comment.body %>
<% end %> + + <%= render 'comments/votes', comment: comment %> + - • <%= time_ago_in_words(comment.created_at) %> +<%= comment.body %>
- <% elsif comment.as_moderator? %> -<%= comment.body %>
- <% elsif comment.user.official? && comment.user_id == @commentable.author_id %> -<%= comment.body %>
- <% elsif comment.user.official? %> -<%= comment.body %>
- <% elsif comment.user_id == @commentable.author_id %> -<%= comment.body %>
- <% else %> -<%= comment.body %>
- <% end %> - - <%= render 'comments/votes', comment: comment %> - - -