diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 71794ffe7..18e967e95 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -1,8 +1,10 @@ class TopicsController < ApplicationController - # include CommentableActions + include CommentableActions before_action :set_community + has_orders %w{most_voted newest oldest}, only: :show + skip_authorization_check def new @@ -21,6 +23,9 @@ class TopicsController < ApplicationController def show @topic = Topic.find(params[:id]) + @commentable = @topic + @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) + set_comment_flags(@comment_tree.comments) end def edit diff --git a/app/models/comment.rb b/app/models/comment.rb index 1db9809ee..8b68e11ad 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base include HasPublicAuthor include Graphqlable - COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation).freeze + COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic).freeze acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/models/topic.rb b/app/models/topic.rb index 04411ac91..6961e3f76 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,4 +1,9 @@ class Topic < ActiveRecord::Base + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + belongs_to :community belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + + has_many :comments, as: :commentable end diff --git a/app/views/topics/_comments.html.erb b/app/views/topics/_comments.html.erb new file mode 100644 index 000000000..ccab89847 --- /dev/null +++ b/app/views/topics/_comments.html.erb @@ -0,0 +1,24 @@ +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@topic), @comment_tree.comments, @comment_tree.comment_authors, @topic.comments_count, @comment_flags] do %> +
+ <%= link_to t("proposals.proposal.comments", count: topic.comments_count), community_topic_path(@community, topic, anchor: "comments") %> + <%= topic.author.name %> + <%= I18n.l topic.created_at %> +
+ <% if topic.author == current_user %> <%= link_to t("topic.edit"), edit_community_topic_path(@community.id, topic), class: 'button expanded' %> <% end %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 333b7b543..b44d3b7cf 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -3,3 +3,12 @@ Comunidad: <%= @community.proposal.title %>
+ +