Organisation submitter is set to the contact if empty
This commit is contained in:
parent
cbba590d4f
commit
f6e43ce10e
@ -35,31 +35,29 @@ class Orga < ActiveRecord::Base
|
||||
scope :geo, -> { where 'latitude is not null and longitude is not null' }
|
||||
|
||||
before_validation do
|
||||
unless submitter.blank?
|
||||
self.secret ||= SecureRandom.urlsafe_base64(32)[0...32]
|
||||
end
|
||||
# Populate submitter using contact info if absent
|
||||
self.submitter ||= contact
|
||||
self.secret ||= SecureRandom.urlsafe_base64(32)[0...32]
|
||||
self.submission_time ||= Time.zone.now
|
||||
end
|
||||
|
||||
after_create do
|
||||
send_secret unless submitter.blank?
|
||||
send_secret
|
||||
# Send email to moderators when an new orga is received
|
||||
ModerationorgaMailer.create(self).deliver_now!
|
||||
end
|
||||
|
||||
after_update do
|
||||
unless submitter.blank?
|
||||
send_secret if secret_changed?
|
||||
send_secret if secret_changed? || submitter_changed?
|
||||
|
||||
if moderated_changed?
|
||||
OrgaMailer.accept(self).deliver_now!
|
||||
# Send email to moderators when an orga is accepted
|
||||
ModerationorgaMailer.accept(self).deliver_now!
|
||||
else
|
||||
OrgaMailer.update(self).deliver_now!
|
||||
# Send email to moderators when an orga is updated
|
||||
ModerationorgaMailer.update(self).deliver_now!
|
||||
end
|
||||
if moderated_changed?
|
||||
OrgaMailer.accept(self).deliver_now!
|
||||
# Send email to moderators when an orga is accepted
|
||||
ModerationorgaMailer.accept(self).deliver_now!
|
||||
else
|
||||
OrgaMailer.update(self).deliver_now!
|
||||
# Send email to moderators when an orga is updated
|
||||
ModerationorgaMailer.update(self).deliver_now!
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -20,17 +20,6 @@ class OrgaTest < ActiveSupport::TestCase
|
||||
tags: 'hello world'
|
||||
)
|
||||
end
|
||||
|
||||
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
|
||||
Orga.create!(
|
||||
kind: Kind.first,
|
||||
name: 'Tested organisation',
|
||||
url: 'http://example.com',
|
||||
region: Region.first,
|
||||
contact: 'contact@example.com',
|
||||
tags: 'hello world'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
test 'set and send secret' do
|
||||
|
Loading…
Reference in New Issue
Block a user