Skip to content
Snippets Groups Projects

Sync changes in ApplicationSetting to Default Organization

Closed Rutger Wessels requested to merge 394801-sync-setting into master
1 unresolved thread
4 files
+ 109
0
Compare changes
  • Side-by-side
  • Inline
Files
4
# frozen_string_literal: true
module ApplicationSettings
class SyncService
def execute
return false unless can_sync?
settings = default_organization_settings
current_application_settings = ApplicationSetting.first.attributes
# Attributes that exist in both OrganizationSetting and ApplicationSetting
supported_settings = settings.attributes.keys & current_application_settings.keys.excluding(%w[updated_at
created_at])
settings.update(current_application_settings.slice(*supported_settings))
end
private
# ApplicationSettings can be created before migrations have been run
# So we need to be sure the tables exist before we can sync
def can_sync?
Organizations::Organization.table_exists? &&
Organizations::OrganizationSetting.table_exists? &&
Organizations::Organization.default_organization
end
def default_organization_settings
default_org = Organizations::Organization.default_organization
default_org.settings || default_org.build_settings
end
end
end
Loading