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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide comments when parent resource is hidden #13554

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Run linter
  • Loading branch information
andra-panaite committed Oct 18, 2024
commit bd3dc3eb8047afc34066e54a77c2c52468a53757
2 changes: 1 addition & 1 deletion decidim-ai/lib/decidim/ai/spam_detection/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def error_message(klass, method_name)
end

def resource_hidden?(resource)
resource.class.included_modules.include?(Decidim::Reportable) && resource.hidden? && !spam_reasons.include?(resource.reports&.last.&reason)
resource.class.included_modules.include?(Decidim::Reportable) && resource.hidden? && spam_reasons.exclude?(resource.reports&.last&.reason)
alecslupu marked this conversation as resolved.
Show resolved Hide resolved
alecslupu marked this conversation as resolved.
Show resolved Hide resolved
end

def spam_reasons
alecslupu marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
expect(comment.reload).to be_hidden

visit decidim.search_path
expect(page).not_to have_content(translated(comment.body))
expect(page).to have_no_content(translated(comment.body))
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions decidim-core/lib/decidim/moderation_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ def hide_comments!

reportable.comments.each do |comment|
tool = Decidim::ModerationTools.new(comment, @current_user)
tool.create_report!({
unless Decidim::Report.exists?("decidim_moderation_id" => tool.moderation.id, "decidim_user_id" => @current_user.id)
tool.create_report!({
reason: "parent_hidden",
details: I18n.t("report_details", scope: "decidim.reports.parent_hidden")
}) unless Decidim::Report.exists?("decidim_moderation_id" => tool.moderation.id, "decidim_user_id" => @current_user.id)
})
end

tool.hide!
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
let!(:searchables) { create_list(:searchable_resource, 8, resource_type: "Decidim::Proposals") }

it "it hides the reported resource and associated comments from search results" do
comments = Decidim::Comments::Comment.where("decidim_root_commentable_id" => searchables.collect(&:id).sample(1))
comments = Decidim::Comments::Comment.where("decidim_root_commentable_id" => searchables.collect(&:id).sample(1))
expect { task.execute }.to change(Decidim::SearchableResource, :count).by(-comments.size)
end
end
end

Loading