Project

General

Profile

Can you help me to make a plugin out of this "source" modification?

Added by Jorge S. over 10 years ago

First of all, I don't know almost anything about ruby, had to Google some syntax.

I know PHP and ActiveRecord framework Yii.

I needed to email people that is part of a project, whenever a version was closed.

It is really basic, not much of "I want to be notified" mark for it, but hardcoded for all users. I would like to make it part of a plugin.

models/mailer.rb

# Notificar version cerrada
  def version_closed(version)
    redmine_headers 'Project' => version.project.identifier
    @author = User.current
    @version = version
    @version_url = url_for(:controller => 'versions', :action => 'show', :id => version.id)
    mail :to => version.recipients,
      :subject => "Version cerrada: #{version.name}" 
  end

models/version.rb


after_save :enviar_aviso_version_cerrada

def enviar_aviso_version_cerrada
    logger.info(YAML::dump(self))
    if closed?
    then
      Mailer.version_closed(self).deliver
    end
  end

  def recipients
    project.recipients_closed_project_version
  end

models/project.rb

  # Los mails de todos los usuarios del proyecto
    def recipients_closed_project_version
      notified_users_all.collect {|user| user.mail}
    end

    # Returns the users that should be notified on project events
    def notified_users_all
      members.select {|m| m.principal.present?}.collect {|m| m.principal}
    end

views/mailer/version_closed.html.erb (empty for now)
views/mailer/version_closed.text.erb (Empty for now)

Thanks a lot!