docbrown/app/models/users/setting.rb
Ridhwana 4848a8b2e1
User Settings Step 1: Add user_settings and user_notification_settings tables (rfc#32) (#12768)
* feat: add the two new models users_setting and users_notification_setting

* feat: add the settings and notification_settings table to the schema

* feat: add the user and notification models

* feat: add the user_id foreign key to the model

* chore: sneaky indent

* feat: add some fields from the profile attributes

* Revert "feat: add some fields from the profile attributes"

This reverts commit 376828746ded063a243505d317140fa5339227cf.

* chore: add some profile field attributes

* chore: remove language_settings

* chore: update indent

* chore: remove language_settings

* feat: changes to the tables

* chore:  remove validation in favor of the foreign keys

* chore: add default for editor version

* Address PR review suggestions

* setting_spec.rb needs to be fixed; need help

* Working on PR review comments

* Continue with addressing PR review comments

* Remove normalize_config_values method; pass correct values from forms

* Address Travis failures

* revert some unnecessary changes in spec file

Co-authored-by: Arit Amana <msarit@gmail.com>
2021-03-31 14:37:46 +02:00

33 lines
1.2 KiB
Ruby

module Users
class Setting < ApplicationRecord
self.table_name_prefix = "users_"
belongs_to :user
enum editor_version: { v2: 0, v1: 1 }, _suffix: :editor
enum config_font: { default: 0, comic_sans: 1, monospace: 2, open_dyslexic: 3, sans_serif: 4, serif: 5 }
enum inbox_type: { private: 0, open: 1 }, _suffix: :inbox
enum config_navbar: { default_navbar: 0, static_navbar: 1 }
enum config_theme: { default_theme: 0, minimal_light_theme: 1, night_theme: 2, pink_theme: 3,
ten_x_hacker_theme: 4 }
validates :user_id, presence: true
validates :experience_level, numericality: { less_than_or_equal_to: 10 }, allow_blank: true
validates :feed_referential_link, inclusion: { in: [true, false] }
validates :feed_url, length: { maximum: 500 }, allow_nil: true
validates :inbox_guidelines, length: { maximum: 250 }, allow_nil: true
validate :validate_feed_url, if: :feed_url_changed?
private
def validate_feed_url
return if feed_url.blank?
valid = Feeds::ValidateUrl.call(feed_url)
errors.add(:feed_url, "is not a valid RSS/Atom feed") unless valid
rescue StandardError => e
errors.add(:feed_url, e.message)
end
end
end