Allow any admin to publish welcome thread (#11597)
* Allow any admin to publish welcome thread * Update app/models/article.rb Co-authored-by: rhymes <rhymes@hey.com> * Fix specs by making user for welcome thread an admin * revert spec changes and update code to include either admin, super_admin, or site mascot * add specs for scope * Modify tests and include mascot user * Fix test Co-authored-by: rhymes <rhymes@hey.com> Co-authored-by: mstruve <mollylbs@gmail.com>
This commit is contained in:
parent
68867e9384
commit
673b1406be
2 changed files with 32 additions and 3 deletions
|
|
@ -112,9 +112,10 @@ class Article < ApplicationRecord
|
|||
|
||||
scope :admin_published_with, lambda { |tag_name|
|
||||
published
|
||||
.where(user_id: SiteConfig.staff_user_id)
|
||||
.order(published_at: :desc)
|
||||
.tagged_with(tag_name)
|
||||
.where(user_id: User.with_role(:super_admin)
|
||||
.union(User.with_role(:admin))
|
||||
.union(id: [SiteConfig.staff_user_id, SiteConfig.mascot_user_id].compact)
|
||||
.select(:id)).order(published_at: :desc).tagged_with(tag_name)
|
||||
}
|
||||
|
||||
scope :user_published_with, lambda { |user_id, tag_name|
|
||||
|
|
|
|||
|
|
@ -53,6 +53,34 @@ RSpec.describe Article, type: :model do
|
|||
|
||||
it { is_expected.not_to allow_value("foo").for(:main_image_background_hex_color) }
|
||||
|
||||
describe "::admin_published_with" do
|
||||
it "includes mascot-published articles" do
|
||||
allow(SiteConfig).to receive(:mascot_user_id).and_return(3)
|
||||
user = create(:user, id: 3)
|
||||
create(:article, user: user, tags: "challenge")
|
||||
expect(described_class.admin_published_with("challenge").count).to eq(1)
|
||||
end
|
||||
|
||||
it "includes staff-user-published articles" do
|
||||
allow(SiteConfig).to receive(:staff_user_id).and_return(3)
|
||||
user = create(:user, id: 3)
|
||||
create(:article, user: user, tags: "challenge")
|
||||
expect(described_class.admin_published_with("challenge").count).to eq(1)
|
||||
end
|
||||
|
||||
it "includes admin published articles" do
|
||||
user = create(:user, :admin)
|
||||
create(:article, user: user, tags: "challenge")
|
||||
expect(described_class.admin_published_with("challenge").count).to eq(1)
|
||||
end
|
||||
|
||||
it "does not include regular user published articles" do
|
||||
user = create(:user)
|
||||
create(:article, user: user, tags: "challenge")
|
||||
expect(described_class.admin_published_with("challenge").count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#body_markdown" do
|
||||
it "is unique scoped for user_id and title" do
|
||||
art2 = build(:article, body_markdown: article.body_markdown, user: article.user, title: article.title)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue