Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show a second reply button when comment is hidden #5045

Merged
merged 3 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

**Fixed**:

- **decidim-comments**: Don't show a second reply button when comment is hidden. [#5045](https://github.com/decidim/decidim/pull/5045)
- **decidim-core**: Fix amendments forms: show error messages and render hashtags. [#4951](https://github.com/decidim/decidim/pull/4951)
- **decidim-comments**: Fixes that as a normal user (no private user) I can comment on a private assembly where is available. [#4924](https://github.com/decidim/decidim/pull/4924)
- **decidim-accountability**: Handle special case when all children weight are nil on accountability. [#5026](https://github.com/decidim/decidim/pull/5026)
Expand Down
7 changes: 7 additions & 0 deletions decidim-comments/app/models/decidim/comments/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def accepts_new_comments?
root_commentable.accepts_new_comments? && depth < MAX_DEPTH
end

# Public: Override comment threads to exclude hidden ones.
#
# Returns comment.
def comment_threads
super.reject(&:hidden?)
end

# Public: Override Commentable concern method `users_to_notify_on_comment_created`.
# Return the comment author together with whatever ActiveRecord::Relation is returned by
# the `commentable`. This will cause the comment author to be notified when the
Expand Down
15 changes: 15 additions & 0 deletions decidim-comments/spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ module Comments
expect(comment.formatted_body).to eq("<p>bold text <em>neque dicta enim quasi</em> link</p>")
end
end

describe "#comment_threads count" do
let!(:parent) { create(:comment, commentable: commentable) }
let!(:comments) { create_list(:comment, 3, commentable: parent, root_commentable: commentable) }

it "return 3" do
expect(parent.comment_threads.count).to eq 3
end

it "returns 2 when a comment has been moderated" do
Decidim::Moderation.create!(reportable: comments.last, participatory_space: comments.last.participatory_space, hidden_at: 1.day.ago)

expect(parent.comment_threads.count).to eq 2
end
end
end
end
end
10 changes: 10 additions & 0 deletions decidim-comments/spec/types/comment_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ module Comments
FactoryBot.create(:comment, commentable: model)
expect(response).to include("hasComments" => true)
end

context "when comment child has been moderated" do
let(:comment) { create(:comment, commentable: model) }

it "return false" do
Decidim::Moderation.create!(reportable: comment, participatory_space: comment.participatory_space, hidden_at: 1.day.ago)

expect(response).to include("hasComments" => false)
end
end
end

describe "acceptsNewComments" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
visit resource_path

expect(page).to have_selector(".comment__reply")
expect(page).not_to have_selector(".comment__additionalreply")

within "#comments #comment_#{comment.id}" do
click_button "Reply"
Expand All @@ -110,10 +111,27 @@
end

expect(page).to have_selector(".comment-thread .comment--nested")
expect(page).to have_selector(".comment__additionalreply")
expect(page).to have_reply_to(comment, "This is a reply")
end
end

context "when a comment has been moderated" do
let!(:parent) { create(:comment, commentable: commentable) }
let!(:reply) { create(:comment, commentable: parent, root_commentable: commentable) }

it "doesn't show additional reply" do
Decidim::Moderation.create!(reportable: reply, participatory_space: reply.participatory_space, hidden_at: 1.day.ago)

visit current_path

within "#comments #comment_#{parent.id}" do
expect(page).to have_selector(".comment__reply")
expect(page).not_to have_selector(".comment__additionalreply")
end
end
end

describe "arguable option" do
context "when commenting with alignment" do
before do
Expand Down