From 76555495f62b5dcae247f7106192d9bae88ae579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 2 Dec 2021 03:38:33 +0100 Subject: [PATCH] Hide legislation proposals when blocking a user We're also updating the notice messages to specify all contents have been hidden (not just debates). --- app/models/user.rb | 2 ++ config/locales/en/moderation.yml | 4 ++-- config/locales/es/moderation.yml | 4 ++-- .../moderation/users_controller_spec.rb | 2 +- spec/factories/legislations.rb | 4 ++++ spec/models/user_spec.rb | 21 +++++++++++++++++++ 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0e4be645d..0c6e03bfe 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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( diff --git a/config/locales/en/moderation.yml b/config/locales/en/moderation.yml index 6fc1e98c4..473e7238b 100644 --- a/config/locales/en/moderation.yml +++ b/config/locales/en/moderation.yml @@ -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. diff --git a/config/locales/es/moderation.yml b/config/locales/es/moderation.yml index 445dca9f9..14d2c4d47 100644 --- a/config/locales/es/moderation.yml +++ b/config/locales/es/moderation.yml @@ -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. diff --git a/spec/controllers/moderation/users_controller_spec.rb b/spec/controllers/moderation/users_controller_spec.rb index 4f9fdea6d..a1e9fcea2 100644 --- a/spec/controllers/moderation/users_controller_spec.rb +++ b/spec/controllers/moderation/users_controller_spec.rb @@ -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 diff --git a/spec/factories/legislations.rb b/spec/factories/legislations.rb index 94693417b..069899884 100644 --- a/spec/factories/legislations.rb +++ b/spec/factories/legislations.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d24392549..9c326f846 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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