Skip to content

Commit

Permalink
Make articles from a user with spam role inaccessible (direct access) (
Browse files Browse the repository at this point in the history
forem#20515)

* Make articles inaccessible if their author has spam role

* Improve specs a bit for showing spammer articles
  • Loading branch information
lightalloy authored Jan 12, 2024
1 parent 33fd983 commit 9c7476d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def assign_feed_stories
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

Expand Down
19 changes: 19 additions & 0 deletions spec/requests/articles/articles_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@
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
Expand Down

0 comments on commit 9c7476d

Please sign in to comment.