2014-08-06 14:47:47 +02:00
|
|
|
# Groups related to this agenda
|
2015-02-15 17:10:17 +01:00
|
|
|
class Orga < ActiveRecord::Base
|
2015-07-25 18:32:27 +02:00
|
|
|
has_paper_trail
|
|
|
|
|
2015-02-15 15:50:47 +01:00
|
|
|
belongs_to :region
|
2015-02-28 17:28:05 +01:00
|
|
|
belongs_to :kind
|
|
|
|
|
|
|
|
validates :kind, presence: true
|
|
|
|
validates :name, presence: true
|
|
|
|
validates :region, presence: true
|
|
|
|
validates :url, format: %r{\Ahttps?:\/\/.*\..*\z}
|
|
|
|
validates :feed, allow_blank: true, format: %r{\Ahttps?:\/\/.*\..*\z}
|
2015-05-25 11:42:53 +02:00
|
|
|
validates :contact, presence: true, email: true
|
2015-02-28 17:28:05 +01:00
|
|
|
validates :submitter, allow_blank: true, email: true
|
|
|
|
|
2015-07-25 18:32:27 +02:00
|
|
|
scope :moderated, -> { where moderated: true }
|
|
|
|
scope :unmoderated, -> { where moderated: false }
|
|
|
|
|
2015-05-25 11:42:53 +02:00
|
|
|
before_validation do
|
|
|
|
self.secret ||= SecureRandom.urlsafe_base64(32)[0...32]
|
|
|
|
self.submission_time ||= Time.zone.now
|
2015-02-28 17:28:05 +01:00
|
|
|
|
|
|
|
# Populate submitter using contact info if absent
|
|
|
|
self.submitter ||= contact
|
|
|
|
end
|
2015-07-25 18:32:27 +02:00
|
|
|
|
|
|
|
after_create do
|
|
|
|
send_secret
|
|
|
|
end
|
|
|
|
|
2015-09-05 18:56:48 +02:00
|
|
|
after_update do
|
2015-07-25 18:32:27 +02:00
|
|
|
send_secret if secret_changed?
|
|
|
|
|
|
|
|
if moderated_changed?
|
|
|
|
OrgaMailer.accept(self).deliver_now!
|
2015-09-05 18:56:48 +02:00
|
|
|
else
|
2015-07-25 18:32:27 +02:00
|
|
|
OrgaMailer.update(self).deliver_now!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before_destroy do
|
|
|
|
OrgaMailer.destroy(self).deliver_now!
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_secret
|
|
|
|
OrgaMailer.create(self).deliver_now!
|
|
|
|
end
|
2013-12-28 15:45:21 +01:00
|
|
|
end
|