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:
@@ -241,6 +241,7 @@ class User < ApplicationRecord
|
||||
|
||||
Debate.hide_all debate_ids
|
||||
Comment.hide_all comment_ids
|
||||
Legislation::Proposal.hide_all legislation_proposal_ids
|
||||
Proposal.hide_all proposal_ids
|
||||
Budget::Investment.hide_all budget_investment_ids
|
||||
ProposalNotification.hide_all ProposalNotification.where(author_id: id).ids
|
||||
@@ -250,6 +251,7 @@ class User < ApplicationRecord
|
||||
ActiveRecord::Base.transaction do
|
||||
Debate.restore_all debates.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)
|
||||
Budget::Investment.restore_all budget_investments.where("hidden_at >= ?", hidden_at)
|
||||
ProposalNotification.restore_all(
|
||||
|
||||
@@ -106,5 +106,5 @@ en:
|
||||
hide: Hide
|
||||
search_placeholder: email or name of user
|
||||
title: Block users
|
||||
notice_block: User blocked. All of this user's debates and comments have been hidden.
|
||||
notice_hide: User blocked. All ot this user's debates and comments are still available.
|
||||
notice_block: The user has been blocked. All contents authored by this user have been hidden.
|
||||
notice_hide: The user has been hidden. Contents authored by this user are still available.
|
||||
|
||||
@@ -106,5 +106,5 @@ es:
|
||||
hide: Ocultar
|
||||
search_placeholder: email o nombre de usuario
|
||||
title: Bloquear usuarios
|
||||
notice_block: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
||||
notice_hide: Usuario bloqueado. Todos sus debates y comentarios siguen disponibles.
|
||||
notice_block: Usuario bloqueado. Se han ocultado todos sus contenidos y comentarios.
|
||||
notice_hide: Usuario ocultado. Todos sus contenidos y comentarios siguen disponibles.
|
||||
|
||||
@@ -30,7 +30,7 @@ describe Moderation::UsersController do
|
||||
put :block, params: { id: user }
|
||||
|
||||
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
|
||||
|
||||
it "redirects to the index with a nested resource" do
|
||||
|
||||
@@ -164,5 +164,9 @@ FactoryBot.define do
|
||||
terms_of_service { "1" }
|
||||
process factory: :legislation_process
|
||||
author factory: :user
|
||||
|
||||
trait :hidden do
|
||||
hidden_at { Time.current }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -758,6 +758,21 @@ describe User do
|
||||
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
|
||||
it "restore all previous hidden user content" do
|
||||
user = create(:user, :hidden)
|
||||
@@ -768,18 +783,21 @@ describe User do
|
||||
investment = create(:budget_investment, :hidden, author: user)
|
||||
proposal = create(:proposal, :hidden, author: user)
|
||||
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_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_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_legislation_proposal = create(:legislation_proposal, hidden_at: 3.days.ago, author: user)
|
||||
|
||||
other_user_comment = create(:comment, :hidden, author: other_user)
|
||||
other_user_debate = create(:debate, :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_proposal_notification = create(:proposal_notification, :hidden, proposal: other_user_proposal)
|
||||
other_user_legislation_proposal = create(:legislation_proposal, :hidden, author: other_user)
|
||||
|
||||
user.full_restore
|
||||
|
||||
@@ -788,18 +806,21 @@ describe User do
|
||||
expect(investment.reload).not_to be_hidden
|
||||
expect(proposal.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_debate.reload).to be_hidden
|
||||
expect(old_hidden_investment.reload).to be_hidden
|
||||
expect(old_hidden_proposal.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_debate.reload).to be_hidden
|
||||
expect(other_user_investment.reload).to be_hidden
|
||||
expect(other_user_proposal.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
|
||||
|
||||
Reference in New Issue
Block a user