diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index 1c1271d..a70e8ba 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -24,7 +24,8 @@ "activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))), "ssh" -> trim(label("SSH access", boolean())), "sshPort" -> trim(label("SSH port", optional(number()))), - "smtp" -> optionalIfNotChecked("notification", mapping( + "useSMTP" -> trim(label("SMTP", boolean())), + "smtp" -> optionalIfNotChecked("useSMTP", mapping( "host" -> trim(label("SMTP Host", text(required))), "port" -> trim(label("SMTP Port", optional(number()))), "user" -> trim(label("SMTP User", optional(text()))), diff --git a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala index af4a6ef..3346bec 100644 --- a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala +++ b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala @@ -22,7 +22,8 @@ settings.activityLogLimit.foreach(x => props.setProperty(ActivityLogLimit, x.toString)) props.setProperty(Ssh, settings.ssh.toString) settings.sshPort.foreach(x => props.setProperty(SshPort, x.toString)) - if(settings.notification) { + props.setProperty(UseSMTP, settings.useSMTP.toString) + if(settings.useSMTP) { settings.smtp.foreach { smtp => props.setProperty(SmtpHost, smtp.host) smtp.port.foreach(x => props.setProperty(SmtpPort, x.toString)) @@ -75,7 +76,8 @@ getOptionValue[Int](props, ActivityLogLimit, None), getValue(props, Ssh, false), getOptionValue(props, SshPort, Some(DefaultSshPort)), - if(getValue(props, Notification, false)){ + getValue(props, UseSMTP, getValue(props, Notification, false)), // handle migration scenario from only notification to useSMTP + if(getValue(props, UseSMTP, getValue(props, Notification, false))){ Some(Smtp( getValue(props, SmtpHost, ""), getOptionValue(props, SmtpPort, Some(DefaultSmtpPort)), @@ -125,6 +127,7 @@ activityLogLimit: Option[Int], ssh: Boolean, sshPort: Option[Int], + useSMTP: Boolean, smtp: Option[Smtp], ldapAuthentication: Boolean, ldap: Option[Ldap]){ @@ -172,6 +175,7 @@ private val ActivityLogLimit = "activity_log_limit" private val Ssh = "ssh" private val SshPort = "ssh.port" + private val UseSMTP = "useSMTP" private val SmtpHost = "smtp.host" private val SmtpPort = "smtp.port" private val SmtpUser = "smtp.user" diff --git a/src/main/scala/gitbucket/core/util/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala index 7eed798..b851c7b 100644 --- a/src/main/scala/gitbucket/core/util/Notifier.scala +++ b/src/main/scala/gitbucket/core/util/Notifier.scala @@ -37,7 +37,7 @@ object Notifier { // TODO We want to be able to switch to mock. def apply(): Notifier = new SystemSettingsService {}.loadSystemSettings match { - case settings if settings.notification => new Mailer(settings.smtp.get) + case settings if (settings.notification && settings.useSMTP) => new Mailer(settings.smtp.get) case _ => new MockMailer } diff --git a/src/main/twirl/gitbucket/core/admin/system.scala.html b/src/main/twirl/gitbucket/core/admin/system.scala.html index 276c25e..251d72a 100644 --- a/src/main/twirl/gitbucket/core/admin/system.scala.html +++ b/src/main/twirl/gitbucket/core/admin/system.scala.html @@ -224,14 +224,25 @@
- +
-
+ + + +
+ +
+ +
+
@@ -292,8 +303,16 @@ $('.ssh input').prop('disabled', !$(this).prop('checked')); }).change(); - $('#notification').change(function(){ - $('.notification input').prop('disabled', !$(this).prop('checked')); + $('#useSMTP').change(function(){ + $('.useSMTP input').prop('disabled', !$(this).prop('checked')); + + // With only SMTP in current version, notification cannot be enabled if no communication channel exists + $('#notification').prop('disabled', !$(this).prop('checked')); + + if (!$(this).prop('checked')) { + // With only SMTP in current version, if SMTP is unchecked then we disable notification + $('#notification').prop('checked', false); + } }).change(); $('#ldapAuthentication').change(function(){ diff --git a/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala b/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala index 85d60b9..75b9744 100644 --- a/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala +++ b/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala @@ -103,6 +103,7 @@ activityLogLimit = None, ssh = false, sshPort = None, + useSMTP = false, smtp = None, ldapAuthentication = false, ldap = None)