mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: properly ban non human users from draft system
Previously we had a partial fix in place where non human users were not allowed draft sequences, this left edges around where non human users asked for drafts yet had none. For example system could already have a few drafts in place. This also removes and extensibility point we added that is not in use
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
class DraftSequence < ActiveRecord::Base
|
||||
def self.next!(user, key)
|
||||
return nil if !user
|
||||
|
||||
user_id = user
|
||||
user_id = user.id unless user.is_a?(Integer)
|
||||
|
||||
return 0 if invalid_user_id?(user_id)
|
||||
return 0 if !User.human_user_id?(user_id)
|
||||
|
||||
h = { user_id: user_id, draft_key: key }
|
||||
c = DraftSequence.find_by(h)
|
||||
@@ -18,27 +20,17 @@ class DraftSequence < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.current(user, key)
|
||||
return nil unless user
|
||||
return nil if !user
|
||||
|
||||
user_id = user
|
||||
user_id = user.id unless user.is_a?(Integer)
|
||||
|
||||
return 0 if invalid_user_id?(user_id)
|
||||
return 0 if !User.human_user_id?(user_id)
|
||||
|
||||
# perf critical path
|
||||
r, _ = DB.query_single('select sequence from draft_sequences where user_id = ? and draft_key = ?', user_id, key)
|
||||
r.to_i
|
||||
end
|
||||
|
||||
cattr_accessor :plugin_ignore_draft_sequence_callbacks
|
||||
self.plugin_ignore_draft_sequence_callbacks = {}
|
||||
|
||||
def self.invalid_user_id?(user_id)
|
||||
user_id < 0 || self.plugin_ignore_draft_sequence_callbacks.any? do |plugin, callback|
|
||||
plugin.enabled? ? callback.call(user_id) : false
|
||||
end
|
||||
end
|
||||
private_class_method :invalid_user_id?
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
Reference in New Issue
Block a user