mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
42 lines
875 B
Ruby
42 lines
875 B
Ruby
class Wizard
|
|
class StepUpdater
|
|
include ActiveModel::Model
|
|
|
|
attr_accessor :refresh_required, :fields
|
|
|
|
def initialize(current_user, step, fields)
|
|
@current_user = current_user
|
|
@step = step
|
|
@refresh_required = false
|
|
@fields = fields
|
|
end
|
|
|
|
def update
|
|
@step.updater.call(self) if @step.updater.present?
|
|
end
|
|
|
|
def success?
|
|
@errors.blank?
|
|
end
|
|
|
|
def refresh_required?
|
|
@refresh_required
|
|
end
|
|
|
|
def update_setting(id, value)
|
|
value.strip! if value.is_a?(String)
|
|
SiteSetting.set_and_log(id, value, @current_user) if SiteSetting.send(id) != value
|
|
end
|
|
|
|
def apply_setting(id)
|
|
update_setting(id, @fields[id])
|
|
rescue Discourse::InvalidParameters => e
|
|
errors.add(id, e.message)
|
|
end
|
|
|
|
def apply_settings(*ids)
|
|
ids.each {|id| apply_setting(id)}
|
|
end
|
|
|
|
end
|
|
end
|