2018-08-02 00:09:29 +02:00
|
|
|
# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Jeremy Lecour <jlecour@evolix.fr>, 2018 Evolix <info@evolix.fr>
|
|
|
|
# License: GNU AGPL-3+ (see full text in LICENSE file)
|
2018-05-31 20:49:06 +02:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: notifications
|
|
|
|
#
|
2018-08-30 11:07:17 +02:00
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
# channel :integer default("email"), not null
|
|
|
|
# checks_count :integer default(0), not null
|
|
|
|
# interval :integer not null
|
|
|
|
# label :string(255)
|
|
|
|
# recipient :string(255) not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# check_id :bigint(8)
|
|
|
|
# user_id :bigint(8)
|
2018-05-31 20:49:06 +02:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_notifications_on_check_id (check_id)
|
2018-08-30 11:07:17 +02:00
|
|
|
# index_notifications_on_user_id (user_id)
|
2018-05-31 20:49:06 +02:00
|
|
|
#
|
|
|
|
# Foreign Keys
|
|
|
|
#
|
|
|
|
# fk_rails_... (check_id => checks.id)
|
2018-08-30 11:07:17 +02:00
|
|
|
# fk_rails_... (user_id => users.id)
|
2018-05-31 20:49:06 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
class Notification < ApplicationRecord
|
2018-08-30 11:08:37 +02:00
|
|
|
belongs_to :user
|
2018-08-31 10:06:16 +02:00
|
|
|
has_many :check_notifications, dependent: :destroy
|
|
|
|
has_many :checks, -> { order(domain_expires_at: :asc) }, through: :check_notifications
|
2018-05-31 20:49:06 +02:00
|
|
|
|
2018-06-04 14:06:37 +02:00
|
|
|
enum channel: [:email]
|
2018-05-31 20:49:06 +02:00
|
|
|
|
|
|
|
validates :channel, presence: true
|
2018-06-05 22:44:48 +02:00
|
|
|
validates :interval, numericality: { only_integer: true, greater_than_or_equal_to: 1 }
|
2018-06-04 14:06:37 +02:00
|
|
|
validates :recipient, presence: true
|
2018-08-30 20:09:52 +02:00
|
|
|
|
|
|
|
def notifical_label
|
|
|
|
return label if label.present?
|
|
|
|
|
|
|
|
"#{recipient} (#{interval})"
|
|
|
|
end
|
2018-05-31 20:49:06 +02:00
|
|
|
end
|