Hide legislation proposals when blocking a user

We're also updating the notice messages to specify all contents have
been hidden (not just debates).
This commit is contained in:
Javi Martín
2021-12-02 03:38:33 +01:00
parent 021fef07b6
commit 76555495f6
6 changed files with 32 additions and 5 deletions

View File

@@ -241,6 +241,7 @@ class User < ApplicationRecord
Debate.hide_all debate_ids Debate.hide_all debate_ids
Comment.hide_all comment_ids Comment.hide_all comment_ids
Legislation::Proposal.hide_all legislation_proposal_ids
Proposal.hide_all proposal_ids Proposal.hide_all proposal_ids
Budget::Investment.hide_all budget_investment_ids Budget::Investment.hide_all budget_investment_ids
ProposalNotification.hide_all ProposalNotification.where(author_id: id).ids ProposalNotification.hide_all ProposalNotification.where(author_id: id).ids
@@ -250,6 +251,7 @@ class User < ApplicationRecord
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
Debate.restore_all debates.where("hidden_at >= ?", hidden_at) Debate.restore_all debates.where("hidden_at >= ?", hidden_at)
Comment.restore_all comments.where("hidden_at >= ?", hidden_at) Comment.restore_all comments.where("hidden_at >= ?", hidden_at)
Legislation::Proposal.restore_all legislation_proposals.only_hidden.where("hidden_at >= ?", hidden_at)
Proposal.restore_all proposals.where("hidden_at >= ?", hidden_at) Proposal.restore_all proposals.where("hidden_at >= ?", hidden_at)
Budget::Investment.restore_all budget_investments.where("hidden_at >= ?", hidden_at) Budget::Investment.restore_all budget_investments.where("hidden_at >= ?", hidden_at)
ProposalNotification.restore_all( ProposalNotification.restore_all(

View File

@@ -106,5 +106,5 @@ en:
hide: Hide hide: Hide
search_placeholder: email or name of user search_placeholder: email or name of user
title: Block users title: Block users
notice_block: User blocked. All of this user's debates and comments have been hidden. notice_block: The user has been blocked. All contents authored by this user have been hidden.
notice_hide: User blocked. All ot this user's debates and comments are still available. notice_hide: The user has been hidden. Contents authored by this user are still available.

View File

@@ -106,5 +106,5 @@ es:
hide: Ocultar hide: Ocultar
search_placeholder: email o nombre de usuario search_placeholder: email o nombre de usuario
title: Bloquear usuarios title: Bloquear usuarios
notice_block: Usuario bloqueado. Se han ocultado todos sus debates y comentarios. notice_block: Usuario bloqueado. Se han ocultado todos sus contenidos y comentarios.
notice_hide: Usuario bloqueado. Todos sus debates y comentarios siguen disponibles. notice_hide: Usuario ocultado. Todos sus contenidos y comentarios siguen disponibles.

View File

@@ -30,7 +30,7 @@ describe Moderation::UsersController do
put :block, params: { id: user } put :block, params: { id: user }
expect(response).to redirect_to proposals_path expect(response).to redirect_to proposals_path
expect(flash[:notice]).to eq "User blocked. All of this user's debates and comments have been hidden." expect(flash[:notice]).to eq "The user has been blocked. All contents authored by this user have been hidden."
end end
it "redirects to the index with a nested resource" do it "redirects to the index with a nested resource" do

View File

@@ -164,5 +164,9 @@ FactoryBot.define do
terms_of_service { "1" } terms_of_service { "1" }
process factory: :legislation_process process factory: :legislation_process
author factory: :user author factory: :user
trait :hidden do
hidden_at { Time.current }
end
end end
end end

View File

@@ -758,6 +758,21 @@ describe User do
end end
end end
describe "#block" do
it "hides legislation proposals created by the user" do
user = create(:user)
other_user = create(:user)
proposal = create(:legislation_proposal, author: user)
other_proposal = create(:legislation_proposal, author: other_user)
user.block
expect(Legislation::Proposal.all).to eq [other_proposal]
expect(Legislation::Proposal.with_hidden).to match_array [proposal, other_proposal]
end
end
describe "#full_restore" do describe "#full_restore" do
it "restore all previous hidden user content" do it "restore all previous hidden user content" do
user = create(:user, :hidden) user = create(:user, :hidden)
@@ -768,18 +783,21 @@ describe User do
investment = create(:budget_investment, :hidden, author: user) investment = create(:budget_investment, :hidden, author: user)
proposal = create(:proposal, :hidden, author: user) proposal = create(:proposal, :hidden, author: user)
proposal_notification = create(:proposal_notification, :hidden, proposal: proposal) proposal_notification = create(:proposal_notification, :hidden, proposal: proposal)
legislation_proposal = create(:legislation_proposal, :hidden, author: user)
old_hidden_comment = create(:comment, hidden_at: 3.days.ago, author: user) old_hidden_comment = create(:comment, hidden_at: 3.days.ago, author: user)
old_hidden_debate = create(:debate, hidden_at: 3.days.ago, author: user) old_hidden_debate = create(:debate, hidden_at: 3.days.ago, author: user)
old_hidden_investment = create(:budget_investment, hidden_at: 3.days.ago, author: user) old_hidden_investment = create(:budget_investment, hidden_at: 3.days.ago, author: user)
old_hidden_proposal = create(:proposal, hidden_at: 3.days.ago, author: user) old_hidden_proposal = create(:proposal, hidden_at: 3.days.ago, author: user)
old_hidden_proposal_notification = create(:proposal_notification, hidden_at: 3.days.ago, proposal: proposal) old_hidden_proposal_notification = create(:proposal_notification, hidden_at: 3.days.ago, proposal: proposal)
old_hidden_legislation_proposal = create(:legislation_proposal, hidden_at: 3.days.ago, author: user)
other_user_comment = create(:comment, :hidden, author: other_user) other_user_comment = create(:comment, :hidden, author: other_user)
other_user_debate = create(:debate, :hidden, author: other_user) other_user_debate = create(:debate, :hidden, author: other_user)
other_user_proposal = create(:proposal, :hidden, author: other_user) other_user_proposal = create(:proposal, :hidden, author: other_user)
other_user_investment = create(:budget_investment, :hidden, author: other_user) other_user_investment = create(:budget_investment, :hidden, author: other_user)
other_user_proposal_notification = create(:proposal_notification, :hidden, proposal: other_user_proposal) other_user_proposal_notification = create(:proposal_notification, :hidden, proposal: other_user_proposal)
other_user_legislation_proposal = create(:legislation_proposal, :hidden, author: other_user)
user.full_restore user.full_restore
@@ -788,18 +806,21 @@ describe User do
expect(investment.reload).not_to be_hidden expect(investment.reload).not_to be_hidden
expect(proposal.reload).not_to be_hidden expect(proposal.reload).not_to be_hidden
expect(proposal_notification.reload).not_to be_hidden expect(proposal_notification.reload).not_to be_hidden
expect(legislation_proposal.reload).not_to be_hidden
expect(old_hidden_comment.reload).to be_hidden expect(old_hidden_comment.reload).to be_hidden
expect(old_hidden_debate.reload).to be_hidden expect(old_hidden_debate.reload).to be_hidden
expect(old_hidden_investment.reload).to be_hidden expect(old_hidden_investment.reload).to be_hidden
expect(old_hidden_proposal.reload).to be_hidden expect(old_hidden_proposal.reload).to be_hidden
expect(old_hidden_proposal_notification.reload).to be_hidden expect(old_hidden_proposal_notification.reload).to be_hidden
expect(old_hidden_legislation_proposal.reload).to be_hidden
expect(other_user_comment.reload).to be_hidden expect(other_user_comment.reload).to be_hidden
expect(other_user_debate.reload).to be_hidden expect(other_user_debate.reload).to be_hidden
expect(other_user_investment.reload).to be_hidden expect(other_user_investment.reload).to be_hidden
expect(other_user_proposal.reload).to be_hidden expect(other_user_proposal.reload).to be_hidden
expect(other_user_proposal_notification.reload).to be_hidden expect(other_user_proposal_notification.reload).to be_hidden
expect(other_user_legislation_proposal.reload).to be_hidden
end end
end end
end end