Return 404 if user is a spammer (#20546)

This commit is contained in:
Anna Buianova 2024-01-22 18:20:42 +03:00 committed by GitHub
parent aab0a19011
commit 947aaef7c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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