mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: Add timezone to core user_options (#8380)
* Add timezone to user_options table * Also migrate existing timezone values from UserCustomField, which is where the discourse-calendar plugin is storing them * Allow user to change their core timezone from Profile * Auto guess & set timezone on login & invite accept & signup * Serialize user_options.timezone for group members. this is so discourse-group-timezones can access the core user timezone, as it is being removed in discourse-calendar. * Annotate user_option with timezone * Validate timezone values
This commit is contained in:
22
lib/validators/timezone_validator.rb
Normal file
22
lib/validators/timezone_validator.rb
Normal file
@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TimezoneValidator < ActiveModel::EachValidator
|
||||
def self.valid?(value)
|
||||
ok = ActiveSupport::TimeZone[value].present?
|
||||
Rails.logger.warn("Invalid timezone '#{value}' detected!") if !ok
|
||||
ok
|
||||
end
|
||||
|
||||
def self.error_message(value)
|
||||
I18n.t("errors.messages.invalid_timezone", tz: value)
|
||||
end
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
return if value.blank? || TimezoneValidator.valid?(value)
|
||||
record.errors.add(
|
||||
attribute,
|
||||
:timezone,
|
||||
message: TimezoneValidator.error_message(value)
|
||||
)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user