docbrown/app/services/badges/award_first_post.rb
Ben Halpern 78f9bec3e7
Allow admin to declare whether to include the badge description in message (#20684)
* Allow admin to declare whether to include the badge description in badge achievement message

* Update spec/services/badges/award_spec.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Add proper acceptance to tests

* Tweak tests

* Switch to kwargs

* Clean up test acceptance

* Change interface

* Update spec/requests/admin/badge_achievements_spec.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update app/services/badges/award.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Adjust interface

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-02-28 11:02:58 -05:00

23 lines
669 B
Ruby

module Badges
class AwardFirstPost
BADGE_SLUG = "writing-debut".freeze
def self.call
return unless (badge_id = Badge.id_for_slug(BADGE_SLUG))
Article.joins(:user)
.published
.where("articles.published_at > ?", 1.week.ago)
.where("articles.published_at < ?", 1.hour.ago)
.where("articles.score >= ?", 0)
.where(nth_published_by_author: 1)
.where.not(users: { id: User.with_role(:spam).or(User.with_role(:suspended)) })
.find_each do |article|
BadgeAchievement.create(
user_id: article.user_id,
badge_id: badge_id,
)
end
end
end
end