FIX: Better handling for toggling must_approve_users

If you turn it on now, default all users to approved since they were
previously. Also support approving a user that doesn't have a reviewable
record (it will be created first.)

This also includes a refactor to move class method calls to
`DiscourseEvent` into an initializer. Otherwise the load order of
classes makes a difference in the test environment and some settings
might be triggered and others not, randomly.
This commit is contained in:
Robin Ward
2019-04-16 14:42:47 -04:00
parent cec0b580e6
commit ba6d4b2a8d
20 changed files with 103 additions and 61 deletions

View File

@ -4,7 +4,22 @@ class SiteSettings::LocalProcessProvider
attr_accessor :current_site
Setting = Struct.new(:name, :value, :data_type) unless defined? SiteSettings::LocalProcessProvider::Setting
class Setting
attr_accessor :name, :data_type, :value
def value_changed?
true
end
def saved_change_to_value?
true
end
def initialize(name, data_type)
self.name = name
self.data_type = data_type
end
end
def settings
@settings[current_site] ||= {}
@ -26,8 +41,14 @@ class SiteSettings::LocalProcessProvider
def save(name, value, data_type)
# NOTE: convert to string to simulate the conversion that is happening
# when using DbProvider
value = value.to_s
settings[name] = Setting.new(name, value, data_type)
setting = settings[name]
if setting.blank?
setting = Setting.new(name, data_type)
settings[name] = setting
end
setting.value = value.to_s
DiscourseEvent.trigger(:site_setting_saved, setting)
setting
end
def destroy(name)