[deploy] Raise not_found for spam-banished users (#5586)
* Raise not_found for banished users * Move banished logic to decorator
This commit is contained in:
parent
7cda85d644
commit
ba6c70c2d2
6 changed files with 49 additions and 8 deletions
|
|
@ -42,7 +42,7 @@ class StoriesController < ApplicationController
|
|||
potential_username = params[:username].tr("@", "").downcase
|
||||
user_or_org = User.find_by("old_username = ? OR old_old_username = ?", potential_username, potential_username) ||
|
||||
Organization.find_by("old_slug = ? OR old_old_slug = ?", potential_username, potential_username)
|
||||
if user_or_org.present?
|
||||
if user_or_org.present? && !user_or_org.decorate.fully_banished?
|
||||
redirect_to user_or_org.path
|
||||
else
|
||||
not_found
|
||||
|
|
@ -163,14 +163,9 @@ class StoriesController < ApplicationController
|
|||
redirect_to_changed_username_profile
|
||||
return
|
||||
end
|
||||
not_found if @user.username.include?("spam_") && @user.decorate.fully_banished?
|
||||
assign_user_comments
|
||||
@pinned_stories = Article.published.where(id: @user.profile_pins.select(:pinnable_id)).
|
||||
limited_column_select.
|
||||
order("published_at DESC").decorate
|
||||
@stories = ArticleDecorator.decorate_collection(@user.articles.published.
|
||||
limited_column_select.
|
||||
where.not(id: @pinned_stories.pluck(:id)).
|
||||
order("published_at DESC").page(@page).per(user_signed_in? ? 2 : 5))
|
||||
assign_user_stories
|
||||
@article_index = true
|
||||
@list_of = "articles"
|
||||
redirect_if_view_param
|
||||
|
|
@ -244,6 +239,16 @@ class StoriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def assign_user_stories
|
||||
@pinned_stories = Article.published.where(id: @user.profile_pins.select(:pinnable_id)).
|
||||
limited_column_select.
|
||||
order("published_at DESC").decorate
|
||||
@stories = ArticleDecorator.decorate_collection(@user.articles.published.
|
||||
limited_column_select.
|
||||
where.not(id: @pinned_stories.pluck(:id)).
|
||||
order("published_at DESC").page(@page).per(user_signed_in? ? 2 : 5))
|
||||
end
|
||||
|
||||
def stories_by_timeframe
|
||||
if %w[week month year infinity].include?(params[:timeframe])
|
||||
@stories.where("published_at > ?", Timeframer.new(params[:timeframe]).datetime).
|
||||
|
|
|
|||
|
|
@ -25,4 +25,10 @@ class OrganizationDecorator < ApplicationDecorator
|
|||
text: "#ffffff"
|
||||
}
|
||||
end
|
||||
|
||||
def fully_banished?
|
||||
# We do not *currently* have the functionality to "ban" organizations.
|
||||
# We deal with them in other ways, but we still need to respond to this question.
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -95,6 +95,13 @@ class UserDecorator < ApplicationDecorator
|
|||
colors[id % 10]
|
||||
end
|
||||
|
||||
def fully_banished?
|
||||
# User suspended and has no content
|
||||
articles_count.zero? &&
|
||||
comments_count.zero? &&
|
||||
banned
|
||||
end
|
||||
|
||||
def stackbit_integration?
|
||||
access_tokens.any?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,6 +35,16 @@ RSpec.describe UserDecorator, type: :decorator do
|
|||
follow.update(points: 0.1)
|
||||
expect(user.decorate.cached_followed_tags.first.points).to eq(0.1)
|
||||
end
|
||||
|
||||
it "returns not fully banished if in good standing" do
|
||||
expect(user.decorate.fully_banished?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns fully banished if user has been banished" do
|
||||
Moderator::BanishUser.call_banish(admin: user, user: user)
|
||||
expect(user.decorate.fully_banished?).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#config_body_class" do
|
||||
|
|
|
|||
|
|
@ -202,4 +202,10 @@ RSpec.describe Organization, type: :model do
|
|||
expect(build(:organization).pro?).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#decoarated" do
|
||||
it "returns not fully banished" do
|
||||
expect(organization.decorate.fully_banished?).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ RSpec.describe "UserProfiles", type: :request do
|
|||
expect(response).to redirect_to("/#{user.username}")
|
||||
end
|
||||
|
||||
it "raises not found for banished users" do
|
||||
banishable_user = create(:user)
|
||||
Moderator::BanishUser.call_banish(admin: user, user: banishable_user)
|
||||
expect { get "/#{banishable_user.reload.old_username}" }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { get "/#{banishable_user.reload.username}" }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "renders noindex meta if banned" do
|
||||
user.add_role(:banned)
|
||||
get "/#{user.username}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue