mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 19:45:57 +01:00
Fix error response.
This commit is contained in:
@@ -26,6 +26,9 @@ abstract class ControllerBase extends ScalatraFilter with ClientSideValidationFo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected def NotFound() = redirect("/")
|
||||||
|
protected def Unauthorized() = redirect("/")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Context(path: String, loginAccount: Option[Account])
|
case class Context(path: String, loginAccount: Option[Account])
|
||||||
@@ -26,8 +26,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/:owner") {
|
get("/:owner") {
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
|
getAccountByUserName(owner) match {
|
||||||
html.user(getAccountByUserName(owner).get, getRepositoriesOfUser(owner, servletContext))
|
case Some(account) => html.user(account, getRepositoriesOfUser(owner, servletContext))
|
||||||
|
case None => NotFound()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +101,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the file content of the specified branch or commit.
|
* Displays the file content of the specified branch or commit.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ trait SettingsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/settings")(ownerOnly {
|
get("/:owner/:repository/settings")(ownerOnly {
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
redirect("/%s/%s/settings/options".format(owner, repository))
|
redirect("/%s/%s/settings/options".format(owner, repository))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -40,7 +41,10 @@ trait SettingsControllerBase extends ControllerBase {
|
|||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
settings.html.options(getRepository(owner, repository, servletContext).get)
|
getRepository(owner, repository, servletContext) match {
|
||||||
|
case Some(r) => settings.html.options(r)
|
||||||
|
case None => NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +67,10 @@ trait SettingsControllerBase extends ControllerBase {
|
|||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
settings.html.collaborators(getCollaborators(owner, repository), getRepository(owner, repository, servletContext).get)
|
getRepository(owner, repository, servletContext) match {
|
||||||
|
case Some(r) => settings.html.collaborators(getCollaborators(owner, repository), r)
|
||||||
|
case None => NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +79,7 @@ trait SettingsControllerBase extends ControllerBase {
|
|||||||
post("/:owner/:repository/settings/collaborators/add", collaboratorForm)(ownerOnly { form =>
|
post("/:owner/:repository/settings/collaborators/add", collaboratorForm)(ownerOnly { form =>
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
addCollaborator(owner, repository, form.userName)
|
addCollaborator(owner, repository, form.userName)
|
||||||
redirect("/%s/%s/settings/collaborators".format(owner, repository))
|
redirect("/%s/%s/settings/collaborators".format(owner, repository))
|
||||||
})
|
})
|
||||||
@@ -83,6 +91,7 @@ trait SettingsControllerBase extends ControllerBase {
|
|||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val userName = params("name")
|
val userName = params("name")
|
||||||
|
|
||||||
removeCollaborator(owner, repository, userName)
|
removeCollaborator(owner, repository, userName)
|
||||||
redirect("/%s/%s/settings/collaborators".format(owner, repository))
|
redirect("/%s/%s/settings/collaborators".format(owner, repository))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package util
|
|||||||
|
|
||||||
import app.ControllerBase
|
import app.ControllerBase
|
||||||
import service._
|
import service._
|
||||||
|
import org.scalatra._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows only the repository owner and administrators.
|
* Allows only the repository owner and administrators.
|
||||||
*/
|
*/
|
||||||
trait OwnerOnlyAuthenticator { self: ControllerBase =>
|
trait OwnerOnlyAuthenticator { self: ControllerBase =>
|
||||||
|
|
||||||
protected def ownerOnly(action: => Any) = { authenticate(action) }
|
protected def ownerOnly(action: => Any) = { authenticate(action) }
|
||||||
protected def ownerOnly[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
protected def ownerOnly[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ trait OwnerOnlyAuthenticator { self: ControllerBase =>
|
|||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) if(x.userType == AccountService.Administrator) => action
|
case Some(x) if(x.userType == AccountService.Administrator) => action
|
||||||
case Some(x) if(request.getRequestURI.split("/")(1) == x.userName) => action
|
case Some(x) if(request.getRequestURI.split("/")(1) == x.userName) => action
|
||||||
case _ => redirect("/signin")
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,6 @@ trait OwnerOnlyAuthenticator { self: ControllerBase =>
|
|||||||
* Allows only signed in users.
|
* Allows only signed in users.
|
||||||
*/
|
*/
|
||||||
trait UsersOnlyAuthenticator { self: ControllerBase =>
|
trait UsersOnlyAuthenticator { self: ControllerBase =>
|
||||||
|
|
||||||
protected def usersOnly(action: => Any) = { authenticate(action) }
|
protected def usersOnly(action: => Any) = { authenticate(action) }
|
||||||
protected def usersOnly[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
protected def usersOnly[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ trait UsersOnlyAuthenticator { self: ControllerBase =>
|
|||||||
{
|
{
|
||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) => action
|
case Some(x) => action
|
||||||
case None => redirect("/signin")
|
case None => Unauthorized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +51,7 @@ trait AdminOnlyAuthenticator { self: ControllerBase =>
|
|||||||
{
|
{
|
||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) if(x.userType == AccountService.Administrator) => action
|
case Some(x) if(x.userType == AccountService.Administrator) => action
|
||||||
case _ => redirect("/signin")
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +61,6 @@ trait AdminOnlyAuthenticator { self: ControllerBase =>
|
|||||||
* Allows only collaborators and administrators.
|
* Allows only collaborators and administrators.
|
||||||
*/
|
*/
|
||||||
trait WritableRepositoryAuthenticator { self: ControllerBase with RepositoryService =>
|
trait WritableRepositoryAuthenticator { self: ControllerBase with RepositoryService =>
|
||||||
|
|
||||||
protected def writableRepository(action: => Any) = { authenticate(action) }
|
protected def writableRepository(action: => Any) = { authenticate(action) }
|
||||||
protected def writableRepository[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
protected def writableRepository[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
||||||
|
|
||||||
@@ -72,7 +70,7 @@ trait WritableRepositoryAuthenticator { self: ControllerBase with RepositoryServ
|
|||||||
case Some(x) if(x.userType == AccountService.Administrator) => action
|
case Some(x) if(x.userType == AccountService.Administrator) => action
|
||||||
case Some(x) if(paths(1) == x.userName) => action
|
case Some(x) if(paths(1) == x.userName) => action
|
||||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action
|
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action
|
||||||
case _ => redirect("/signin")
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +79,6 @@ trait WritableRepositoryAuthenticator { self: ControllerBase with RepositoryServ
|
|||||||
* Allows only the repository owner and administrators.
|
* Allows only the repository owner and administrators.
|
||||||
*/
|
*/
|
||||||
trait ReadableRepositoryAuthenticator { self: ControllerBase with RepositoryService =>
|
trait ReadableRepositoryAuthenticator { self: ControllerBase with RepositoryService =>
|
||||||
|
|
||||||
protected def readableRepository(action: => Any) = { authenticate(action) }
|
protected def readableRepository(action: => Any) = { authenticate(action) }
|
||||||
protected def readableRepository[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
protected def readableRepository[T](action: T => Any) = (form: T) => authenticate({action(form)})
|
||||||
|
|
||||||
@@ -96,7 +93,7 @@ trait ReadableRepositoryAuthenticator { self: ControllerBase with RepositoryServ
|
|||||||
case Some(x) if(x.userType == AccountService.Administrator) => action
|
case Some(x) if(x.userType == AccountService.Administrator) => action
|
||||||
case Some(x) if(paths(1) == x.userName) => action
|
case Some(x) if(paths(1) == x.userName) => action
|
||||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action
|
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action
|
||||||
case _ => redirect("/")
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user