Show mail address in profile page, It can be controlled by settings. closes #673.

This commit is contained in:
KOUNOIKE Yuusuke
2018-04-29 19:05:45 +09:00
parent 915cfd06c3
commit 70dbee839a
9 changed files with 49 additions and 12 deletions

View File

@@ -229,13 +229,15 @@ trait AccountControllerBase extends AccountManagementControllerBase {
get("/:userName") { get("/:userName") {
val userName = params("userName") val userName = params("userName")
getAccountByUserName(userName).map { account => getAccountByUserName(userName).map { account =>
val extraMailAddresses = getAccountExtraMailAddresses(userName)
params.getOrElse("tab", "repositories") match { params.getOrElse("tab", "repositories") match {
// Public Activity // Public Activity
case "activity" => case "activity" =>
gitbucket.core.account.html.activity( gitbucket.core.account.html.activity(
account, account,
if (account.isGroupAccount) Nil else getGroupsByUserName(userName), if (account.isGroupAccount) Nil else getGroupsByUserName(userName),
getActivitiesByUser(userName, true) getActivitiesByUser(userName, true),
extraMailAddresses
) )
// Members // Members
@@ -244,6 +246,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
gitbucket.core.account.html.members( gitbucket.core.account.html.members(
account, account,
members, members,
extraMailAddresses,
context.loginAccount.exists( context.loginAccount.exists(
x => x =>
members.exists { member => members.exists { member =>
@@ -260,6 +263,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
account, account,
if (account.isGroupAccount) Nil else getGroupsByUserName(userName), if (account.isGroupAccount) Nil else getGroupsByUserName(userName),
getVisibleRepositories(context.loginAccount, Some(userName)), getVisibleRepositories(context.loginAccount, Some(userName)),
extraMailAddresses,
context.loginAccount.exists( context.loginAccount.exists(
x => x =>
members.exists { member => members.exists { member =>

View File

@@ -89,7 +89,8 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
"jwsAlgorithm" -> trim(label("Signature algorithm", optional(text()))) "jwsAlgorithm" -> trim(label("Signature algorithm", optional(text())))
)(OIDC.apply) )(OIDC.apply)
), ),
"skinName" -> trim(label("AdminLTE skin name", text(required))) "skinName" -> trim(label("AdminLTE skin name", text(required))),
"showMailAddress" -> trim(label("Show mail address", 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

@@ -68,6 +68,7 @@ trait SystemSettingsService {
} }
} }
props.setProperty(SkinName, settings.skinName.toString) props.setProperty(SkinName, settings.skinName.toString)
props.setProperty(ShowMailAddress, settings.showMailAddress.toString)
using(new java.io.FileOutputStream(GitBucketConf)) { out => using(new java.io.FileOutputStream(GitBucketConf)) { out =>
props.store(out, null) props.store(out, null)
} }
@@ -144,7 +145,8 @@ trait SystemSettingsService {
} else { } else {
None None
}, },
getValue(props, SkinName, "skin-blue") getValue(props, SkinName, "skin-blue"),
getValue(props, ShowMailAddress, false)
) )
} }
} }
@@ -174,7 +176,8 @@ object SystemSettingsService {
ldap: Option[Ldap], ldap: Option[Ldap],
oidcAuthentication: Boolean, oidcAuthentication: Boolean,
oidc: Option[OIDC], oidc: Option[OIDC],
skinName: String skinName: String,
showMailAddress: Boolean
) { ) {
def baseUrl(request: HttpServletRequest): String = def baseUrl(request: HttpServletRequest): String =
@@ -283,6 +286,7 @@ object SystemSettingsService {
private val OidcClientSecret = "oidc.client_secret" private val OidcClientSecret = "oidc.client_secret"
private val OidcJwsAlgorithm = "oidc.jws_algorithm" private val OidcJwsAlgorithm = "oidc.jws_algorithm"
private val SkinName = "skinName" private val SkinName = "skinName"
private val ShowMailAddress = "showMailAddress"
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

@@ -1,8 +1,9 @@
@(account: gitbucket.core.model.Account, @(account: gitbucket.core.model.Account,
groupNames: List[String], groupNames: List[String],
activities: List[gitbucket.core.model.Activity])(implicit context: gitbucket.core.controller.Context) activities: List[gitbucket.core.model.Activity],
extraMailAddresses: List[String])(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers @import gitbucket.core.view.helpers
@gitbucket.core.account.html.main(account, groupNames, "activity"){ @gitbucket.core.account.html.main(account, groupNames, "activity", extraMailAddresses){
<div class="pull-right"> <div class="pull-right">
<a href="@context.path/@{account.userName}.atom"><img src="@helpers.assets("/common/images/feed.png")" alt="activities"></a> <a href="@context.path/@{account.userName}.atom"><img src="@helpers.assets("/common/images/feed.png")" alt="activities"></a>
</div> </div>

View File

@@ -1,4 +1,4 @@
@(account: gitbucket.core.model.Account, groupNames: List[String], active: String, @(account: gitbucket.core.model.Account, groupNames: List[String], active: String, extraMailAddresses: List[String],
isGroupManager: Boolean = false)(body: Html)(implicit context: gitbucket.core.controller.Context) isGroupManager: Boolean = false)(body: Html)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers @import gitbucket.core.view.helpers
@gitbucket.core.html.main(account.userName){ @gitbucket.core.html.main(account.userName){
@@ -20,6 +20,16 @@
<i class="octicon octicon-home"></i> <a href="@account.url">@account.url</a> <i class="octicon octicon-home"></i> <a href="@account.url">@account.url</a>
</p> </p>
} }
@if(context.settings.showMailAddress){
<p style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<i class="octicon octicon-mail"></i> <a href="mailto: @account.mailAddress">@account.mailAddress</a>
</p>
@extraMailAddresses.map{ mail =>
<p style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<i class="octicon octicon-mail"></i> <a href="mailto: @mail">@mail</a>
</p>
}
}
<p style="color: #999"> <p style="color: #999">
<i class="octicon octicon-clock"></i> Joined on @helpers.date(account.registeredDate) <i class="octicon octicon-clock"></i> Joined on @helpers.date(account.registeredDate)
</p> </p>

View File

@@ -1,6 +1,6 @@
@(account: gitbucket.core.model.Account, members: List[gitbucket.core.model.GroupMember], isGroupManager: Boolean)(implicit context: gitbucket.core.controller.Context) @(account: gitbucket.core.model.Account, members: List[gitbucket.core.model.GroupMember], extraMailAddresses: List[String], isGroupManager: Boolean)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers @import gitbucket.core.view.helpers
@gitbucket.core.account.html.main(account, Nil, "members", isGroupManager){ @gitbucket.core.account.html.main(account, Nil, "members", extraMailAddresses, isGroupManager){
@if(members.isEmpty){ @if(members.isEmpty){
No members No members
} else { } else {

View File

@@ -1,8 +1,9 @@
@(account: gitbucket.core.model.Account, groupNames: List[String], @(account: gitbucket.core.model.Account, groupNames: List[String],
repositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo], repositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo],
extraMailAddresses: List[String],
isGroupManager: Boolean)(implicit context: gitbucket.core.controller.Context) isGroupManager: Boolean)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers @import gitbucket.core.view.helpers
@gitbucket.core.account.html.main(account, groupNames, "repositories", isGroupManager){ @gitbucket.core.account.html.main(account, groupNames, "repositories", extraMailAddresses, isGroupManager){
@if(repositories.isEmpty){ @if(repositories.isEmpty){
No repositories No repositories
} else { } else {

View File

@@ -132,6 +132,21 @@
</label> </label>
</fieldset> </fieldset>
<!--====================================================================--> <!--====================================================================-->
<!-- Show mail address -->
<!--====================================================================-->
<hr>
<label class="strong">Show mail address</label>
<fieldset>
<label class="radio">
<input type="radio" name="showMailAddress" value="true"@if(context.settings.showMailAddress){ checked}>
<span class="strong">Show</span> <span class="normal">- Anyone can view mail address by user's profile page.</span>
</label>
<label class="radio">
<input type="radio" name="allowAnonymousAccess" value="false"@if(!context.settings.showMailAddress){ checked}>
<span class="strong">Hide</span> <span class="normal">- Hide mail address in user's profile page.</span>
</label>
</fieldset>
<!--====================================================================-->
<!-- Activity --> <!-- Activity -->
<!--====================================================================--> <!--====================================================================-->
<hr> <hr>

View File

@@ -134,7 +134,8 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
ldap = None, ldap = None,
oidcAuthentication = false, oidcAuthentication = false,
oidc = None, oidc = None,
skinName = "skin-blue" skinName = "skin-blue",
showMailAddress = false
) )
/** /**