1
0
şunun yansıması https://github.com/SonarSource/sonarqube.git eşitlendi 2024-07-28 08:17:45 +02:00

SONAR-2596,SONAR-2601 UI for email notifications

* Add email configuration to sidebar menu
* I18n for email and notifications settings
* Email configuration properties must be secured
* Rename sonar-email-plugin to sonar-email-notifications-plugin
Bu işleme şunda yer alıyor:
Evgeny Mandrikov 2011-07-26 14:25:57 +04:00
ebeveyn fea2ef37ed
işleme b508728dc8
23 değiştirilmiş dosya ile 114 ekleme ve 77 silme

Dosyayı Görüntüle

@ -10,10 +10,11 @@
</parent>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-email-plugin</artifactId>
<artifactId>sonar-email-notifications-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<name>Sonar :: Plugins :: Email</name>
<name>Sonar :: Plugins :: Email Notifications</name>
<description>Email Notifications</description>
<dependencies>
<dependency>
@ -53,9 +54,8 @@
<artifactId>sonar-packaging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<pluginName>Email</pluginName>
<pluginClass>org.sonar.plugins.email.EmailPlugin</pluginClass>
<pluginDescription><![CDATA[TODO]]></pluginDescription>
<pluginName>Email notifications</pluginName>
<pluginClass>org.sonar.plugins.emailnotifications.EmailNotificationsPlugin</pluginClass>
</configuration>
</plugin>
</plugins>

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email;
package org.sonar.plugins.emailnotifications;
import org.apache.commons.configuration.Configuration;
import org.sonar.api.CoreProperties;
@ -30,15 +30,15 @@ import org.sonar.api.ServerExtension;
*/
public class EmailConfiguration implements ServerExtension {
public static final String SMTP_HOST = "email.smtp_host";
public static final String SMTP_HOST = "email.smtp_host.secured";
public static final String SMTP_HOST_DEFAULT = "";
public static final String SMTP_PORT = "email.smtp_port";
public static final String SMTP_PORT = "email.smtp_port.secured";
public static final String SMTP_PORT_DEFAULT = "25";
public static final String SMTP_USE_TLS = "email.smtp_use_tls";
public static final String SMTP_USE_TLS = "email.smtp_use_tls.secured";
public static final boolean SMTP_USE_TLS_DEFAULT = false;
public static final String SMTP_USERNAME = "email.smtp_username";
public static final String SMTP_USERNAME = "email.smtp_username.secured";
public static final String SMTP_USERNAME_DEFAULT = "";
public static final String SMTP_PASSWORD = "email.smtp_password";
public static final String SMTP_PASSWORD = "email.smtp_password.secured";
public static final String SMTP_PASSWORD_DEFAULT = "";
public static final String FROM = "email.from";
public static final String FROM_DEFAULT = "noreply@nowhere";

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email;
package org.sonar.plugins.emailnotifications;
import java.net.MalformedURLException;
import java.net.URL;
@ -31,8 +31,8 @@ import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.security.UserFinder;
import org.sonar.plugins.email.api.EmailMessage;
import org.sonar.plugins.email.api.EmailTemplate;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailTemplate;
/**
* References:
@ -98,14 +98,14 @@ public class EmailNotificationChannel extends NotificationChannel {
LOG.warn("Email not defined for user: " + username);
return;
}
EmailMessage emailMessage = format(notification, username);
EmailMessage emailMessage = format(notification);
if (emailMessage != null) {
emailMessage.setTo(user.getEmail());
deliver(emailMessage);
}
}
private EmailMessage format(Notification notification, String username) {
private EmailMessage format(Notification notification) {
for (EmailTemplate template : templates) {
EmailMessage email = template.format(notification);
if (email != null) {

Dosyayı Görüntüle

@ -17,17 +17,17 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email;
package org.sonar.plugins.emailnotifications;
import org.sonar.api.SonarPlugin;
import org.sonar.plugins.email.reviews.ChangesInReviewAssignedToMe;
import org.sonar.plugins.email.reviews.ChangesInReviewCreatedByMe;
import org.sonar.plugins.email.reviews.ReviewEmailTemplate;
import org.sonar.plugins.emailnotifications.reviews.ChangesInReviewAssignedToMe;
import org.sonar.plugins.emailnotifications.reviews.ChangesInReviewCreatedByMe;
import org.sonar.plugins.emailnotifications.reviews.ReviewEmailTemplate;
import java.util.Arrays;
import java.util.List;
public class EmailPlugin extends SonarPlugin {
public class EmailNotificationsPlugin extends SonarPlugin {
public List getExtensions() {
return Arrays.asList(

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.api;
package org.sonar.plugins.emailnotifications.api;
import org.apache.commons.lang.builder.ToStringBuilder;

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.api;
package org.sonar.plugins.emailnotifications.api;
import org.sonar.api.ServerExtension;
import org.sonar.api.notifications.Notification;

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.reviews;
package org.sonar.plugins.emailnotifications.reviews;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.notifications.Notification;

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.reviews;
package org.sonar.plugins.emailnotifications.reviews;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.notifications.Notification;

Dosyayı Görüntüle

@ -17,15 +17,15 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.reviews;
package org.sonar.plugins.emailnotifications.reviews;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
import org.sonar.api.security.UserFinder;
import org.sonar.plugins.email.EmailConfiguration;
import org.sonar.plugins.email.api.EmailMessage;
import org.sonar.plugins.email.api.EmailTemplate;
import org.sonar.plugins.emailnotifications.EmailConfiguration;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailTemplate;
/**
* Creates email message for notification "review-changed".

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email;
package org.sonar.plugins.emailnotifications;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email;
package org.sonar.plugins.emailnotifications;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
@ -33,7 +33,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.sonar.plugins.email.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import com.dumbster.smtp.SimpleSmtpServer;
import com.dumbster.smtp.SmtpMessage;

Dosyayı Görüntüle

@ -17,18 +17,18 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email;
package org.sonar.plugins.emailnotifications;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertThat;
import org.junit.Test;
public class EmailPluginTest {
public class EmailNotificationsPluginTest {
@Test
public void testGetExtensions() {
assertThat(new EmailPlugin().getExtensions().size(), greaterThan(1));
assertThat(new EmailNotificationsPlugin().getExtensions().size(), greaterThan(1));
}
}

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.reviews;
package org.sonar.plugins.emailnotifications.reviews;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.reviews;
package org.sonar.plugins.emailnotifications.reviews;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

Dosyayı Görüntüle

@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.email.reviews;
package org.sonar.plugins.emailnotifications.reviews;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
@ -31,8 +31,8 @@ import org.junit.Test;
import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
import org.sonar.api.security.UserFinder;
import org.sonar.plugins.email.EmailConfiguration;
import org.sonar.plugins.email.api.EmailMessage;
import org.sonar.plugins.emailnotifications.EmailConfiguration;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
public class ReviewEmailTemplateTest {
@ -290,6 +290,8 @@ public class ReviewEmailTemplateTest {
*
* Status: RESOLVED (was REOPENED)
* Resolution: FALSE-POSITIVE
* Comment:
* Because!
*
* --
* See it in Sonar: http://nemo.sonarsource.org/review/view/1
@ -303,12 +305,13 @@ public class ReviewEmailTemplateTest {
.setFieldValue("old.status", "REOPENED")
.setFieldValue("old.resolution", null)
.setFieldValue("new.status", "RESOLVED")
.setFieldValue("new.resolution", "FALSE-POSITIVE");
.setFieldValue("new.resolution", "FALSE-POSITIVE")
.setFieldValue("new.comment", "Because!");
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("review/1"));
assertThat(message.getSubject(), is("Review #1"));
assertThat(message.getFrom(), is("Freddy Mallet"));
assertThat(message.getMessage(), is("Status: RESOLVED (was REOPENED)\nResolution: FALSE-POSITIVE\n\n--\nSee it in Sonar: http://nemo.sonarsource.org/review/view/1\n"));
assertThat(message.getMessage(), is("Status: RESOLVED (was REOPENED)\nResolution: FALSE-POSITIVE\nComment:\n Because!\n\n--\nSee it in Sonar: http://nemo.sonarsource.org/review/view/1\n"));
}
@Test

Dosyayı Görüntüle

@ -291,6 +291,7 @@ users.page=Users
violations.page=Violations
violations_drilldown.page=Violations drilldown
update_center.page=Update Center
email_configuration.page=Email configuration
org.sonar.plugins.core.hotspots.GwtHotspots.page=Hotspots
org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer.page=Duplications
@ -635,6 +636,33 @@ rules_configuration.x_rules_have_been_activated={0} rules have been activated.
rules_configuration.x_rules_have_been_deactivated={0} rules have been deactivated.
#------------------------------------------------------------------------------
#
# EMAIL CONFIGURATION
#
#------------------------------------------------------------------------------
email_configuration.smtp_host=SMTP host
email_configuration.smtp_port=SMTP port
email_configuration.use_tls=Use TLS
email_configuration.smtp_username=SMTP username
email_configuration.smtp_password=SMTP password
email_configuration.from_address=From address
email_configuration.email_prefix=Email prefix
email_configuration.test.title=Send Test Email
email_configuration.test.to_address=To
email_configuration.test.to_address_required=You must provide address where to send test email
email_configuration.test.subject=Subject
email_configuration.test.subject_text=Test Message from Sonar
email_configuration.test.message=Message
email_configuration.test.message_text=This is a test message from Sonar
email_configuration.test.send=Send
email_configuration.test.email_was_sent_to_x=Email was sent to {0}
notification.channel.EmailNotificationChannel=Email
notification.dispatcher.ChangesInReviewAssignedToMe=Changes in review assigned to me
notification.dispatcher.ChangesInReviewCreatedByMe=Changes in review created by me
#------------------------------------------------------------------------------
#
# ALERTS

Dosyayı Görüntüle

@ -49,7 +49,7 @@
<module>plugins/sonar-squid-java-plugin</module>
<module>plugins/sonar-design-plugin</module>
<module>plugins/sonar-i18n-en-plugin</module>
<module>plugins/sonar-email-plugin</module>
<module>plugins/sonar-email-notifications-plugin</module>
</modules>
<organization>

Dosyayı Görüntüle

@ -210,7 +210,7 @@
</dependency>
<dependency>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-email-plugin</artifactId>
<artifactId>sonar-email-notifications-plugin</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

Dosyayı Görüntüle

@ -456,7 +456,7 @@
</dependency>
<dependency>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-email-plugin</artifactId>
<artifactId>sonar-email-notifications-plugin</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

Dosyayı Görüntüle

@ -48,10 +48,11 @@ class EmailConfigurationController < ApplicationController
subject = params[:subject]
message = params[:message]
if to_address.blank?
flash[:notice] = 'You must provide address where to send test email'
flash[:notice] = message('email_configuration.test.to_address_required')
else
begin
java_facade.getComponentByClassname('email', 'org.sonar.plugins.email.EmailNotificationChannel').sendTestEmail(to_address, subject, message)
java_facade.getComponentByClassname('emailnotifications', 'org.sonar.plugins.emailnotifications.EmailNotificationChannel').sendTestEmail(to_address, subject, message)
flash[:notice] = message('email_configuration.test.email_was_sent_to_x', :params => [to_address])
rescue Exception => e
flash[:error] = e.message
end
@ -62,7 +63,7 @@ class EmailConfigurationController < ApplicationController
private
def configuration
java_facade.getComponentByClassname('email', 'org.sonar.plugins.email.EmailConfiguration').class
java_facade.getComponentByClassname('emailnotifications', 'org.sonar.plugins.emailnotifications.EmailConfiguration').class
end
end

Dosyayı Görüntüle

@ -29,9 +29,9 @@
<h1>Change password</h1>
<br/>
<% form_tag( {:action => 'change_password' }, :id => 'pass_form_tag', :name => 'pass_form_tag') do -%>
<table>
<tr>
<td nowrap>
<table>
<tr>
<td nowrap>
<label for="old_password"><b>Old value:</b></label>
</td>
<td class="sep"> </td>
@ -40,7 +40,7 @@
</td>
</tr>
<tr>
<td nowrap>
<td nowrap>
<label for="password"><b>New value:</b></label>
</td>
<td class="sep"> </td>
@ -49,7 +49,7 @@
</td>
</tr>
<tr>
<td nowrap>
<td nowrap>
<label for="password_confirmation"><b>Confirm new value:</b></label>
</td>
<td class="sep"> </td>
@ -58,15 +58,15 @@
</td>
</tr>
</table>
<br/>
<%= submit_tag 'Change password' %>
</table>
<br/>
<%= submit_tag 'Change password' %>
<% end %>
<script type="text/javascript">
//<![CDATA[
<script type="text/javascript">
//<![CDATA[
$('pass_form_tag').focusFirstElement();
//]]>
</script>
</script>
<% end -%>
<br/>
@ -77,12 +77,12 @@
<tr>
<td></td>
<% for channel in @channels %>
<td><%= channel.getKey() %></td>
<td><%= message('notification.channel.' + channel.getKey()) -%></td>
<% end %>
</tr>
<% for dispatcher in @dispatchers %>
<tr>
<td><%= dispatcher.getKey() %></td>
<td><%= message('notification.dispatcher.' + dispatcher.getKey()) -%></td>
<td>
<%
for channel in @channels

Dosyayı Görüntüle

@ -1,9 +1,10 @@
<h1>Email configuration</h1>
<h1><%= message('email_configuration.page') -%></h1>
<br/>
<% form_tag({:action => 'save'}) do -%>
<table>
<tr>
<td nowrap>
<label for="smtp_host"><b>SMTP Host:</b></label>
<label for="smtp_host"><b><%= message('email_configuration.smtp_host') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -13,7 +14,7 @@
<tr>
<td nowrap>
<label for="smtp_port"><b>SMTP Port:</b></label>
<label for="smtp_port"><b><%= message('email_configuration.smtp_port') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -23,7 +24,7 @@
<tr>
<td nowrap>
<label for="smtp_port"><b>Use TLS:</b></label>
<label for="smtp_port"><b><%= message('email_configuration.use_tls') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -33,7 +34,7 @@
<tr>
<td nowrap>
<label for="smtp_username"><b>SMTP Username:</b></label>
<label for="smtp_username"><b><%= message('email_configuration.smtp_username') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -43,7 +44,7 @@
<tr>
<td nowrap>
<label for="smtp_password"><b>SMTP Password:</b></label>
<label for="smtp_password"><b><%= message('email_configuration.smtp_password') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -53,7 +54,7 @@
<tr>
<td nowrap>
<label for="email_from"><b>From address:</b></label>
<label for="email_from"><b><%= message('email_configuration.from_address') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -63,7 +64,7 @@
<tr>
<td nowrap>
<label for="email_prefix"><b>Email prefix:</b></label>
<label for="email_prefix"><b><%= message('email_configuration.email_prefix') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -71,16 +72,18 @@
</td>
</tr>
</table>
<%= submit_tag %>
<br/>
<%= submit_tag message('save') %>
<% end -%>
<br/>
<h1>Send Test Email</h1>
<h1><%= message('email_configuration.test.title') -%></h1>
<br/>
<% form_tag({:action => 'send_test_email'}) do -%>
<table>
<tr>
<td nowrap>
<label for="to_address"><b>To:</b></label>
<label for="to_address"><b><%= message('email_configuration.test.to_address') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
@ -89,22 +92,23 @@
</tr>
<tr>
<td nowrap>
<label for="subject"><b>Subject:</b></label>
<label for="subject"><b><%= message('email_configuration.test.subject') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
<%= text_field_tag 'subject', 'Test Message from Sonar' %>
<%= text_field_tag 'subject', message('email_configuration.test.subject_text') %>
</td>
</tr>
<tr>
<td nowrap>
<label for="message"><b>Message:</b></label>
<label for="message"><b><%= message('email_configuration.test.message') -%></b></label>
</td>
<td class="sep"> </td>
<td align="left">
<%= text_area_tag 'message', 'This is a test message from Sonar.' %>
<%= text_area_tag 'message', message('email_configuration.test.message_text') %>
</td>
</tr>
<table>
<%= submit_tag 'Send' %>
<br/>
<%= submit_tag message('email_configuration.test.send') %>
<% end -%>

Dosyayı Görüntüle

@ -86,6 +86,7 @@
if update_center_activated=='true' %>
<li class="<%= 'selected' if controller.controller_path=='updatecenter' -%>"><a href="<%= ApplicationController.root_context -%>/updatecenter"><%= message('update_center.page') -%></a></li>
<% end %>
<li class="<%= 'selected' if controller.controller_path=='email_configuration' -%>"><a href="<%= ApplicationController.root_context -%>/email_configuration"><%= message('email_configuration.page') -%></a></li>
<% end %>
<% end %>