From 947aaef7c1fee09344b6b9f9cffd5b0972e8c068 Mon Sep 17 00:00:00 2001 From: Anna Buianova Date: Mon, 22 Jan 2024 18:20:42 +0300 Subject: [PATCH] Return 404 if user is a spammer (#20546) --- app/controllers/stories_controller.rb | 4 ++-- spec/requests/user/user_profile_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 71e2825ea..948bd724a 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -26,7 +26,6 @@ class StoriesController < ApplicationController def index @page = (params[:page] || 1).to_i - return handle_user_or_organization_or_podcast_or_page_index if params[:username] handle_base_index @@ -184,7 +183,8 @@ class StoriesController < ApplicationController end not_found if @user.username.include?("spam_") && @user.decorate.fully_banished? not_found unless @user.registered - if !user_signed_in? && (@user.spam_or_suspended? && @user.has_no_published_content?) + not_found if @user.spam? + if !user_signed_in? && (@user.suspended? && @user.has_no_published_content?) not_found end assign_user_comments diff --git a/spec/requests/user/user_profile_spec.rb b/spec/requests/user/user_profile_spec.rb index 60ee897d8..3437102d3 100644 --- a/spec/requests/user/user_profile_spec.rb +++ b/spec/requests/user/user_profile_spec.rb @@ -180,6 +180,9 @@ RSpec.describe "UserProfiles" do # rubocop:disable RSpec/NestedGroups describe "not found and no index behaviour" do + let(:spam_user) { create(:user, :spam) } + let(:admin_user) { create(:user, :admin) } + it "raises not found for banished users" do banishable_user = create(:user) Moderator::BanishUser.call(admin: user, user: banishable_user) @@ -187,6 +190,23 @@ RSpec.describe "UserProfiles" do expect { get "/#{banishable_user.reload.username}" }.to raise_error(ActiveRecord::RecordNotFound) end + it "raises not found for spammers with articles for signed in" do + sign_in current_user + create(:article, user: spam_user) + expect { get spam_user.path }.to raise_error(ActiveRecord::RecordNotFound) + end + + it "raises not found for spammers with articles for signed out" do + create(:article, user: spam_user) + expect { get spam_user.path }.to raise_error(ActiveRecord::RecordNotFound) + end + + it "renders spammer users for admins", skip: "to implement later" do + sign_in admin_user + get spam_user.path + expect(response).to be_successful + end + context "when a user is signed in" do it "does not raise not found for suspended users who have no current content" do sign_in current_user