class Notifier

Clase para las notificaciones por email

Constants

FROM
FROM_EMAIL
REPLY_TO
SERVICENAME
SERVICEURL

Public Instance Methods

activate_person_account(user) click to toggle source

Confirmación de identidad de un usuario. Se le envía un email con enlace para activar su cuenta

# File app/models/notifier.rb, line 82
def activate_person_account(user)
  @recipients = user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.welcome_person')}"
  @body["user"] = user
end
activate_person_from_proposal(user) click to toggle source

Confirmación de identidad de un usuario desde la creacion de una propuesta. Se le envía un email con enlace para activar su cuenta

# File app/models/notifier.rb, line 91
def activate_person_from_proposal(user)
  @recipients = user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.welcome_person_from_proposal')}"
  @body["user"] = user
end
contact(sender_name, sender_email, message) click to toggle source

Formulario de contacto

# File app/models/notifier.rb, line 58
def contact(sender_name, sender_email, message)
  # Email header info MUST be added here
  @recipients = "irekia@ej-gv.es"
  @from = Notifier::FROM
  @headers['Reply-to'] = "#{sender_name} <#{sender_email}>"
  @subject = "[#{Notifier::SERVICENAME}] Danos tu opinión"

  # Email body substitutions go here
  @body["sender_name"] = sender_name
  @body["sender_email"] = sender_email
  @body["message"] = message
end
email_document(sender_name, recipient_name, recipient_email, document) click to toggle source

Enviar por email una noticia a un amigo

# File app/models/notifier.rb, line 44
def email_document(sender_name, recipient_name, recipient_email, document)
  # Email header info MUST be added here
  @recipients = recipient_email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('share.te_recomienda', :sender_name => sender_name)}"

  # Email body substitutions go here
  @body["sender_name"] = sender_name
  @body["recipient_name"] = recipient_name
  @body["document"] = document
end
journalist_event_alert(event_alert) click to toggle source

Email de alerta de evento para periodistas

# File app/models/notifier.rb, line 100
def journalist_event_alert(event_alert)
  @recipients = event_alert.spammable.email
  @headers['Reply-to'] = Notifier::REPLY_TO
  @from = Notifier::FROM
  @content_type = "multipart/alternative" 

  event_title = event_alert.event.send("title_#{event_alert.spammable.alerts_locale}").present? ? event_alert.event.send("title_#{event_alert.spammable.alerts_locale}") : event_alert.event.title 
  @subject = "[#{Notifier::SERVICENAME}] #{event_title}"
  
  part "text/plain" do |p| 
    p.body = render_message("journalist_event_alert", :event_alert => event_alert, :event_title => event_title)  
  end 

  unless event_alert.event.deleted?
    attachment "text/calendar" do |a|
      event_ics = RiCal.Calendar do |cal|
        cal.add_x_property('X-WR-CALNAME','Irekia::Eventos')
        event_alert.event.to_ics(cal) {{:url => url_for(:controller => "/ma/events", :action => "show", :id => event_alert, :only_path => false, :host => Notifier::SERVICEURL)}}
      end
      a.body = event_ics.to_s
      a.filename = "event#{event_alert.event_id}.ics"
    end    
  end
end
new_proposal(proposal) click to toggle source
# File app/models/notifier.rb, line 168
def new_proposal(proposal)
  @recipients = Contribution::MODERATORS
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] Nueva propuesta en Irekia"
  @body["proposal"] = proposal
end
new_question(question) click to toggle source
# File app/models/notifier.rb, line 204
def new_question(question)
  @recipients = Contribution::MODERATORS
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] Nueva pregunta en Irekia"
  @body["question"] = question
end
password_reminder(user) click to toggle source

Recordatorio de contraseña

# File app/models/notifier.rb, line 32
def password_reminder(user)
  # Email header info MUST be added here
  @recipients = user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.info_acceso')}"

  # Email body substitutions go here
  @body["user"] = user
end
proposal_approval(proposal) click to toggle source
# File app/models/notifier.rb, line 185
def proposal_approval(proposal)
  @recipients = proposal.user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.proposal_approval.subject')}"
  @body["proposal"] = proposal    
end
proposal_organization(proposal) click to toggle source
# File app/models/notifier.rb, line 176
def proposal_organization(proposal)
  department = proposal.organization.department
  @recipients = department.department_editors.collect(&:email) + department.department_members_official_commenters.collect(&:email)
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] Nueva propuesta en Irekia"
  @body["proposal"] = proposal
end
proposal_rejection(proposal) click to toggle source

Email que avisa a un comentarista de que su comentario ha sido rechazado

# File app/models/notifier.rb, line 194
def proposal_rejection(proposal)
  @recipients = proposal.user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.propuesta_rechazado')}"

  # Email body substitutions go here
  @body["proposal"] = proposal
end
question_approval(question) click to toggle source
# File app/models/notifier.rb, line 237
def question_approval(question)
  @recipients = question.user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.question_approval.subject')}"
  @body["question"] = question
end
question_organization(question) click to toggle source

def new_question_for_politician(question)

@recipients = question.for_whom.email
@from = Notifier::FROM
@headers['Reply-to'] = Notifier::REPLY_TO
@subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.new_question_for_politician.subject', :locale => question.for_whom.alerts_locale)}"
@body["question"] = question

end

# File app/models/notifier.rb, line 220
def question_organization(question)
  department = question.organization.department
  @recipients = department.department_editors.collect(&:email) + department.department_members_official_commenters.collect(&:email)
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] Nueva pregunta en Irekia"
  @body["question"] = question
end
question_receiver(question) click to toggle source
# File app/models/notifier.rb, line 229
def question_receiver(question)
  @recipients = question.for_whom.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.new_question_for_politician.subject', :locale => question.for_whom.alerts_locale)}"
  @body["question"] = question
end
rejected_comment(comment) click to toggle source

Email que avisa a un comentarista de que su comentario ha sido rechazado

# File app/models/notifier.rb, line 158
def rejected_comment(comment)
  @recipients = comment.user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.comentario_rechazado')}"

  # Email body substitutions go here
  @body["comment"] = comment
end
staff_event_alert(event_alert) click to toggle source

Email de alerta de evento con streaming, para responsable de sala o operador de streaming

# File app/models/notifier.rb, line 126
def staff_event_alert(event_alert)
  @recipients = event_alert.spammable.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @content_type = "multipart/alternative" 

  locale = event_alert.spammable.respond_to?("alerts_locale") ? event_alert.spammable.alerts_locale : "es"
  title = event_alert.event.send("title_#{locale}").present? ? event_alert.event.send("title_#{locale}").tildes : event_alert.event.title.tildes
  notify_about = event_alert.notify_about.eql?('coverage') ? 'cobertura' : 'streaming'
  @subject = "[#{Notifier::SERVICENAME}] Notificacion sobre #{notify_about} a #{User::TYPES[event_alert.spammable_type]}"
  
  part "text/plain" do |p| 
    p.body = render_message("staff_event_alert", :event_alert => event_alert)  
  end 

  # Enviamos el ics como attachement.
  unless event_alert.event.deleted?
    attachment "text/calendar" do |a|
      event_ics = RiCal.Calendar do |cal|
        cal.add_x_property('X-WR-CALNAME','Irekia::Eventos')
        event_alert.event.to_ics(cal) {
          {:url => url_for(:controller => "/sadmin/events", :action => "show", :id => event_alert, :only_path => false, :host => Notifier::SERVICEURL), 
           :description => render_message("staff_event_alert", :event_alert => event_alert)}
        }
      end
      a.body = event_ics.to_s
      a.filename = "event#{event_alert.event_id}.ics"
    end    
  end
end
welcome_journalist(user) click to toggle source

Email de bienvenida a un periodista. Se envía al aprobar a un periodista, y se le manda la contraseña que se le acaba de generar

# File app/models/notifier.rb, line 73
def welcome_journalist(user)
  @recipients = user.email
  @from = Notifier::FROM
  @headers['Reply-to'] = Notifier::REPLY_TO
  @subject = "[#{Notifier::SERVICENAME}] #{I18n.t('notifier.welcome_journalist', :name => I18n.t('site_name'))}"
  @body["user"] = user
end