Index: app/models/mailer.rb =================================================================== --- app/models/mailer.rb (revision 4362) +++ app/models/mailer.rb (working copy) @@ -271,6 +271,20 @@ render_multipart('test', body) end + # Builds a tmail object used to email users belonging to the changeset's project. + # + # Example: + # changeset(change) => tmail object + # Mailer.deliver_changeset(change) => sends an email to the changeset's project recipients + def changeset(change) + redmine_headers 'Project' => change.project.identifier + recipients change.recipients + subject "[#{change.project.name}] #{change.title}" + body :change => change, + :change_url => url_for(:controller => 'repositories', :action => 'revision', :id => change.repository.project, :rev => change.revision) + render_multipart('changeset', body) + end + # Overrides default deliver! method to prevent from sending an email # with no recipient, cc or bcc def deliver!(mail = @mail) Index: app/models/changeset.rb =================================================================== --- app/models/changeset.rb (revision 4362) +++ app/models/changeset.rb (working copy) @@ -152,6 +152,42 @@ to_utf8(str.to_s.strip) end + # needed by Mailer + def visible?(user=nil) + (user || User.current).allowed_to?(:view_changesets, self.project) + end + + def title + "#{l(:label_revision)} #{self.revision}" + (self.short_comments.blank? ? '' : (': ' + self.short_comments)) + end + + def datetime + self[:committed_on] + end + + def path + self[:from_path] + end + + def diff + @path = self.path + @rev = self[:from_revision] + @rev_to = self.revision + @diff = repository.diff(@path, @rev_to, @rev) + if @diff + return "#{@diff.join}" + end + + end + + def recipients + notified = project.notified_users + notified << author if author && author.active? && author.notify_about?(self) + notified.uniq! + notified.reject! {|user| !visible?(user)} + notified.collect(&:mail) + end + # Creates a new Change from it's common parameters def create_change(change) Change.create(:changeset => self, @@ -159,6 +195,7 @@ :path => change[:path], :from_path => change[:from_path], :from_revision => change[:from_revision]) + Mailer.deliver_changeset(self) end private