Make articles from a user with spam role inaccessible (direct access) (#20515)

* Make articles inaccessible if their author has spam role

* Improve specs a bit for showing spammer articles
This commit is contained in:
Anna Buianova 2024-01-12 18:36:44 +03:00 committed by GitHub
parent 33fd9836be
commit 9c7476db62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -262,6 +262,7 @@ class StoriesController < ApplicationController
def assign_article_show_variables
not_found if permission_denied?
not_found unless @article.user
not_found if @article.user.spam?
@pinned_article_id = PinnedArticle.id

View file

@ -129,6 +129,25 @@ RSpec.describe "ArticlesShow" do
end
end
context "when author has spam role" do
before do
article.user.add_role(:spam)
end
it "renders 404" do
expect do
get article.path
end.to raise_error(ActiveRecord::RecordNotFound)
end
it "renders 404 for authorized user" do
sign_in user
expect do
get article.path
end.to raise_error(ActiveRecord::RecordNotFound)
end
end
context "when user signed in" do
before do
sign_in user