Fix the repository url.

This commit is contained in:
takezoe
2013-06-16 03:20:34 +09:00
parent c3a4c36ac2
commit 676e6c6047
12 changed files with 48 additions and 40 deletions

View File

@@ -23,7 +23,7 @@ trait AccountControllerBase extends ControllerBase {
get("/:userName") {
val userName = params("userName")
getAccountByUserName(userName) match {
case Some(a) => account.html.userinfo(a, getRepositoriesOfUser(userName, servletContext))
case Some(a) => account.html.userinfo(a, getRepositoriesOfUser(userName, baseUrl))
case None => NotFound()
}
}

View File

@@ -29,6 +29,14 @@ abstract class ControllerBase extends ScalatraFilter with ClientSideValidationFo
protected def NotFound() = html.error("Not Found")
protected def Unauthorized() = redirect("/")
protected def baseUrl = {
println(request.getRequestURL.toString)
println(request.getRequestURI)
val url = request.getRequestURL.toString
println(url.substring(0, url.length - request.getRequestURI.length))
url.substring(0, url.length - request.getRequestURI.length)
}
}
case class Context(path: String, loginAccount: Option[Account])

View File

@@ -87,7 +87,7 @@ trait CreateRepositoryControllerBase extends ControllerBase {
def validate(name: String, value: String): Option[String] = {
if(!value.matches("^[a-zA-Z0-9\\-_]+$")){
Some("Repository name contains invalid character.")
} else if(getRepositoriesOfUser(context.loginAccount.get.userName, servletContext).contains(value)){
} else if(getRepositoriesOfUser(context.loginAccount.get.userName, baseUrl).contains(value)){
Some("Repository already exists.")
} else {
None

View File

@@ -7,7 +7,7 @@ class IndexController extends IndexControllerBase with RepositoryService with Ac
trait IndexControllerBase extends ControllerBase { self: RepositoryService =>
get("/"){
html.index(getAccessibleRepositories(context.loginAccount, servletContext))
html.index(getAccessibleRepositories(context.loginAccount, baseUrl))
}
}

View File

@@ -8,15 +8,15 @@ class IssuesController extends IssuesControllerBase
trait IssuesControllerBase extends ControllerBase { self: RepositoryService =>
get("/:owner/:repository/issues"){
issues.html.issues(getRepository(params("owner"), params("repository"), servletContext).get)
issues.html.issues(getRepository(params("owner"), params("repository"), baseUrl).get)
}
get("/:owner/:repository/issues/:id"){
issues.html.issue(getRepository(params("owner"), params("repository"), servletContext).get)
issues.html.issue(getRepository(params("owner"), params("repository"), baseUrl).get)
}
get("/:owner/:repository/issues/new"){
issues.html.issueedit(getRepository(params("owner"), params("repository"), servletContext).get)
issues.html.issueedit(getRepository(params("owner"), params("repository"), baseUrl).get)
}
post("/:owner/:repository/issues"){

View File

@@ -32,7 +32,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
val enableIssueLink = params("enableIssueLink").toBoolean
contentType = "text/html"
view.helpers.markdown(content, getRepository(owner, repository, servletContext).get,
view.helpers.markdown(content, getRepository(owner, repository, baseUrl).get,
enableWikiLink, enableCommitLink, enableIssueLink)
})
@@ -78,7 +78,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
val (logs, hasNext) = JGitUtil.getCommitLog(git, branchName, page, 30)
repo.html.commits(Nil, branchName, getRepository(owner, repository, servletContext).get,
repo.html.commits(Nil, branchName, getRepository(owner, repository, baseUrl).get,
logs.splitWith{ (commit1, commit2) =>
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
}, page, hasNext)
@@ -98,7 +98,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
val (logs, hasNext) = JGitUtil.getCommitLog(git, branchName, page, 30, path)
repo.html.commits(path.split("/").toList, branchName, getRepository(owner, repository, servletContext).get,
repo.html.commits(path.split("/").toList, branchName, getRepository(owner, repository, baseUrl).get,
logs.splitWith{ (commit1, commit2) =>
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
}, page, hasNext)
@@ -114,7 +114,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
val id = params("id") // branch name or commit id
val raw = params.get("raw").getOrElse("false").toBoolean
val path = multiParams("splat").head //.replaceFirst("^tree/.+?/", "")
val repositoryInfo = getRepository(owner, repository, servletContext).get
val repositoryInfo = getRepository(owner, repository, baseUrl).get
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
@@ -158,7 +158,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
getRepository(owner, repository, servletContext).get, JGitUtil.getDiffs(git, id))
getRepository(owner, repository, baseUrl).get, JGitUtil.getDiffs(git, id))
}
})
@@ -169,7 +169,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
val owner = params("owner")
val repository = params("repository")
repo.html.tags(getRepository(owner, repository, servletContext).get)
repo.html.tags(getRepository(owner, repository, baseUrl).get)
})
/**
@@ -223,7 +223,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
* @return HTML of the file list
*/
private def fileList(owner: String, repository: String, revstr: String = "", path: String = ".") = {
getRepository(owner, repository, servletContext) match {
getRepository(owner, repository, baseUrl) match {
case None => NotFound()
case Some(repositoryInfo) => {
val revision = if(revstr.isEmpty){

View File

@@ -43,7 +43,7 @@ trait SettingsControllerBase extends ControllerBase {
val owner = params("owner")
val repository = params("repository")
getRepository(owner, repository, servletContext) match {
getRepository(owner, repository, baseUrl) match {
case Some(r) => settings.html.options(r)
case None => NotFound()
}
@@ -69,7 +69,7 @@ trait SettingsControllerBase extends ControllerBase {
val owner = params("owner")
val repository = params("repository")
getRepository(owner, repository, servletContext) match {
getRepository(owner, repository, baseUrl) match {
case Some(r) => settings.html.collaborators(getCollaborators(owner, repository), r)
case None => NotFound()
}
@@ -105,7 +105,7 @@ trait SettingsControllerBase extends ControllerBase {
val owner = params("owner")
val repository = params("repository")
getRepository(owner, repository, servletContext) match {
getRepository(owner, repository, baseUrl) match {
case Some(r) => settings.html.delete(r)
case None => NotFound()
}

View File

@@ -33,7 +33,7 @@ trait WikiControllerBase extends ControllerBase {
val repository = params("repository")
getWikiPage(owner, repository, "Home") match {
case Some(page) => wiki.html.wiki("Home", page, getRepository(owner, repository, servletContext).get, isWritable(owner, repository))
case Some(page) => wiki.html.wiki("Home", page, getRepository(owner, repository, baseUrl).get, isWritable(owner, repository))
case None => redirect("/%s/%s/wiki/Home/_edit".format(owner, repository))
}
})
@@ -44,7 +44,7 @@ trait WikiControllerBase extends ControllerBase {
val pageName = params("page")
getWikiPage(owner, repository, pageName) match {
case Some(page) => wiki.html.wiki(pageName, page, getRepository(owner, repository, servletContext).get, isWritable(owner, repository))
case Some(page) => wiki.html.wiki(pageName, page, getRepository(owner, repository, baseUrl).get, isWritable(owner, repository))
case None => redirect("/%s/%s/wiki/%s/_edit".format(owner, repository, pageName)) // TODO URLEncode
}
})
@@ -56,7 +56,7 @@ trait WikiControllerBase extends ControllerBase {
JGitUtil.withGit(getWikiRepositoryDir(owner, repository)){ git =>
wiki.html.wikihistory(Some(page),
JGitUtil.getCommitLog(git, "master", path = page + ".md")._1, getRepository(owner, repository, servletContext).get)
JGitUtil.getCommitLog(git, "master", path = page + ".md")._1, getRepository(owner, repository, baseUrl).get)
}
})
@@ -68,7 +68,7 @@ trait WikiControllerBase extends ControllerBase {
JGitUtil.withGit(getWikiRepositoryDir(owner, repository)){ git =>
wiki.html.wikicompare(Some(page),
getWikiDiffs(git, commitId(0), commitId(1)), getRepository(owner, repository, servletContext).get)
getWikiDiffs(git, commitId(0), commitId(1)), getRepository(owner, repository, baseUrl).get)
}
})
@@ -79,7 +79,7 @@ trait WikiControllerBase extends ControllerBase {
JGitUtil.withGit(getWikiRepositoryDir(owner, repository)){ git =>
wiki.html.wikicompare(None,
getWikiDiffs(git, commitId(0), commitId(1)), getRepository(owner, repository, servletContext).get)
getWikiDiffs(git, commitId(0), commitId(1)), getRepository(owner, repository, baseUrl).get)
}
})
@@ -89,7 +89,7 @@ trait WikiControllerBase extends ControllerBase {
val page = params("page")
wiki.html.wikiedit(page,
getWikiPage(owner, repository, page), getRepository(owner, repository, servletContext).get)
getWikiPage(owner, repository, page), getRepository(owner, repository, baseUrl).get)
})
post("/:owner/:repository/wiki/_edit", editForm)(writableRepository { form =>
@@ -106,7 +106,7 @@ trait WikiControllerBase extends ControllerBase {
val owner = params("owner")
val repository = params("repository")
wiki.html.wikiedit("", None, getRepository(owner, repository, servletContext).get)
wiki.html.wikiedit("", None, getRepository(owner, repository, baseUrl).get)
})
post("/:owner/:repository/wiki/_new", newForm)(writableRepository { form =>
@@ -133,7 +133,7 @@ trait WikiControllerBase extends ControllerBase {
val owner = params("owner")
val repository = params("repository")
wiki.html.wikipages(getWikiPageList(owner, repository), getRepository(owner, repository, servletContext).get, isWritable(owner, repository))
wiki.html.wikipages(getWikiPageList(owner, repository), getRepository(owner, repository, baseUrl).get, isWritable(owner, repository))
})
get("/:owner/:repository/wiki/_history")(readableRepository {
@@ -142,7 +142,7 @@ trait WikiControllerBase extends ControllerBase {
JGitUtil.withGit(getWikiRepositoryDir(owner, repository)){ git =>
wiki.html.wikihistory(None,
JGitUtil.getCommitLog(git, "master")._1, getRepository(owner, repository, servletContext).get)
JGitUtil.getCommitLog(git, "master")._1, getRepository(owner, repository, baseUrl).get)
}
})

View File

@@ -56,10 +56,10 @@ trait RepositoryService { self: AccountService =>
* Returns the list of specified user's repositories information.
*
* @param userName the user name
* @param servletContext the servlet context
* @param baseUrl the base url of this application
* @return the list of repository information which is sorted in descending order of lastActivityDate.
*/
def getRepositoriesOfUser(userName: String, servletContext: ServletContext): List[RepositoryInfo] = {
def getRepositoriesOfUser(userName: String, baseUrl: String): List[RepositoryInfo] = {
val q1 = Repositories
.filter { r => r.userName is userName.bind }
.map { r => r }
@@ -70,7 +70,7 @@ trait RepositoryService { self: AccountService =>
.map { case (c, r) => r }
q1.union(q2).sortBy(_.lastActivityDate).list map { repository =>
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
}
}
@@ -80,14 +80,14 @@ trait RepositoryService { self: AccountService =>
*
* @param userName the user name of the repository owner
* @param repositoryName the repository name
* @param servletContext the servlet context
* @param baseUrl the base url of this application
* @return the repository information
*/
def getRepository(userName: String, repositoryName: String, servletContext: ServletContext): Option[RepositoryInfo] = {
def getRepository(userName: String, repositoryName: String, baseUrl: String): Option[RepositoryInfo] = {
(Query(Repositories) filter { repository =>
(repository.userName is userName.bind) && (repository.repositoryName is repositoryName.bind)
} firstOption) map { repository =>
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
}
}
@@ -96,15 +96,15 @@ trait RepositoryService { self: AccountService =>
* Returns the list of accessible repositories information for the specified account user.
*
* @param account the account
* @param servletContext the servlet context
* @param baseUrl the base url of this application
* @return the repository informations which is sorted in descending order of lastActivityDate.
*/
def getAccessibleRepositories(account: Option[Account], servletContext: ServletContext): List[RepositoryInfo] = {
def getAccessibleRepositories(account: Option[Account], baseUrl: String): List[RepositoryInfo] = {
account match {
// for Administrators
case Some(x) if(x.userType == AccountService.Administrator) => {
(Query(Repositories) sortBy(_.lastActivityDate desc) list) map { repository =>
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
}
}
@@ -112,14 +112,14 @@ trait RepositoryService { self: AccountService =>
case Some(x) if(x.userType == AccountService.Normal) => {
// TODO only repositories registered as collaborator
(Query(Repositories) sortBy(_.lastActivityDate desc) list) map { repository =>
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
}
}
// for Guests
case None => {
(Query(Repositories) filter(_.repositoryType is Public.bind) sortBy(_.lastActivityDate desc) list) map { repository =>
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
}
}

View File

@@ -25,7 +25,7 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
val repositoryOwner = paths(2)
val repositoryName = paths(3).replaceFirst("\\.git$", "")
getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki", ""), request.getServletContext) match {
getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki", ""), "") match {
case Some(repository) => {
if(!request.getRequestURI.endsWith("/git-receive-pack") &&
repository.repository.repositoryType == RepositoryService.Public){

View File

@@ -85,7 +85,7 @@ trait ReadableRepositoryAuthenticator { self: ControllerBase with RepositoryServ
private def authenticate(action: => Any) = {
{
val paths = request.getRequestURI.split("/")
getRepository(paths(1), paths(2), servletContext) match {
getRepository(paths(1), paths(2), baseUrl) match {
case None => NotFound()
case Some(repository) =>
if(repository.repository.repositoryType == RepositoryService.Public){

View File

@@ -110,10 +110,10 @@ object JGitUtil {
/**
* Returns the repository information. It contains branch names and tag names.
*/
def getRepositoryInfo(owner: String, repository: String, servletContext: ServletContext): RepositoryInfo = {
def getRepositoryInfo(owner: String, repository: String, baseUrl: String): RepositoryInfo = {
withGit(getRepositoryDir(owner, repository)){ git =>
RepositoryInfo(
owner, repository, "http://localhost:8080%s/git/%s/%s.git".format(servletContext.getContextPath, owner, repository),
owner, repository, baseUrl + "/git/%s/%s.git".format(owner, repository),
// branches
git.branchList.call.asScala.map { ref =>
ref.getName.replaceFirst("^refs/heads/", "")