Skip to content
Snippets Groups Projects
Unverified Commit e6545279 authored by Khemissi Amir's avatar Khemissi Amir Committed by GitHub
Browse files

V3 Migrations: Optimized `Migrations::ExternalController::create_settings` API. (#4747)

parent dc24ac9b
No related branches found
No related tags found
No related merge requests found
...@@ -146,26 +146,29 @@ module Api ...@@ -146,26 +146,29 @@ module Api
render_data status: :created unless settings_hash.any? render_data status: :created unless settings_hash.any?
# Finds all the SiteSettings that need to be updated # Finds all the SiteSettings that need to be updated
site_settings_temp = SiteSetting.joins(:setting) site_settings_joined = SiteSetting.joins(:setting)
.where('settings.name': settings_hash[:site_settings].keys, provider: 'greenlight') .where('settings.name': settings_hash[:site_settings].keys, provider: 'greenlight')
.pluck(:id, :'settings.name')
.to_h
return render_error(status: :bad_request, errors: 'A site setting does not exist.') unless site_settings_temp okay = true
site_settings_joined.each do |site_setting|
site_setting_name = site_setting.setting.name
okay = false unless site_setting.update(value: settings_hash[:site_settings][site_setting_name])
end
# Re-structure the data so it is in the format: { <site_setting_id>: { value: <site_setting_new_value> } } return render_error status: :bad_request, errors: 'Something went wrong when migrating site settings.' unless okay
site_settings = site_settings_temp.transform_values { |v| { value: settings_hash[:site_settings][v.to_sym] } }
SiteSetting.update!(site_settings.keys, site_settings.values)
# Finds all the RoomsConfiguration that need to be updated # Finds all the RoomsConfiguration that need to be updated
room_configurations_temp = RoomsConfiguration.joins(:meeting_option) room_configurations_joined = RoomsConfiguration.joins(:meeting_option)
.where('meeting_options.name': settings_hash[:room_configurations].keys, .where('meeting_options.name': settings_hash[:room_configurations].keys,
provider: 'greenlight') provider: 'greenlight')
.pluck(:id, :'meeting_options.name')
.to_h okay = true
# Re-structure the data so it is in the format: { <rooms_configuration_id>: { value: <rooms_configuration_new_value> } } room_configurations_joined.each do |room_configuration|
room_configurations = room_configurations_temp.transform_values { |v| { value: settings_hash[:room_configurations][v.to_sym] } } room_configuration_name = room_configuration.meeting_option.name
RoomsConfiguration.update!(room_configurations.keys, room_configurations.values) okay = false unless room_configuration.update(value: settings_hash[:room_configurations][room_configuration_name])
end
return render_error status: :bad_request, errors: 'Something went wrong when migrating room configurations.' unless okay
render_data status: :created render_data status: :created
end end
...@@ -189,7 +192,10 @@ module Api ...@@ -189,7 +192,10 @@ module Api
end end
def settings_params def settings_params
decrypted_params.require(:settings).permit(site_settings: {}, room_configurations: {}) decrypted_params.require(:settings).permit(site_settings: %w[PrimaryColor PrimaryColorLight Terms PrivacyPolicy RegistrationMethod
ShareRooms PreuploadPresentation],
room_configurations: %w[record muteOnStart guestPolicy glAnyoneCanStart glAnyoneJoinAsModerator
glRequireAuthentication])
end end
def decrypted_params def decrypted_params
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment