diff --git a/src/main/scala/app/SystemSettingsController.scala b/src/main/scala/app/SystemSettingsController.scala
index 6416374..cb1c10a 100644
--- a/src/main/scala/app/SystemSettingsController.scala
+++ b/src/main/scala/app/SystemSettingsController.scala
@@ -12,10 +12,14 @@
trait SystemSettingsControllerBase extends ControllerBase with FlashMapSupport {
self: SystemSettingsService with AccountService with AdminAuthenticator =>
- private case class SystemSettingsForm(allowAccountRegistration: Boolean)
+ private case class SystemSettingsForm(
+ allowAccountRegistration: Boolean,
+ gravatar: Boolean
+ )
private val form = mapping(
- "allowAccountRegistration" -> trim(label("Account registration", boolean()))
+ "allowAccountRegistration" -> trim(label("Account registration", boolean())),
+ "gravatar" -> trim(label("Gravatar", boolean()))
)(SystemSettingsForm.apply)
@@ -24,7 +28,10 @@
})
post("/admin/system", form)(adminOnly { form =>
- saveSystemSettings(SystemSettings(form.allowAccountRegistration))
+ saveSystemSettings(SystemSettings(
+ form.allowAccountRegistration,
+ form.gravatar
+ ))
flash += "info" -> "System settings has been updated."
redirect("/admin/system")
})
diff --git a/src/main/scala/service/RequestCache.scala b/src/main/scala/service/RequestCache.scala
index 758c373..d3fc3e9 100644
--- a/src/main/scala/service/RequestCache.scala
+++ b/src/main/scala/service/RequestCache.scala
@@ -1,6 +1,7 @@
package service
import model._
+import service.SystemSettingsService.SystemSettings
/**
* This service is used for a view helper mainly.
@@ -10,6 +11,11 @@
*/
trait RequestCache {
+ def getSystemSettings()(implicit context: app.Context): SystemSettings =
+ context.cache("system_settings"){
+ new SystemSettingsService {}.loadSystemSettings()
+ }
+
def getIssue(userName: String, repositoryName: String, issueId: String)(implicit context: app.Context): Option[Issue] = {
context.cache(s"issue.${userName}/${repositoryName}#${issueId}"){
new IssuesService {}.getIssue(userName, repositoryName, issueId)
diff --git a/src/main/scala/service/SystemSettingsService.scala b/src/main/scala/service/SystemSettingsService.scala
index b425b34..36368b8 100644
--- a/src/main/scala/service/SystemSettingsService.scala
+++ b/src/main/scala/service/SystemSettingsService.scala
@@ -1,40 +1,47 @@
-package service
-
-import util.Directory._
-import SystemSettingsService._
-
-trait SystemSettingsService {
-
- def saveSystemSettings(settings: SystemSettings): Unit = {
- val props = new java.util.Properties()
- props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
- props.store(new java.io.FileOutputStream(GitBucketConf), null)
- }
-
-
- def loadSystemSettings(): SystemSettings = {
- val props = new java.util.Properties()
- if(GitBucketConf.exists){
- props.load(new java.io.FileInputStream(GitBucketConf))
- }
- SystemSettings(getBoolean(props, "allow_account_registration"))
- }
-
-}
-
-object SystemSettingsService {
-
- case class SystemSettings(allowAccountRegistration: Boolean)
-
- private val AllowAccountRegistration = "allow_account_registration"
-
- private def getBoolean(props: java.util.Properties, key: String, default: Boolean = false): Boolean = {
- val value = props.getProperty(key)
- if(value == null || value.isEmpty){
- default
- } else {
- value.toBoolean
- }
- }
-
-}
+package service
+
+import util.Directory._
+import SystemSettingsService._
+
+trait SystemSettingsService {
+
+ def saveSystemSettings(settings: SystemSettings): Unit = {
+ val props = new java.util.Properties()
+ props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
+ props.setProperty(Gravatar, settings.gravatar.toString)
+ props.store(new java.io.FileOutputStream(GitBucketConf), null)
+ }
+
+
+ def loadSystemSettings(): SystemSettings = {
+ val props = new java.util.Properties()
+ if(GitBucketConf.exists){
+ props.load(new java.io.FileInputStream(GitBucketConf))
+ }
+ SystemSettings(
+ getBoolean(props, AllowAccountRegistration),
+ getBoolean(props, Gravatar, true))
+ }
+
+}
+
+object SystemSettingsService {
+
+ case class SystemSettings(
+ allowAccountRegistration: Boolean,
+ gravatar: Boolean
+ )
+
+ private val AllowAccountRegistration = "allow_account_registration"
+ private val Gravatar = "gravatar"
+
+ private def getBoolean(props: java.util.Properties, key: String, default: Boolean = false): Boolean = {
+ val value = props.getProperty(key)
+ if(value == null || value.isEmpty){
+ default
+ } else {
+ value.toBoolean
+ }
+ }
+
+}
diff --git a/src/main/scala/view/AvatarImageProvider.scala b/src/main/scala/view/AvatarImageProvider.scala
index 28cf7f3..c5ae04e 100644
--- a/src/main/scala/view/AvatarImageProvider.scala
+++ b/src/main/scala/view/AvatarImageProvider.scala
@@ -14,18 +14,19 @@
mailAddress: String = "", tooltip: Boolean = false)(implicit context: app.Context): Html = {
val src = getAccountByUserName(userName).map { account =>
- if(account.image.isEmpty){
+ if(account.image.isEmpty && getSystemSettings().gravatar){
s"""http://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress)}?s=${size}"""
} else {
s"""${context.path}/${userName}/_avatar"""
}
} getOrElse {
- if(mailAddress.nonEmpty){
+ if(mailAddress.nonEmpty && getSystemSettings().gravatar){
s"""http://www.gravatar.com/avatar/${StringUtil.md5(mailAddress)}?s=${size}"""
} else {
s"""${context.path}/${userName}/_avatar"""
}
}
+
if(tooltip){
Html(s"""""")
} else {
diff --git a/src/main/twirl/admin/system.scala.html b/src/main/twirl/admin/system.scala.html
index 75a07b6..72c4d16 100644
--- a/src/main/twirl/admin/system.scala.html
+++ b/src/main/twirl/admin/system.scala.html
@@ -19,6 +19,14 @@
Deny - Only administrators can create account.
+