diff --git a/app/controllers/communities_controller.rb b/app/controllers/communities_controller.rb index f28e03a05..5efa48f9a 100644 --- a/app/controllers/communities_controller.rb +++ b/app/controllers/communities_controller.rb @@ -22,4 +22,8 @@ class CommunitiesController < ApplicationController def load_topics @topics = @community.topics.send("sort_by_#{@order}").page(params[:page]) end + + def load_participants + @participants = @community.participants + end end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index eaa699c37..f0e57a383 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -1,7 +1,9 @@ class TopicsController < ApplicationController include CommentableActions + include FlagActions - before_action :set_community + before_action :load_community + before_action :load_topic, only: [:show, :edit, :update] has_orders %w{most_voted newest oldest}, only: :show @@ -13,7 +15,6 @@ class TopicsController < ApplicationController def create @topic = Topic.new(topic_params.merge(author: current_user, community_id: params[:community_id])) - if @topic.save redirect_to community_path(@community), notice: I18n.t('flash.actions.create.topic') else @@ -22,20 +23,17 @@ class TopicsController < ApplicationController end 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 - @topic = Topic.find(params[:id]) end def update - @topic = Topic.find(params[:id]) if @topic.update(topic_params) - redirect_to community_path(@community), notice: t('topic.update.notice') + redirect_to community_path(@community), notice: t('flash.actions.update.topic') else render :edit end @@ -44,10 +42,14 @@ class TopicsController < ApplicationController private def topic_params - params.require(:topic).permit(:title, :community_id, :description_as_comment) + params.require(:topic).permit(:title, :description) end - def set_community + def load_community @community = Community.find(params[:community_id]) end + + def load_topic + @topic = Topic.find(params[:id]) + end end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 1936f843c..1ab6c9826 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -42,7 +42,7 @@ module CommentsHelper def commentable_path(comment) commentable = comment.commentable - + case comment.commentable_type when "Budget::Investment" budget_investment_path(commentable.budget_id, commentable) @@ -50,6 +50,8 @@ module CommentsHelper legislation_process_question_path(commentable.process, commentable) when "Legislation::Annotation" legislation_process_draft_version_annotation_path(commentable.draft_version.process, commentable.draft_version, commentable) + when "Topic" + community_topic_path(comment.commentable.community, comment.commentable) else commentable end diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb new file mode 100644 index 000000000..1d5f1964f --- /dev/null +++ b/app/helpers/topics_helper.rb @@ -0,0 +1,11 @@ +module TopicsHelper + + def disabled_create_topic + "disabled" unless current_user + end + + def disabled_info_title + t("community.show.sidebar.disabled_info_title") unless current_user + end + +end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index b8f80c0cd..db4cee09d 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -33,7 +33,7 @@ module Abilities can :unmark_featured, Debate can :comment_as_administrator, [Debate, Comment, Proposal, Poll::Question, Budget::Investment, - Legislation::Question, Legislation::Annotation] + Legislation::Question, Legislation::Annotation, Topic] can [:search, :create, :index, :destroy], ::Administrator can [:search, :create, :index, :destroy], ::Moderator diff --git a/app/models/abilities/moderator.rb b/app/models/abilities/moderator.rb index 796bb185a..4e1427c12 100644 --- a/app/models/abilities/moderator.rb +++ b/app/models/abilities/moderator.rb @@ -6,7 +6,7 @@ module Abilities merge Abilities::Moderation.new(user) can :comment_as_moderator, [Debate, Comment, Proposal, Budget::Investment, Poll::Question, - Legislation::Question, Legislation::Annotation] + Legislation::Question, Legislation::Annotation, Topic] end end end diff --git a/app/models/community.rb b/app/models/community.rb index 5d8d82b34..feb6f9c59 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -3,4 +3,7 @@ class Community < ActiveRecord::Base has_one :investment has_many :topics + def participants + User.community_participants(self) + end end diff --git a/app/models/topic.rb b/app/models/topic.rb index 4161a4dce..8c8f3f6c9 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,4 +1,6 @@ class Topic < ActiveRecord::Base + include Flaggable + acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases @@ -7,15 +9,12 @@ class Topic < ActiveRecord::Base has_many :comments, as: :commentable - after_create :associate_comment + validates :title, presence: true + validates :description, presence: true + validates :author, presence: true scope :sort_by_newest, -> { order(created_at: :desc) } scope :sort_by_oldest, -> { order(created_at: :asc) } scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } - private - - def associate_comment - Comment.create(commentable: self, user: self.author, body: self.description_as_comment) - end end diff --git a/app/models/user.rb b/app/models/user.rb index 4d44456d6..da07d7fc7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -315,7 +315,13 @@ class User < ActiveRecord::Base def self.community_participants(community) topics_ids = community.topics.pluck(:id) - User.joins(:comments).where("comments.commentable_id IN (?) and comments.commentable_type = 'Topic'", topics_ids) + users_who_commented = User.joins(:comments).where("comments.commentable_id IN (?) and comments.commentable_type = 'Topic'", topics_ids).uniq + + author_ids = community.topics.pluck(:author_id) + users_who_authors = User.where("users.id IN (?)", author_ids) + + users_participants = users_who_commented + users_who_authors + users_participants.uniq end private diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb index 37d379d4f..a779d1dfa 100644 --- a/app/views/comments/show.html.erb +++ b/app/views/comments/show.html.erb @@ -11,4 +11,4 @@ <%= render @comment %> - \ No newline at end of file + diff --git a/app/views/communities/show.html.erb b/app/views/communities/show.html.erb index f5009c92c..1720c1792 100644 --- a/app/views/communities/show.html.erb +++ b/app/views/communities/show.html.erb @@ -4,7 +4,7 @@

<%= t("community.show.title") %>

<%= @community.proposal.title %>

-

<%= t("community.show.description") %>

+

<%= t("community.show.description") %>

@@ -13,8 +13,8 @@
@@ -26,8 +26,8 @@
@@ -35,9 +35,9 @@