Filter internal valuation comments from public api
Why: Internal valuation comments are only for admins and valuators, not for the public view. How: Adding a `not_valuations` scope and use it at the `public_for_api` one
This commit is contained in:
@@ -33,7 +33,8 @@ class Comment < ActiveRecord::Base
|
||||
end
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :public_for_api, -> do
|
||||
where(%{(comments.commentable_type = 'Debate' and comments.commentable_id in (?)) or
|
||||
not_valuations
|
||||
.where(%{(comments.commentable_type = 'Debate' and comments.commentable_id in (?)) or
|
||||
(comments.commentable_type = 'Proposal' and comments.commentable_id in (?)) or
|
||||
(comments.commentable_type = 'Poll' and comments.commentable_id in (?))},
|
||||
Debate.public_for_api.pluck(:id),
|
||||
@@ -50,6 +51,8 @@ class Comment < ActiveRecord::Base
|
||||
scope :sort_by_oldest, -> { order(created_at: :asc) }
|
||||
scope :sort_descendants_by_oldest, -> { order(created_at: :asc) }
|
||||
|
||||
scope :not_valuations, -> { where(valuation: false) }
|
||||
|
||||
after_create :call_after_commented
|
||||
|
||||
def self.build(commentable, user, body, p_id = nil)
|
||||
|
||||
@@ -465,6 +465,10 @@ FactoryBot.define do
|
||||
trait :with_confidence_score do
|
||||
before(:save) { |d| d.calculate_confidence_score }
|
||||
end
|
||||
|
||||
trait :valuation do
|
||||
valuation true
|
||||
end
|
||||
end
|
||||
|
||||
factory :legacy_legislation do
|
||||
|
||||
@@ -187,5 +187,11 @@ describe Comment do
|
||||
|
||||
expect(described_class.public_for_api).not_to include(comment)
|
||||
end
|
||||
|
||||
it "does not return internal valuation comments" do
|
||||
valuation_comment = create(:comment, :valuation)
|
||||
|
||||
expect(described_class.public_for_api).not_to include(valuation_comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user