diff options
author | Sean McGivern <sean@gitlab.com> | 2017-06-06 19:37:15 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-06-15 17:14:45 +0300 |
commit | f4b5fcbca100769b89e6b06e0df180012d16a7a8 (patch) | |
tree | 7b1cb582647cbbbdabf5521e1c1055e3f89f53e4 /app/models/notification_setting.rb | |
parent | 051b8dc4e3d055f7ac848a80d26bf1e6e0af2e24 (diff) |
Add columns for custom notification settings
Add columns for each custom notification level, defaulting to null. Read from
those columns if non-null, otherwise fall back to the serialized column. Writing
will write to the new column if `events` isn't manually set.
Diffstat (limited to 'app/models/notification_setting.rb')
-rw-r--r-- | app/models/notification_setting.rb | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index 42412a9a44b..2a53484f96f 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -41,10 +41,7 @@ class NotificationSetting < ActiveRecord::Base :success_pipeline ].freeze - store :events, accessors: EMAIL_EVENTS, coder: JSON - - before_create :set_events - before_save :events_to_boolean + store :events, coder: JSON def self.find_or_create_for(source) setting = find_or_initialize_by(source: source) @@ -56,20 +53,11 @@ class NotificationSetting < ActiveRecord::Base setting end - # Set all event attributes to false when level is not custom or being initialized for UX reasons - def set_events - return if custom? - - self.events = {} - end - - # Validates store accessors values as boolean - # It is a text field so it does not cast correct boolean values in JSON - def events_to_boolean - EMAIL_EVENTS.each do |event| - bool = ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(public_send(event)) + EMAIL_EVENTS.each do |event| + define_method(event) do + bool = super() - events[event] = bool + bool.nil? ? !!events[event] : bool end end @@ -77,7 +65,8 @@ class NotificationSetting < ActiveRecord::Base # custom notifications enabled, as these are more like mentions than the other # custom settings. def failed_pipeline - bool = super + bool = read_attribute(:failed_pipeline) + bool = events[:failed_pipeline] if bool.nil? bool.nil? || bool end |