Skip to content

Commit

Permalink
(bug) ignored timezone in opening/closing time
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainbx committed Feb 20, 2023
1 parent 1681dbd commit ef78e4a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog Fab-manager

- Fix a bug: timezone is ignored while configuring calendar opening/closing time
- Fix a bug: unable to configure RAILS_LOCALE to fr-CA
- Fix a bug: unable to fix availabilities for events
- Fix a bug: unable to start Fab-manager with message: maximum must be a nonnegative Integer
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/api/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def update
error = SettingService.check_before_update({ name: params[:name], value: setting_params[:value] })
render status: :unprocessable_entity, json: { error: error } and return if error

if @setting.save && @setting.history_values.create(value: setting_params[:value], invoicing_profile: current_user.invoicing_profile)
if SettingService.save_and_update(@setting, setting_params[:value], current_user)
SettingService.run_after_update([@setting])
render status: :ok
else
Expand All @@ -39,11 +39,8 @@ def bulk_update
error = SettingService.check_before_update(setting)
if error
db_setting.errors.add(:-, "#{I18n.t("settings.#{setting[:name]}")}: #{error}")
elsif db_setting.save
if db_setting.value != setting[:value] &&
db_setting.history_values.create(value: setting[:value], invoicing_profile: current_user.invoicing_profile)
updated_settings.push(db_setting)
end
elsif db_setting.value != setting[:value] && SettingService.save_and_update(db_setting, setting[:value], current_user)
updated_settings.push(db_setting)
end
else
db_setting.errors.add(:-, "#{I18n.t("settings.#{setting[:name]}")}: #{I18n.t('settings.locked_setting')}")
Expand Down
19 changes: 19 additions & 0 deletions app/services/setting_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ def check_before_update(setting)
check_home_scss(setting)
end

# @param setting [Setting]
# @param value [String]
# @param operator [User]
def save_and_update(setting, value, operator)
return false unless setting.save

val = parse_value(setting.name, value)
setting.history_values.create(value: val, invoicing_profile: operator.invoicing_profile)
end

# @param settings [Array<Setting>]
def run_after_update(settings)
update_theme_stylesheet(settings)
Expand All @@ -35,6 +45,14 @@ def run_after_update(settings)

private

# @param setting [String]
# @param value [String]
def parse_value(setting, value)
return value unless %w[booking_window_start booking_window_end].include?(setting)

Time.zone.parse(value)
end

# rebuild the theme stylesheet
# @param settings [Array<Setting>]
def update_theme_stylesheet(settings)
Expand All @@ -44,6 +62,7 @@ def update_theme_stylesheet(settings)
end

# validate that the provided SCSS has a valid syntax
# @param setting [Hash{Symbol->String}]
def check_home_scss(setting)
return nil unless setting[:name] == 'home_css'

Expand Down

0 comments on commit ef78e4a

Please sign in to comment.