2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-09 15:30:26 +08: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:
Sam Saffron 2020-05-26 10:07:00 +10:00
parent 979093787f
commit fc97f7e0e7
No known key found for this signature in database
GPG key ID: B9606168D2FFD9F5
5 changed files with 31 additions and 23 deletions

View file

@ -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