This commit is contained in:
shimamoto
2013-07-11 13:44:12 +09:00
17 changed files with 91 additions and 57 deletions

View File

@@ -70,7 +70,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
val userName = params("userName") val userName = params("userName")
getAccountByUserName(userName).map { account => getAccountByUserName(userName).map { account =>
updateAccount(account.copy( updateAccount(account.copy(
password = form.password.map(encrypt).getOrElse(account.password), password = form.password.map(sha1).getOrElse(account.password),
mailAddress = form.mailAddress, mailAddress = form.mailAddress,
url = form.url)) url = form.url))
@@ -93,7 +93,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
post("/register", newForm){ form => post("/register", newForm){ form =>
if(loadSystemSettings().allowAccountRegistration){ if(loadSystemSettings().allowAccountRegistration){
createAccount(form.userName, encrypt(form.password), form.mailAddress, false, form.url) createAccount(form.userName, sha1(form.password), form.mailAddress, false, form.url)
updateImage(form.userName, form.fileId, false) updateImage(form.userName, form.fileId, false)
redirect("/signin") redirect("/signin")
} else NotFound } else NotFound

View File

@@ -95,7 +95,23 @@ abstract class ControllerBase extends ScalatraFilter
/** /**
* Context object for the current request. * Context object for the current request.
*/ */
case class Context(path: String, loginAccount: Option[Account], currentUrl: String, request: HttpServletRequest) case class Context(path: String, loginAccount: Option[Account], currentUrl: String, request: HttpServletRequest){
/**
* Get object from cache.
*
* If object has not been cached with the specified key then retrieves by given action.
* Cached object are available during a request.
*/
def cache[A](key: String)(action: => A): A = {
Option(request.getAttribute("cache." + key).asInstanceOf[A]).getOrElse {
val newObject = action
request.setAttribute("cache." + key, newObject)
newObject
}
}
}
/** /**
* Base trait for controllers which manages account information. * Base trait for controllers which manages account information.

View File

@@ -213,11 +213,17 @@ trait RepositoryViewerControllerBase extends ControllerBase {
if(repository.commitCount == 0){ if(repository.commitCount == 0){
repo.html.guide(repository) repo.html.guide(repository)
} else { } else {
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git => JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
// get latest commit // get specified commit
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)) val (revCommit, revision) = try {
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
} catch {
case e: NullPointerException => {
val revision = repository.branchList.head
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
}
}
// get files // get files
val files = JGitUtil.getFileList(git, revision, path) val files = JGitUtil.getFileList(git, revision, path)
// process README.md // process README.md
@@ -225,20 +231,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
new String(JGitUtil.getContent(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get, "UTF-8") new String(JGitUtil.getContent(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get, "UTF-8")
} }
repo.html.files( repo.html.files(revision, repository,
// current branch if(path == ".") Nil else path.split("/").toList, // current path
revision, new JGitUtil.CommitInfo(revCommit), // latest commit
// repository files, readme)
repository,
// current path
if(path == ".") Nil else path.split("/").toList,
// latest commit
new JGitUtil.CommitInfo(revCommit),
// file list
files,
// readme
readme
)
} }
} }
} }

View File

@@ -25,7 +25,7 @@ trait SignInControllerBase extends ControllerBase { self: SystemSettingsService
post("/signin", form){ form => post("/signin", form){ form =>
val account = getAccountByUserName(form.userName) val account = getAccountByUserName(form.userName)
if(account.isEmpty || account.get.password != encrypt(form.password)){ if(account.isEmpty || account.get.password != sha1(form.password)){
redirect("/signin") redirect("/signin")
} else { } else {
session.setAttribute("LOGIN_ACCOUNT", account.get) session.setAttribute("LOGIN_ACCOUNT", account.get)

View File

@@ -47,7 +47,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
}) })
post("/admin/users/_new", newForm)(adminOnly { form => post("/admin/users/_new", newForm)(adminOnly { form =>
createAccount(form.userName, encrypt(form.password), form.mailAddress, form.isAdmin, form.url) createAccount(form.userName, sha1(form.password), form.mailAddress, form.isAdmin, form.url)
updateImage(form.userName, form.fileId, false) updateImage(form.userName, form.fileId, false)
redirect("/admin/users") redirect("/admin/users")
}) })
@@ -61,7 +61,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
val userName = params("userName") val userName = params("userName")
getAccountByUserName(userName).map { account => getAccountByUserName(userName).map { account =>
updateAccount(getAccountByUserName(userName).get.copy( updateAccount(getAccountByUserName(userName).get.copy(
password = form.password.map(encrypt).getOrElse(account.password), password = form.password.map(sha1).getOrElse(account.password),
mailAddress = form.mailAddress, mailAddress = form.mailAddress,
isAdmin = form.isAdmin, isAdmin = form.isAdmin,
url = form.url)) url = form.url))

View File

@@ -59,7 +59,7 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
private def isWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo): Boolean = { private def isWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo): Boolean = {
getAccountByUserName(username).map { account => getAccountByUserName(username).map { account =>
account.password == encrypt(password) && hasWritePermission(repository.owner, repository.name, Some(account)) account.password == sha1(password) && hasWritePermission(repository.owner, repository.name, Some(account))
} getOrElse false } getOrElse false
} }

View File

@@ -8,7 +8,7 @@ import scala.slick.driver.H2Driver.simple._
*/ */
object Implicits { object Implicits {
implicit def extendsSeq[A](seq: Seq[A]) = new { implicit class RichSeq[A](seq: Seq[A]) {
def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition) def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition)
@@ -26,7 +26,7 @@ object Implicits {
} }
// TODO Should this implicit conversion move to model.Functions? // TODO Should this implicit conversion move to model.Functions?
implicit def extendsColumn(c1: Column[Boolean]) = new { implicit class RichColumn(c1: Column[Boolean]){
def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1 def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1
} }

View File

@@ -2,7 +2,7 @@ package util
object StringUtil { object StringUtil {
def encrypt(value: String): String = { def sha1(value: String): String = {
val md = java.security.MessageDigest.getInstance("SHA-1") val md = java.security.MessageDigest.getInstance("SHA-1")
md.update(value.getBytes) md.update(value.getBytes)
md.digest.map(b => "%02x".format(b)).mkString md.digest.map(b => "%02x".format(b)).mkString

View File

@@ -75,16 +75,14 @@ object helpers {
// convert commit id to link // convert commit id to link
.replaceAll("(^|\\W)([a-f0-9]{40})(\\W|$)", "$1<a href=\"%s/%s/%s/commit/$2\">$2</a>$3").format(context.path, repository.owner, repository.name)) .replaceAll("(^|\\W)([a-f0-9]{40})(\\W|$)", "$1<a href=\"%s/%s/%s/commit/$2\">$2</a>$3").format(context.path, repository.owner, repository.name))
/** /**
* Returns &lt;img&gt; which displays the avatar icon. * Returns &lt;img&gt; which displays the avatar icon.
* Looks up Gravatar if avatar icon has not been configured in user settings. * 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 = { def avatar(userName: String, size: Int, tooltip: Boolean = false)(implicit context: app.Context): Html = {
val account = Option(context.request.getAttribute("cache.account." + userName).asInstanceOf[model.Account]).orElse { val account = context.cache(s"account.${userName}"){
new AccountService {}.getAccountByUserName(userName).map { account => new AccountService {}.getAccountByUserName(userName)
context.request.setAttribute("cache.account." + userName, account)
account
}
} }
val src = account.collect { case account if(account.image.isEmpty) => val src = account.collect { case account if(account.image.isEmpty) =>
s"""http://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress)}?s=${size}""" s"""http://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress)}?s=${size}"""
@@ -92,16 +90,16 @@ object helpers {
s"""${context.path}/${userName}/_avatar""" s"""${context.path}/${userName}/_avatar"""
} }
if(tooltip){ if(tooltip){
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}:px" data-toggle="tooltip" title=${userName}/>""") Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}px;" data-toggle="tooltip" title=${userName}/>""")
} else { } else {
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}:px" />""") Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}px;" />""")
} }
} }
/** /**
* Implicit conversion to add mkHtml() to Seq[Html]. * Implicit conversion to add mkHtml() to Seq[Html].
*/ */
implicit def extendsHtmlSeq(seq: Seq[Html]) = new { implicit class RichHtmlSeq(seq: Seq[Html]) {
def mkHtml(separator: String) = Html(seq.mkString(separator)) def mkHtml(separator: String) = Html(seq.mkString(separator))
def mkHtml(separator: scala.xml.Elem) = Html(seq.mkString(separator.toString)) def mkHtml(separator: scala.xml.Elem) = Html(seq.mkString(separator.toString))
} }

View File

@@ -11,10 +11,11 @@
<form action="@url(repository)/issues/new" method="POST" validate="true"> <form action="@url(repository)/issues/new" method="POST" validate="true">
<div class="row-fluid"> <div class="row-fluid">
<div class="span9"> <div class="span9">
<div class="box"> <div class="issue-avatar-image">@avatar(loginAccount.get.userName, 48)</div>
<div class="box issue-box">
<div class="box-content"> <div class="box-content">
<span id="error-title" class="error"></span> <span id="error-title" class="error"></span>
<input type="text" name="title" value="" placeholder="Title" style="width: 650px;"/> <input type="text" name="title" value="" placeholder="Title" style="width: 600px;"/>
<div> <div>
<span id="label-assigned">No one is assigned</span> <span id="label-assigned">No one is assigned</span>
@if(hasWritePermission){ @if(hasWritePermission){
@@ -42,10 +43,12 @@
</div> </div>
</div> </div>
<hr> <hr>
@helper.html.preview(repository, "", false, true, true, "width: 650px; height: 200px;") @helper.html.preview(repository, "", false, true, true, "width: 600px; height: 200px;")
</div> </div>
</div> </div>
<input type="submit" class="btn btn-success" value="Submit new issue"/> <div class="pull-right">
<input type="submit" class="btn btn-success" value="Submit new issue"/>
</div>
</div> </div>
<div class="span3"> <div class="span3">
@if(hasWritePermission){ @if(hasWritePermission){

View File

@@ -1,7 +1,7 @@
@(content: String, commentId: Int, owner: String, repository: String)(implicit context: app.Context) @(content: String, commentId: Int, owner: String, repository: String)(implicit context: app.Context)
@import context._ @import context._
<span id="error-edit-content-@commentId" class="error"></span> <span id="error-edit-content-@commentId" class="error"></span>
<textarea style="width: 730px; height: 100px;" id="edit-content-@commentId">@content</textarea> <textarea style="width: 680px; height: 100px;" id="edit-content-@commentId">@content</textarea>
<input type="button" class="btn btn-small" value="Update Comment"/> <input type="button" class="btn btn-small" value="Update Comment"/>
<span class="pull-right"><a class="btn btn-small btn-danger" href="#">Cancel</a></span> <span class="pull-right"><a class="btn btn-small btn-danger" href="#">Cancel</a></span>
<script> <script>

View File

@@ -1,8 +1,8 @@
@(title: String, content: Option[String], issueId: Int, owner: String, repository: String)(implicit context: app.Context) @(title: String, content: Option[String], issueId: Int, owner: String, repository: String)(implicit context: app.Context)
@import context._ @import context._
<span id="error-edit-title" class="error"></span> <span id="error-edit-title" class="error"></span>
<input type="text" style="width: 730px;" id="edit-title" value="@title"/> <input type="text" style="width: 680px;" id="edit-title" value="@title"/>
<textarea style="width: 730px; height: 100px;" id="edit-content">@content.getOrElse("")</textarea> <textarea style="width: 680px; height: 100px;" id="edit-content">@content.getOrElse("")</textarea>
<input type="button" class="btn btn-small" value="Update Issue"/> <input type="button" class="btn btn-small" value="Update Issue"/>
<span class="pull-right"><a class="btn btn-small btn-danger" href="#">Cancel</a></span> <span class="pull-right"><a class="btn btn-small btn-danger" href="#">Cancel</a></span>
<script> <script>

View File

@@ -17,7 +17,8 @@
</ul> </ul>
<div class="row-fluid"> <div class="row-fluid">
<div class="span10"> <div class="span10">
<div class="box"> <div class="issue-avatar-image">@avatar(issue.openedUserName, 48)</div>
<div class="box issue-box">
<div class="box-content" style="padding: 0px;"> <div class="box-content" style="padding: 0px;">
<div class="issue-header"> <div class="issue-header">
@if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){ @if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){
@@ -68,6 +69,7 @@
</div> </div>
</div> </div>
@comments.map { comment => @comments.map { comment =>
<div class="issue-avatar-image">@avatar(comment.commentedUserName, 48)</div>
<div class="box issue-comment-box" id="comment-@comment.commentId"> <div class="box issue-comment-box" id="comment-@comment.commentId">
<div class="box-header-small"> <div class="box-header-small">
<i class="icon-comment"></i> <i class="icon-comment"></i>
@@ -97,16 +99,19 @@
} }
@if(loginAccount.isDefined){ @if(loginAccount.isDefined){
<form action="@url(repository)/issue_comments/new" method="POST" validate="true"> <form action="@url(repository)/issue_comments/new" method="POST" validate="true">
<div class="box"> <div class="issue-avatar-image">@avatar(loginAccount.get.userName, 48)</div>
<div class="box issue-comment-box">
<div class="box-content"> <div class="box-content">
@helper.html.preview(repository, "", false, true, true, "width: 730px; height: 100px;") @helper.html.preview(repository, "", false, true, true, "width: 680px; height: 100px;")
</div> </div>
</div> </div>
<input type="hidden" name="issueId" value="@issue.issueId"/> <div class="pull-right">
<input type="submit" class="btn btn-success" value="Comment"/> <input type="hidden" name="issueId" value="@issue.issueId"/>
@if(hasWritePermission || issue.openedUserName == loginAccount.get.userName){ <input type="submit" class="btn btn-success" value="Comment"/>
<input type="submit" class="btn" value="@{if(issue.closed) "Reopen" else "Close"}" id="action"/> @if(hasWritePermission || issue.openedUserName == loginAccount.get.userName){
} <input type="submit" class="btn" value="@{if(issue.closed) "Reopen" else "Close"}" id="action"/>
}
</div>
</form> </form>
} }
</div> </div>

View File

@@ -1,15 +1,21 @@
@(id: String, repository: service.RepositoryService.RepositoryInfo, active: String)(implicit context: app.Context) @(id: String, repository: service.RepositoryService.RepositoryInfo, active: String,
hideBranchPulldown: Boolean = false)(implicit context: app.Context)
@import context._ @import context._
@import view.helpers._ @import view.helpers._
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
@if(!hideBranchPulldown){
<li> <li>
<div class="btn-group" style="margin-right: 20px;"> <div class="btn-group" style="margin-right: 20px;">
<button class="btn dropdown-toggle" data-toggle="dropdown"> <button class="btn dropdown-toggle" data-toggle="dropdown">
@if(id.length == 40){ @if(id.length == 40){
tree: <strong>@id.substring(0, 10)</strong> tree: <strong>@id.substring(0, 10)</strong>
} else { }
@if(repository.branchList.contains(id)){
branch: <strong>@id</strong> branch: <strong>@id</strong>
} }
@if(repository.tags.exists(_.name == id)){
tag: <strong>@id</strong>
}
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
@@ -19,6 +25,7 @@
</ul> </ul>
</div> </div>
</li> </li>
}
<li@if(active=="files"){ class="active"}><a href="@url(repository)/tree/@id">Files</a></li> <li@if(active=="files"){ class="active"}><a href="@url(repository)/tree/@id">Files</a></li>
<li@if(active=="commits"){ class="active"}><a href="@url(repository)/commits/@id">Commits</a></li> <li@if(active=="commits"){ class="active"}><a href="@url(repository)/commits/@id">Commits</a></li>
<li@if(active=="tags"){ class="active"}><a href="@url(repository)/tags">Tags@if(repository.tags.length > 0){ <span class="badge">@repository.tags.length</span>}</a></li> <li@if(active=="tags"){ class="active"}><a href="@url(repository)/tags">Tags@if(repository.tags.length > 0){ <span class="badge">@repository.tags.length</span>}</a></li>

View File

@@ -3,7 +3,7 @@
@import view.helpers._ @import view.helpers._
@html.main(repository.owner + "/" + repository.name) { @html.main(repository.owner + "/" + repository.name) {
@html.header("code", repository) @html.header("code", repository)
@tab("master", repository, "tags") @* TODO DON'T display branch pulldown *@ @tab(repository.repository.defaultBranch, repository, "tags", true)
<h1>Tags</h1> <h1>Tags</h1>
<table class="table table-bordered"> <table class="table table-bordered">
<tr> <tr>

View File

@@ -8,7 +8,7 @@
<!-- Session configuration --> <!-- Session configuration -->
<!-- ===================================================================== --> <!-- ===================================================================== -->
<listener> <listener>
<listener-class>servlet.SessionCleanipListener</listener-class> <listener-class>servlet.SessionCleanupListener</listener-class>
</listener> </listener>
<!-- ===================================================================== --> <!-- ===================================================================== -->

View File

@@ -502,9 +502,18 @@ h4#issueTitle {
padding: 0px; padding: 0px;
} }
div.issue-avatar-image {
float: left;
}
div.issue-box {
margin-bottom: 15px;
margin-left: 50px;
}
div.issue-comment-box { div.issue-comment-box {
margin-bottom: 15px; margin-bottom: 15px;
margin-top: 25px; margin-left: 50px;
} }
div.issue-comment-action { div.issue-comment-action {