diff --git a/app/mailers/proposition_mailer.rb b/app/mailers/proposition_mailer.rb new file mode 100644 index 0000000..bd043b7 --- /dev/null +++ b/app/mailers/proposition_mailer.rb @@ -0,0 +1,7 @@ +# coding: utf-8 +class PropositionMailer < ActionMailer::Base + def new_proposition_notification(proposition) + @proposition = proposition + mail(to: proposition.proposable.conference.email, subject: "Ново предложение за #{@proposition.proposable_type}: #{@proposition.proposable_title}") + end +end diff --git a/app/models/concerns/proposable.rb b/app/models/concerns/proposable.rb index c1f35e7..6da37b1 100644 --- a/app/models/concerns/proposable.rb +++ b/app/models/concerns/proposable.rb @@ -4,9 +4,25 @@ module Proposable included do has_one :proposition, as: :proposable has_one :proposer, through: :proposition + delegate :email, to: :proposer, prefix: true Proposition.defined_enums["status"].keys.each do |status| scope status.to_sym, -> { joins(:proposition).where(propositions: {status: Proposition.defined_enums["status"][status]}) } end end + + def proposable_type + self.class.model_name.human + end + + def notification_email + conference.email + end + + def proposable_title + title + end + + def proposable_description + end end diff --git a/app/models/event.rb b/app/models/event.rb index 2d86869..5edc660 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -33,6 +33,24 @@ class Event < ActiveRecord::Base read_attribute(:length) || event_type.try(:minimum_length) end + def proposable_type + event_type.name + end + + def proposable_description + { + proposer_email: proposer_email, + title: title, + subtitle: subtitle, + track: track.name, + length: "#{length} m", + language: language, + abstract: abstract, + description: description, + notes: notes + } + end + private def track_belongs_to_the_selected_conference diff --git a/app/models/proposition.rb b/app/models/proposition.rb index dd62544..0a3f365 100644 --- a/app/models/proposition.rb +++ b/app/models/proposition.rb @@ -3,4 +3,10 @@ class Proposition < ActiveRecord::Base belongs_to :proposable, polymorphic: true enum status: [:undecided, :approved, :rejected, :backup] + + delegate :proposable_title, :proposable_type, :proposable_description, to: :proposable + + def send_creation_notification + PropositionMailer.new_proposition_notification(self).deliver_later + end end diff --git a/app/views/proposition_mailer/new_proposition_notification.text.erb b/app/views/proposition_mailer/new_proposition_notification.text.erb new file mode 100644 index 0000000..1720a11 --- /dev/null +++ b/app/views/proposition_mailer/new_proposition_notification.text.erb @@ -0,0 +1,8 @@ +Здравейте, + +Беше получено следното предложение за <%= @proposition.proposable_type %>: + +<% @proposition.proposable_description.each do |key, value| %> +<%= @proposition.proposable.class.human_attribute_name(key) %>: <%= value %> + +<% end %> diff --git a/app/views/proposition_mailer/new_proposition_notification.text.slim b/app/views/proposition_mailer/new_proposition_notification.text.slim new file mode 100644 index 0000000..dc9ff45 --- /dev/null +++ b/app/views/proposition_mailer/new_proposition_notification.text.slim @@ -0,0 +1,3 @@ +PropositionMailer#new_proposition_notification + += @greeting + ", find me in app/views/proposition_mailer/new_proposition_notification.text.slim"