(refs #114)Disable link for disabled users.

This commit is contained in:
takezoe
2013-11-03 14:32:03 +09:00
parent 05296473d3
commit a03acc68e7
6 changed files with 47 additions and 22 deletions

View File

@@ -35,12 +35,16 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
Html(Markdown.toHtml(value, repository, enableWikiLink, enableRefsLink))
/**
* Returns <img> which displays the avatar icon.
* Looks up Gravatar if avatar icon has not been configured in user settings.
* Returns <img> which displays the avatar icon for the given user name.
* This method looks up Gravatar if avatar icon has not been configured in user settings.
*/
def avatar(userName: String, size: Int, tooltip: Boolean = false)(implicit context: app.Context): Html =
getAvatarImageHtml(userName, size, "", tooltip)
/**
* Returns <img> which displays the avatar icon for the given mail address.
* This method looks up Gravatar if avatar icon has not been configured in user settings.
*/
def avatar(commit: util.JGitUtil.CommitInfo, size: Int)(implicit context: app.Context): Html =
getAvatarImageHtml(commit.committer, size, commit.mailAddress)
@@ -64,6 +68,9 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
}
}
/**
* Convert link notations in the activity message.
*/
def activityMessage(message: String)(implicit context: app.Context): Html =
Html(message
.replaceAll("\\[issue:([^\\s]+?)/([^\\s]+?)#((\\d+))\\]" , s"""<a href="${context.path}/$$1/$$2/issues/$$3">$$1/$$2#$$3</a>""")
@@ -71,7 +78,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
.replaceAll("\\[repo:([^\\s]+?)/([^\\s]+?)\\]" , s"""<a href="${context.path}/$$1/$$2\">$$1/$$2</a>""")
.replaceAll("\\[branch:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]", (m: Match) => s"""<a href="${context.path}/${m.group(1)}/${m.group(2)}/tree/${encodeRefName(m.group(3))}">${m.group(3)}</a>""")
.replaceAll("\\[tag:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]" , (m: Match) => s"""<a href="${context.path}/${m.group(1)}/${m.group(2)}/tree/${encodeRefName(m.group(3))}">${m.group(3)}</a>""")
.replaceAll("\\[user:([^\\s]+?)\\]" , s"""<a href="${context.path}/$$1">$$1</a>""") // TODO disable link if user is removed?
.replaceAll("\\[user:([^\\s]+?)\\]" , (m: Match) => user(m.group(1)).body)
)
/**
@@ -100,14 +107,32 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
def assets(implicit context: app.Context): String = s"${context.path}/assets"
/**
* Generates the link to the account page.
* Generates the text link to the account page.
* If user does not exist or disabled, this method returns user name as text without link.
*/
def user(userName: String, mailAddress: String, styleClass: String = "")(implicit context: app.Context): Html = {
getAccountByMailAddress(mailAddress).map { account =>
Html(s"""<a href="${url(account.userName)}" class="${styleClass}">${userName}</a>""")
} getOrElse Html(userName)
}
def user(userName: String, mailAddress: String = "", styleClass: String = "")(implicit context: app.Context): Html =
userWithContent(userName, mailAddress, styleClass)(Html(userName))
/**
* Generates the avatar link to the account page.
* If user does not exist or disabled, this method returns avatar image without link.
*/
def avatarLink(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)(implicit context: app.Context): Html =
userWithContent(userName, mailAddress)(avatar(userName, size, tooltip))
private def userWithContent(userName: String, mailAddress: String = "", styleClass: String = "")(content: Html)(implicit context: app.Context): Html =
(if(mailAddress.isEmpty){
getAccountByUserName(userName)
} else {
getAccountByMailAddress(mailAddress)
}).map { account =>
Html(s"""<a href="${url(account.userName)}" class="${styleClass}">${content}</a>""")
} getOrElse content
/**
* Test whether the given Date is past date.
*/
def isPast(date: Date): Boolean = System.currentTimeMillis > date.getTime
/**

View File

@@ -11,7 +11,7 @@
<div class="box issue-comment-box" id="comment-@comment.commentId">
<div class="box-header-small">
<i class="icon-comment"></i>
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> commented
@user(comment.commentedUserName, styleClass="username strong") commented
<span class="pull-right">
@datetime(comment.registeredDate)
@if(comment.action != "commit" && comment.action != "merge" && (hasWritePermission || loginAccount.map(_.userName == comment.commentedUserName).getOrElse(false))){
@@ -36,7 +36,7 @@
<div class="small" style="margin-top: 10px; margin-bottom: 10px;">
<span class="label label-info">Merged</span>
@avatar(comment.commentedUserName, 20)
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> merged commit <code>@pullreq.map(_.commitIdTo.substring(0, 7))</code>
@user(comment.commentedUserName, styleClass="username strong") merged commit <code>@pullreq.map(_.commitIdTo.substring(0, 7))</code>
@if(pullreq.get.requestUserName == repository.owner){
<span class="label label-info monospace">@pullreq.map(_.requestBranch)</span> to <span class="label label-info monospace">@pullreq.map(_.branch)</span>
} else {
@@ -50,9 +50,9 @@
<span class="label label-important">Closed</span>
@avatar(comment.commentedUserName, 20)
@if(issue.isPullRequest){
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> closed the pull request @datetime(comment.registeredDate)
@user(comment.commentedUserName, styleClass="username strong") closed the pull request @datetime(comment.registeredDate)
} else {
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> closed the issue @datetime(comment.registeredDate)
@user(comment.commentedUserName, styleClass="username strong") closed the issue @datetime(comment.registeredDate)
}
</div>
}
@@ -60,7 +60,7 @@
<div class="small issue-comment-action">
<span class="label label-success">Reopened</span>
@avatar(comment.commentedUserName, 20)
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> reopened the issue @datetime(comment.registeredDate)
@user(comment.commentedUserName, styleClass="username strong") reopened the issue @datetime(comment.registeredDate)
</div>
}
}

View File

@@ -14,14 +14,14 @@
<span class="pull-right"><a class="btn btn-small" href="#" id="edit">Edit</a></span>
}
<div class="small muted">
<a href="@url(issue.openedUserName)" class="username">@issue.openedUserName</a> opened this issue @datetime(issue.registeredDate)
@user(issue.openedUserName, styleClass="username strong") opened this issue @datetime(issue.registeredDate)
</div>
<h4 id="issueTitle">@issue.title</h4>
</div>
<div class="issue-info">
<span id="label-assigned">
@issue.assignedUserName.map { userName =>
@avatar(userName, 20) <a href="@url(userName)" class="username strong">@userName</a> is assigned
@avatar(userName, 20) @user(userName, styleClass="username strong") is assigned
}.getOrElse("No one is assigned")
</span>
@if(hasWritePermission){
@@ -84,7 +84,7 @@
<div class="issue-participants">
@defining((issue.openedUserName :: comments.map(_.commentedUserName)).distinct){ participants =>
<span class="strong">@participants.size</span> @plural(participants.size, "participant")
@participants.map { participant => <a href="@url(participant)">@avatar(participant, 20, tooltip = true)</a> }
@participants.map { participant => @avatarLink(participant, 20, tooltip = true) }
}
</div>
<script>

View File

@@ -165,7 +165,7 @@
#@issue.issueId
</span>
<div class="small muted" style="margin-left: 20px;">
Opened by <a href="@url(issue.openedUserName)" class="username">@issue.openedUserName</a> @datetime(issue.registeredDate)&nbsp;
Opened by @user(issue.openedUserName, styleClass="username") @datetime(issue.registeredDate)&nbsp;
@if(commentCount > 0){
<i class="icon-comment"></i><a href="@path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count">@commentCount @plural(commentCount, "comment")</a>
}

View File

@@ -85,7 +85,7 @@
}
</div>
<div class="small muted" style="margin-left: 20px;">
@avatar(issue.openedUserName, 20) by <a href="@url(issue.openedUserName)" class="username">@issue.openedUserName</a> @datetime(issue.registeredDate)&nbsp;
@avatarLink(issue.openedUserName, 20) by @user(issue.openedUserName, styleClass="username") @datetime(issue.registeredDate)&nbsp;
@if(commentCount > 0){
<i class="icon-comment"></i><a href="@path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count">@commentCount @plural(commentCount, "comment")</a>
}

View File

@@ -16,17 +16,17 @@
@if(issue.closed) {
@comments.find(_.action == "merge").map{ comment =>
<span class="label label-info">Merged</span>
<a href="@url(comment.commentedUserName)" class="username strong">@comment.commentedUserName</a> merged @commits.size @plural(commits.size, "commit")
@user(comment.commentedUserName, styleClass="username strong") merged @commits.size @plural(commits.size, "commit")
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
at @datetime(comment.registeredDate)
}.getOrElse {
<span class="label label-important">Closed</span>
<a href="@url(issue.openedUserName)" class="username strong">@issue.openedUserName</a> wants to merge @commits.size @plural(commits.size, "commit")
@user(issue.openedUserName, styleClass="username strong") wants to merge @commits.size @plural(commits.size, "commit")
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
}
} else {
<span class="label label-success">Open</span>
<a href="@url(issue.openedUserName)" class="username strong">@issue.openedUserName</a> wants to merge @commits.size @plural(commits.size, "commit")
@user(issue.openedUserName, styleClass="username strong") wants to merge @commits.size @plural(commits.size, "commit")
into <code>@pullreq.requestUserName:@pullreq.requestBranch</code> from <code>@pullreq.userName:@pullreq.branch</code>
}
</div>