* 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>
18 lines
549 B
Ruby
18 lines
549 B
Ruby
module Badges
|
|
class Award
|
|
def self.call(user_relation, slug, message_markdown, include_default_description: true)
|
|
return unless (badge_id = Badge.id_for_slug(slug))
|
|
|
|
user_relation.find_each do |user|
|
|
next if user.banished?
|
|
|
|
achievement = user.badge_achievements.create(
|
|
badge_id: badge_id,
|
|
rewarding_context_message_markdown: message_markdown,
|
|
include_default_description: include_default_description,
|
|
)
|
|
user.touch if achievement.persisted?
|
|
end
|
|
end
|
|
end
|
|
end
|