FIX: FirstReplyByEmail badge wasn't granted
DEPRECATED: PostProcess badge trigger
This commit is contained in:
parent
d763ce08c0
commit
e55e2aff94
|
@ -1,6 +1,7 @@
|
||||||
module Jobs
|
module Jobs
|
||||||
|
|
||||||
class GrantFirstReplyByEmail < Jobs::Onceoff
|
class GrantFirstReplyByEmail < Jobs::Onceoff
|
||||||
|
|
||||||
def execute_onceoff(args)
|
def execute_onceoff(args)
|
||||||
return unless SiteSetting.enable_badges
|
return unless SiteSetting.enable_badges
|
||||||
to_award = {}
|
to_award = {}
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Jobs
|
||||||
.select(:id, :created_at, :cooked, :user_id)
|
.select(:id, :created_at, :cooked, :user_id)
|
||||||
.visible
|
.visible
|
||||||
.public_posts
|
.public_posts
|
||||||
.where("cooked like '%emoji%'")
|
.where("cooked LIKE '%emoji%'")
|
||||||
.find_in_batches do |group|
|
.find_in_batches do |group|
|
||||||
group.each do |p|
|
group.each do |p|
|
||||||
doc = Nokogiri::HTML::fragment(p.cooked)
|
doc = Nokogiri::HTML::fragment(p.cooked)
|
||||||
|
|
|
@ -11,9 +11,8 @@ module Jobs
|
||||||
.select(:id, :created_at, :raw, :user_id)
|
.select(:id, :created_at, :raw, :user_id)
|
||||||
.visible
|
.visible
|
||||||
.public_posts
|
.public_posts
|
||||||
.where("raw like '%http%'")
|
.where("raw LIKE '%http%'")
|
||||||
.find_in_batches do |group|
|
.find_in_batches do |group|
|
||||||
|
|
||||||
group.each do |p|
|
group.each do |p|
|
||||||
begin
|
begin
|
||||||
# Note we can't use `p.cooked` here because oneboxes have been cooked out
|
# Note we can't use `p.cooked` here because oneboxes have been cooked out
|
||||||
|
|
|
@ -66,14 +66,14 @@ class Badge < ActiveRecord::Base
|
||||||
PostRevision = 2
|
PostRevision = 2
|
||||||
TrustLevelChange = 4
|
TrustLevelChange = 4
|
||||||
UserChange = 8
|
UserChange = 8
|
||||||
PostProcessed = 16
|
PostProcessed = 16 # deprecated
|
||||||
|
|
||||||
def self.is_none?(trigger)
|
def self.is_none?(trigger)
|
||||||
[None].include? trigger
|
[None].include? trigger
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.uses_user_ids?(trigger)
|
def self.uses_user_ids?(trigger)
|
||||||
[TrustLevelChange, UserChange, PostProcessed].include? trigger
|
[TrustLevelChange, UserChange].include? trigger
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.uses_post_ids?(trigger)
|
def self.uses_post_ids?(trigger)
|
||||||
|
|
|
@ -362,6 +362,10 @@ class Post < ActiveRecord::Base
|
||||||
post_number == 1
|
post_number == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_reply_by_email?
|
||||||
|
via_email && post_number.present? && post_number > 1
|
||||||
|
end
|
||||||
|
|
||||||
def is_flagged?
|
def is_flagged?
|
||||||
post_actions.where(post_action_type_id: PostActionType.flag_types.values, deleted_at: nil).count != 0
|
post_actions.where(post_action_type_id: PostActionType.flag_types.values, deleted_at: nil).count != 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,7 +76,7 @@ class BadgeGranter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.queue_badge_grant(type,opt)
|
def self.queue_badge_grant(type, opt)
|
||||||
return unless SiteSetting.enable_badges
|
return unless SiteSetting.enable_badges
|
||||||
payload = nil
|
payload = nil
|
||||||
|
|
||||||
|
@ -105,12 +105,6 @@ class BadgeGranter
|
||||||
type: "PostAction",
|
type: "PostAction",
|
||||||
post_ids: [action.post_id, action.related_post_id].compact!
|
post_ids: [action.post_id, action.related_post_id].compact!
|
||||||
}
|
}
|
||||||
when Badge::Trigger::PostProcessed
|
|
||||||
user = opt[:user]
|
|
||||||
payload = {
|
|
||||||
type: "PostProcessed",
|
|
||||||
user_ids: [user.id]
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
$redis.lpush queue_key, payload.to_json if payload
|
$redis.lpush queue_key, payload.to_json if payload
|
||||||
|
@ -128,16 +122,17 @@ class BadgeGranter
|
||||||
limit -= 1
|
limit -= 1
|
||||||
end
|
end
|
||||||
|
|
||||||
items = items.group_by{|i| i["type"]}
|
items = items.group_by { |i| i["type"] }
|
||||||
|
|
||||||
items.each do |type, list|
|
items.each do |type, list|
|
||||||
post_ids = list.map{|i| i["post_ids"]}.flatten.compact.uniq
|
post_ids = list.flat_map { |i| i["post_ids"] }.compact.uniq
|
||||||
user_ids = list.map{|i| i["user_ids"]}.flatten.compact.uniq
|
user_ids = list.flat_map { |i| i["user_ids"] }.compact.uniq
|
||||||
|
|
||||||
next unless post_ids.present? || user_ids.present?
|
next unless post_ids.present? || user_ids.present?
|
||||||
find_by_type(type).each{ |badge|
|
|
||||||
|
find_by_type(type).each do |badge|
|
||||||
backfill(badge, post_ids: post_ids, user_ids: user_ids)
|
backfill(badge, post_ids: post_ids, user_ids: user_ids)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -229,10 +224,10 @@ class BadgeGranter
|
||||||
MAX_ITEMS_FOR_DELTA = 200
|
MAX_ITEMS_FOR_DELTA = 200
|
||||||
def self.backfill(badge, opts=nil)
|
def self.backfill(badge, opts=nil)
|
||||||
return unless SiteSetting.enable_badges
|
return unless SiteSetting.enable_badges
|
||||||
return unless badge.query.present? && badge.enabled
|
return unless badge.enabled
|
||||||
|
return unless badge.query.present?
|
||||||
|
|
||||||
post_ids = user_ids = nil
|
post_ids = user_ids = nil
|
||||||
|
|
||||||
post_ids = opts[:post_ids] if opts
|
post_ids = opts[:post_ids] if opts
|
||||||
user_ids = opts[:user_ids] if opts
|
user_ids = opts[:user_ids] if opts
|
||||||
|
|
||||||
|
@ -331,7 +326,6 @@ class BadgeGranter
|
||||||
raise ex
|
raise ex
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.revoke_ungranted_titles!
|
def self.revoke_ungranted_titles!
|
||||||
Badge.exec_sql("UPDATE users SET title = ''
|
Badge.exec_sql("UPDATE users SET title = ''
|
||||||
WHERE NOT title IS NULL AND
|
WHERE NOT title IS NULL AND
|
||||||
|
|
|
@ -382,7 +382,7 @@ Badge.seed do |b|
|
||||||
b.query = nil
|
b.query = nil
|
||||||
b.badge_grouping_id = BadgeGrouping::GettingStarted
|
b.badge_grouping_id = BadgeGrouping::GettingStarted
|
||||||
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
|
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
|
||||||
b.trigger = Badge::Trigger::PostProcessed
|
b.trigger = Badge::Trigger::None
|
||||||
b.system = true
|
b.system = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ Badge.seed do |b|
|
||||||
b.query = nil
|
b.query = nil
|
||||||
b.badge_grouping_id = BadgeGrouping::GettingStarted
|
b.badge_grouping_id = BadgeGrouping::GettingStarted
|
||||||
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
|
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
|
||||||
b.trigger = Badge::Trigger::PostProcessed
|
b.trigger = Badge::Trigger::None
|
||||||
b.system = true
|
b.system = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ Badge.seed do |b|
|
||||||
b.query = nil
|
b.query = nil
|
||||||
b.badge_grouping_id = BadgeGrouping::GettingStarted
|
b.badge_grouping_id = BadgeGrouping::GettingStarted
|
||||||
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
|
b.default_badge_grouping_id = BadgeGrouping::GettingStarted
|
||||||
b.trigger = Badge::Trigger::PostProcessed
|
b.trigger = Badge::Trigger::None
|
||||||
b.system = true
|
b.system = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ class CookedPostProcessor
|
||||||
|
|
||||||
BadgeGranter.grant(Badge.find(Badge::FirstEmoji), @post.user, post_id: @post.id) if has_emoji?
|
BadgeGranter.grant(Badge.find(Badge::FirstEmoji), @post.user, post_id: @post.id) if has_emoji?
|
||||||
BadgeGranter.grant(Badge.find(Badge::FirstOnebox), @post.user, post_id: @post.id) if @has_oneboxes
|
BadgeGranter.grant(Badge.find(Badge::FirstOnebox), @post.user, post_id: @post.id) if @has_oneboxes
|
||||||
|
BadgeGranter.grant(Badge.find(Badge::FirstReplyByEmail), @post.user, post_id: @post.id) if @post.is_reply_by_email?
|
||||||
end
|
end
|
||||||
|
|
||||||
def keep_reverse_index_up_to_date
|
def keep_reverse_index_up_to_date
|
||||||
|
|
|
@ -541,19 +541,20 @@ describe CookedPostProcessor do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "extracts links" do
|
context "extracts links" do
|
||||||
let(:post) { Fabricate(:post, raw: "sam has a blog at https://samsaffron.com") }
|
let(:post) { Fabricate(:post, raw: "sam has a blog at https://samsaffron.com") }
|
||||||
it "always re-extracts links on post process" do
|
|
||||||
TopicLink.destroy_all
|
it "always re-extracts links on post process" do
|
||||||
CookedPostProcessor.new(post).post_process
|
TopicLink.destroy_all
|
||||||
expect(TopicLink.count).to eq(1)
|
CookedPostProcessor.new(post).post_process
|
||||||
end
|
expect(TopicLink.count).to eq(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "grant badges" do
|
context "grant badges" do
|
||||||
|
let(:cpp) { CookedPostProcessor.new(post) }
|
||||||
|
|
||||||
context "emoji inside a quote" do
|
context "emoji inside a quote" do
|
||||||
let(:post) { Fabricate(:post, raw: "time to eat some sweet [quote]:candy:[/quote] mmmm") }
|
let(:post) { Fabricate(:post, raw: "time to eat some sweet [quote]:candy:[/quote] mmmm") }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
|
||||||
|
|
||||||
it "doesn't award a badge when the emoji is in a quote" do
|
it "doesn't award a badge when the emoji is in a quote" do
|
||||||
cpp.grant_badges
|
cpp.grant_badges
|
||||||
|
@ -563,7 +564,6 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
context "emoji in the text" do
|
context "emoji in the text" do
|
||||||
let(:post) { Fabricate(:post, raw: "time to eat some sweet :candy: mmmm") }
|
let(:post) { Fabricate(:post, raw: "time to eat some sweet :candy: mmmm") }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
|
||||||
|
|
||||||
it "awards a badge for using an emoji" do
|
it "awards a badge for using an emoji" do
|
||||||
cpp.grant_badges
|
cpp.grant_badges
|
||||||
|
@ -572,13 +572,9 @@ describe CookedPostProcessor do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "onebox" do
|
context "onebox" do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:post) { Fabricate(:post, raw: "onebox me:\n\nhttps://www.youtube.com/watch?v=Wji-BZ0oCwg\n") }
|
||||||
let(:post) { Fabricate.build(:post, user: user, raw: "onebox me:\n\nhttps://www.youtube.com/watch?v=Wji-BZ0oCwg\n") }
|
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
|
||||||
|
|
||||||
before do
|
before { Oneboxer.stubs(:onebox) }
|
||||||
Oneboxer.stubs(:onebox)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "awards a badge for using an emoji" do
|
it "awards a badge for using an emoji" do
|
||||||
cpp.post_process_oneboxes
|
cpp.post_process_oneboxes
|
||||||
|
@ -587,6 +583,15 @@ describe CookedPostProcessor do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "reply_by_email" do
|
||||||
|
let(:post) { Fabricate(:post, raw: "This is a **reply** via email ;)", via_email: true, post_number: 2) }
|
||||||
|
|
||||||
|
it "awards a badge for replying via email" do
|
||||||
|
cpp.grant_badges
|
||||||
|
expect(post.user.user_badges.where(badge_id: Badge::FirstReplyByEmail).exists?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue