diff --git a/app/models/comment.rb b/app/models/comment.rb index a1d89a33f..1d5c9aa30 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,6 @@ class Comment < ActiveRecord::Base include Flaggable + include HasPublicAuthor acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases @@ -16,7 +17,6 @@ class Comment < ActiveRecord::Base belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true belongs_to :user, -> { with_hidden } - belongs_to :public_author, -> { with_public_activity }, class_name: 'User', foreign_key: 'user_id' before_save :calculate_confidence_score diff --git a/app/models/concerns/has_public_author.rb b/app/models/concerns/has_public_author.rb new file mode 100644 index 000000000..a1af255c5 --- /dev/null +++ b/app/models/concerns/has_public_author.rb @@ -0,0 +1,5 @@ +module HasPublicAuthor + def public_author + self.author.public_activity? ? self.author : nil + end +end diff --git a/app/models/debate.rb b/app/models/debate.rb index 13cff5b3f..5e7491b83 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -7,13 +7,13 @@ class Debate < ActiveRecord::Base include Sanitizable include Searchable include Filterable + include HasPublicAuthor acts_as_votable acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' - belongs_to :public_author, -> { with_public_activity }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone has_many :comments, as: :commentable diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 64cadbb24..ad51436b0 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -6,6 +6,7 @@ class Proposal < ActiveRecord::Base include Sanitizable include Searchable include Filterable + include HasPublicAuthor acts_as_votable acts_as_paranoid column: :hidden_at @@ -14,7 +15,6 @@ class Proposal < ActiveRecord::Base RETIRE_OPTIONS = %w(duplicated started unfeasible done other) belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' - belongs_to :public_author, -> { with_public_activity }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone has_many :comments, as: :commentable has_many :proposal_notifications