add debug option to SystemSettings. and error page shows stacktrace only for admin or debug settings.

This commit is contained in:
KOUNOIKE Yuusuke
2017-08-17 17:48:53 +09:00
parent 48a92df719
commit 040d812f2a
4 changed files with 24 additions and 14 deletions

View File

@@ -62,8 +62,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
"mailAttribute" -> trim(label("Mail address attribute", optional(text()))), "mailAttribute" -> trim(label("Mail address attribute", optional(text()))),
"tls" -> trim(label("Enable TLS", optional(boolean()))), "tls" -> trim(label("Enable TLS", optional(boolean()))),
"ssl" -> trim(label("Enable SSL", optional(boolean()))), "ssl" -> trim(label("Enable SSL", optional(boolean()))),
"keystore" -> trim(label("Keystore", optional(text()))) "keystore" -> trim(label("Keystore", optional(text()))),
)(Ldap.apply)) )(Ldap.apply)),
"debug" -> trim(label("Debug", boolean()))
)(SystemSettings.apply).verifying { settings => )(SystemSettings.apply).verifying { settings =>
Vector( Vector(
if(settings.ssh && settings.baseUrl.isEmpty){ if(settings.ssh && settings.baseUrl.isEmpty){

View File

@@ -54,6 +54,7 @@ trait SystemSettingsService {
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x)) ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
} }
} }
props.setProperty(Debug, settings.debug.toString)
using(new java.io.FileOutputStream(GitBucketConf)){ out => using(new java.io.FileOutputStream(GitBucketConf)){ out =>
props.store(out, null) props.store(out, null)
} }
@@ -111,7 +112,8 @@ trait SystemSettingsService {
getOptionValue(props, LdapKeystore, None))) getOptionValue(props, LdapKeystore, None)))
} else { } else {
None None
} },
getValue(props, Debug, false)
) )
} }
} }
@@ -136,7 +138,8 @@ object SystemSettingsService {
useSMTP: Boolean, useSMTP: Boolean,
smtp: Option[Smtp], smtp: Option[Smtp],
ldapAuthentication: Boolean, ldapAuthentication: Boolean,
ldap: Option[Ldap]){ ldap: Option[Ldap],
debug: Boolean){
def baseUrl(request: HttpServletRequest): String = baseUrl.fold(request.baseUrl)(_.stripSuffix("/")) def baseUrl(request: HttpServletRequest): String = baseUrl.fold(request.baseUrl)(_.stripSuffix("/"))
def sshAddress:Option[SshAddress] = def sshAddress:Option[SshAddress] =
@@ -219,6 +222,7 @@ object SystemSettingsService {
private val LdapTls = "ldap.tls" private val LdapTls = "ldap.tls"
private val LdapSsl = "ldap.ssl" private val LdapSsl = "ldap.ssl"
private val LdapKeystore = "ldap.keystore" private val LdapKeystore = "ldap.keystore"
private val Debug = "debug"
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A = { private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A = {
getSystemProperty(key).getOrElse(getEnvironmentVariable(key).getOrElse { getSystemProperty(key).getOrElse(getEnvironmentVariable(key).getOrElse {

View File

@@ -3,15 +3,19 @@
<div class="content-wrapper main-center"> <div class="content-wrapper main-center">
<div class="content body"> <div class="content body">
<h1>@title</h1> <h1>@title</h1>
@e.map { ex => @if(context.loginAccount.map{_.isAdmin}.getOrElse(false) || context.settings.debug){
<h2>@ex.getMessage</h2> @e.map { ex =>
<table class="table table-condensed table-striped table-hover"> <h2>@ex.getMessage</h2>
<tbody> <table class="table table-condensed table-striped table-hover">
@ex.getStackTrace.map{ st => <tbody>
<tr><td>@st</td></tr> @ex.getStackTrace.map{ st =>
} <tr><td>@st</td></tr>
</tbody> }
</table> </tbody>
</table>
}
} else {
<div>Please contact your administrator.</div>
} }
</div> </div>
</div> </div>

View File

@@ -118,7 +118,8 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
useSMTP = false, useSMTP = false,
smtp = None, smtp = None,
ldapAuthentication = false, ldapAuthentication = false,
ldap = None) ldap = None,
debug = false)
/** /**
* Adapter to test AvatarImageProviderImpl. * Adapter to test AvatarImageProviderImpl.