aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2011-08-20 16:48:33 +0200
committerAlex Legler <alex@a3li.li>2011-08-20 16:48:33 +0200
commit893c9f7af1b9e75a9262321752f29ae4cb510c26 (patch)
tree4839a97368a05f7df2ed07861d66fa8ef7da68bf
parentMigrate CVEController to rails3 (diff)
downloadglsamaker-893c9f7af1b9e75a9262321752f29ae4cb510c26.tar.gz
glsamaker-893c9f7af1b9e75a9262321752f29ae4cb510c26.tar.bz2
glsamaker-893c9f7af1b9e75a9262321752f29ae4cb510c26.zip
Migrate GLSAMailer to rails3
-rw-r--r--app/mailers/glsa_mailer.rb37
-rw-r--r--app/models/glsa_mailer.rb57
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/glsa_mailer/approval.text.erb (renamed from app/views/glsa_mailer/approval.erb)6
-rw-r--r--app/views/glsa_mailer/comment.text.erb (renamed from app/views/glsa_mailer/comment.erb)4
-rw-r--r--app/views/glsa_mailer/edit.erb6
-rw-r--r--app/views/glsa_mailer/edit.text.erb8
-rw-r--r--app/views/glsa_mailer/new_request.text.erb (renamed from app/views/glsa_mailer/request.erb)4
-rw-r--r--app/views/glsa_mailer/sent.erb3
-rw-r--r--app/views/glsa_mailer/text.text.erb (renamed from app/views/glsa_mailer/text.erb)0
-rw-r--r--config/initializers/glsamaker.rb.sample3
-rw-r--r--lib/glsamaker/mail.rb10
-rw-r--r--test/functional/glsa_mailer_test.rb7
13 files changed, 73 insertions, 76 deletions
diff --git a/app/mailers/glsa_mailer.rb b/app/mailers/glsa_mailer.rb
new file mode 100644
index 0000000..5027eaa
--- /dev/null
+++ b/app/mailers/glsa_mailer.rb
@@ -0,0 +1,37 @@
+class GlsaMailer < ActionMailer::Base
+ default :from => GLSAMAKER_FROM_EMAIL,
+ :content_type => 'text/plain'
+
+ def new_request(recipient, glsa, requestor)
+ @requestor = requestor
+ @glsa = glsa
+
+ mail(:to => recipient.email,
+ :subject => "[GLSAMaker] New request: #{glsa.last_revision.title}")
+ end
+
+ def edit(recipient, glsa, diff, editor)
+ @editor = editor
+ @diff = diff
+ @glsa = glsa
+
+ mail(:to => recipient.email,
+ :subject => "[GLSAMaker] Draft edit: #{glsa.last_revision.title}")
+ end
+
+ def comment(recipient, glsa, comment, commentator)
+ @commentator = commentator
+ @comment = comment
+ @glsa = glsa
+
+ mail(:to => recipient.email,
+ :subject => "[GLSAMaker] Draft commented: #{glsa.last_revision.title}")
+ end
+
+ def approval(recipient, glsa)
+ @glsa = glsa
+
+ mail(:to => recipient.email,
+ :subject => "[GLSAMaker] Draft approved: #{glsa.last_revision.title}")
+ end
+end
diff --git a/app/models/glsa_mailer.rb b/app/models/glsa_mailer.rb
deleted file mode 100644
index 61db1da..0000000
--- a/app/models/glsa_mailer.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-class GlsaMailer < ActionMailer::Base
-
- def request(user, glsa, edit_user)
- subject "[GLSAMaker] New request: '#{glsa.last_revision.title}'"
- recipients user.email
- from GLSAMAKER_FROM_EMAIL
- sent_on Time.now
-
- body :glsa => glsa, :user => edit_user
- end
-
- def edit(user, glsa, diff, edit_user)
- subject "[GLSAMaker] Draft edit: '#{glsa.last_revision.title}'"
- recipients user.email
- from GLSAMAKER_FROM_EMAIL
- sent_on Time.now
-
- body :glsa => glsa, :diff => diff, :user => edit_user
- end
-
- def comment(user, glsa, comment, edit_user)
- subject "[GLSAMaker] Draft commented: '#{glsa.last_revision.title}'"
- recipients user.email
- from GLSAMAKER_FROM_EMAIL
- sent_on Time.now
-
- body :glsa => glsa, :comment => comment, :user => edit_user
- end
-
- def approval(user, glsa)
- subject "[GLSAMaker] Draft approved: '#{glsa.last_revision.title}'"
- recipients user.email
- from GLSAMAKER_FROM_EMAIL
- sent_on Time.now
-
- body :glsa => glsa
- end
-
- def sent(sent_at = Time.now)
- subject 'GlsaMailer#sent'
- recipients ''
- from ''
- sent_on sent_at
-
- body :greeting => 'Hi,'
- end
-
- def text(user, _subject, text, footer)
- subject _subject
- recipients user.email
- from GLSAMAKER_FROM_EMAIL
- sent_on Time.now
-
- body :text => text, :footer => footer
- end
-
-end
diff --git a/app/models/user.rb b/app/models/user.rb
index cd6ce59..be737e0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -47,6 +47,10 @@ class User < ActiveRecord::Base
true
end
+
+ def to_s
+ "#{name} (#{login})"
+ end
# Returns a certain category form the user's preferences
# or an empty hash if that category does not exist
diff --git a/app/views/glsa_mailer/approval.erb b/app/views/glsa_mailer/approval.text.erb
index 4b0e13f..939e07c 100644
--- a/app/views/glsa_mailer/approval.erb
+++ b/app/views/glsa_mailer/approval.text.erb
@@ -3,19 +3,19 @@ Your draft is now approved.
Approval overview
-----------------
<% @glsa.approvals.each do |approval| -%>
-<%= approval.created_at.rfc2822 %> by <%= approval.user.login %>
+<%= approval.created_at.rfc2822 %> by <%= approval.user.to_s %>
<% end -%>
<% if @glsa.rejections.count > 0 -%>
Rejection overview
------------------
<% @glsa.rejections.each do |rejection| -%>
-<%= rejection.created_at.rfc2822 %> by <%= rejection.user.login %>
+<%= rejection.created_at.rfc2822 %> by <%= rejection.user.to_s %>
<% end -%>
<% end -%>
You should check whether all bugs linked in the draft are in a bug ready state.
-Then, you can release the advisory.
+Then, you can release the advisory at <%= prepare_release_glsa_url(@glsa) %>
Thanks for your work!
diff --git a/app/views/glsa_mailer/comment.erb b/app/views/glsa_mailer/comment.text.erb
index 2e40122..901eede 100644
--- a/app/views/glsa_mailer/comment.erb
+++ b/app/views/glsa_mailer/comment.text.erb
@@ -1,4 +1,6 @@
-Your draft received a comment (<%= @comment.rating %>) from <%= @user.login %> @ <%= @comment.created_at.rfc2822 %>:
+Your draft received a comment (<%= @comment.rating %>) from <%= @commentator.to_s %> @ <%= @comment.created_at.rfc2822 %>:
+
+<%= glsa_url(@glsa) %>
<%= @comment.text %>
diff --git a/app/views/glsa_mailer/edit.erb b/app/views/glsa_mailer/edit.erb
deleted file mode 100644
index 000ea1d..0000000
--- a/app/views/glsa_mailer/edit.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-The draft was edited by <%= @user.login %> @ <%= @glsa.last_revision.created_at.rfc2822 %>:
-
-<%= @diff %>
-
---
-This email notification is brought to you by GLSAMaker 2. \ No newline at end of file
diff --git a/app/views/glsa_mailer/edit.text.erb b/app/views/glsa_mailer/edit.text.erb
new file mode 100644
index 0000000..cf45a06
--- /dev/null
+++ b/app/views/glsa_mailer/edit.text.erb
@@ -0,0 +1,8 @@
+The draft was edited by <%= @editor.to_s %> @ <%= @glsa.last_revision.created_at.rfc2822 %>:
+
+<%= glsa_url(@glsa) %>
+
+<%= @diff.html_safe %>
+
+--
+This email notification is brought to you by GLSAMaker 2. \ No newline at end of file
diff --git a/app/views/glsa_mailer/request.erb b/app/views/glsa_mailer/new_request.text.erb
index 6ec1e5b..dadb8d0 100644
--- a/app/views/glsa_mailer/request.erb
+++ b/app/views/glsa_mailer/new_request.text.erb
@@ -1,8 +1,10 @@
-A new request was filed by <%= @user.login %> @ <%= @glsa.last_revision.created_at.rfc2822 %>:
+A new request was filed by <%= @requestor.to_s %> @ <%= @glsa.last_revision.created_at.rfc2822 %>:
<%= @glsa.last_revision.title %>
<%= "-" * @glsa.last_revision.title.length %>
+<%= glsa_url(@glsa) %>
+
Bugs:
<% @glsa.last_revision.bugs.each do |bug| %>
* <%= bug.bug_id %><%= " (#{bug.title})" if bug.title %>
diff --git a/app/views/glsa_mailer/sent.erb b/app/views/glsa_mailer/sent.erb
deleted file mode 100644
index e7a8755..0000000
--- a/app/views/glsa_mailer/sent.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-GlsaMailer#sent
-
-Find me in app/views/glsa_mailer/sent.erb
diff --git a/app/views/glsa_mailer/text.erb b/app/views/glsa_mailer/text.text.erb
index 8279bb9..8279bb9 100644
--- a/app/views/glsa_mailer/text.erb
+++ b/app/views/glsa_mailer/text.text.erb
diff --git a/config/initializers/glsamaker.rb.sample b/config/initializers/glsamaker.rb.sample
index 1dfef77..38bb156 100644
--- a/config/initializers/glsamaker.rb.sample
+++ b/config/initializers/glsamaker.rb.sample
@@ -19,6 +19,9 @@ GLSAMAKER_FROM_EMAIL = "glsamaker@gentoo.org"
# Do not send any emails (for development)
GLSAMAKER_NO_EMAIL = false
+# Where does the app live?
+GLSAMAKER_HOST = "localhost:3000"
+
# Location of the Portage tree, that can be a full gentoo tree, or what this gets you:
#
# rsync -av rsync://rsync1.de.gentoo.org/gentoo-portage --include 'metadata' \
diff --git a/lib/glsamaker/mail.rb b/lib/glsamaker/mail.rb
index d3ab36b..dca02a2 100644
--- a/lib/glsamaker/mail.rb
+++ b/lib/glsamaker/mail.rb
@@ -1,5 +1,5 @@
# ===GLSAMaker v2
-# Copyright (C) 2010 Alex Legler <a3li@gentoo.org>
+# Copyright (C) 2010-11 Alex Legler <a3li@gentoo.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -21,7 +21,7 @@ module Glsamaker
next unless rcpt.can_access? glsa
unless rcpt.get_pref_category(:mail)[:edit] == false
- GlsaMailer.deliver_edit(rcpt, glsa, diff, user)
+ GlsaMailer.edit(rcpt, glsa, diff, user).deliver
end
end
end
@@ -36,7 +36,7 @@ module Glsamaker
next unless rcpt.can_access? glsa
unless rcpt.get_pref_category(:mail)[:request] == false
- GlsaMailer.deliver_request(rcpt, glsa, user)
+ GlsaMailer.new_request(rcpt, glsa, user).deliver
end
end
end
@@ -52,7 +52,7 @@ module Glsamaker
return if rcpt == user
unless rcpt.get_pref_category(:mail)[:comment] == false
- GlsaMailer.deliver_comment(rcpt, glsa, comment, user)
+ GlsaMailer.comment(rcpt, glsa, comment, user).deliver
end
end
@@ -66,7 +66,7 @@ module Glsamaker
return unless rcpt.can_access? glsa
unless rcpt.get_pref_category(:mail)[:comment] == false
- GlsaMailer.deliver_approval(rcpt, glsa)
+ GlsaMailer.approval(rcpt, glsa).deliver
end
end
diff --git a/test/functional/glsa_mailer_test.rb b/test/functional/glsa_mailer_test.rb
new file mode 100644
index 0000000..5963931
--- /dev/null
+++ b/test/functional/glsa_mailer_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class GlsaMailerTest < ActionMailer::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end