mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-10-30 10:06:07 +01:00
Separate Authenticators to the trait from ControllerBase.
This commit is contained in:
@@ -26,101 +26,6 @@ abstract class ControllerBase extends ScalatraFilter with ClientSideValidationFo
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows only the repository owner and administrators.
|
||||
*/
|
||||
protected def ownerOnly(action: => Any) = {
|
||||
{
|
||||
context.loginAccount match {
|
||||
case Some(x) if(x.userType == AccountService.Administrator) => action
|
||||
case Some(x) if(request.getRequestURI.split("/")(1) == x.userName) => action
|
||||
case _ => redirect("/signin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows only the repository owner and administrators.
|
||||
*/
|
||||
protected def ownerOnly[T](action: T => Any) = {
|
||||
(form: T) => {
|
||||
context.loginAccount match {
|
||||
case Some(x) if(x.userType == AccountService.Administrator) => action(form)
|
||||
case Some(x) if(request.getRequestURI.split("/")(1) == x.userName) => action(form)
|
||||
case _ => redirect("/signin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows only signed in users.
|
||||
*/
|
||||
protected def usersOnly(action: => Any) = {
|
||||
{
|
||||
context.loginAccount match {
|
||||
case Some(x) => action
|
||||
case None => redirect("/signin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows only signed in users.
|
||||
*/
|
||||
protected def usersOnly[T](action: T => Any) = {
|
||||
(form: T) => {
|
||||
context.loginAccount match {
|
||||
case Some(x) => action(form)
|
||||
case None => redirect("/signin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Allows only collaborators and administrators.
|
||||
// */
|
||||
// protected def collaboratorsOnly(action: => Any) = {
|
||||
// {
|
||||
// context.loginAccount match {
|
||||
// case Some(x) if(x.userType == AccountService.Administrator) => action
|
||||
// case Some(x) if(request.getRequestURI.split("/")(1) == x.userName) => action
|
||||
// case Some(x) => {
|
||||
// val paths = request.getRequestURI.split("/")
|
||||
// if(getCollaborators(paths(1), paths(2)).contains(x.userName)){
|
||||
// action
|
||||
// } else {
|
||||
// redirect("/signin")
|
||||
// }
|
||||
// }
|
||||
// case None => redirect("/signin")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Allows only collaborators and administrators.
|
||||
// */
|
||||
// protected def collaboratorsOnly[T](action: T => Any) = {
|
||||
// (form: T) => {
|
||||
// context.loginAccount match {
|
||||
// case Some(x) if(x.userType == AccountService.Administrator) => action(form)
|
||||
// case Some(x) if(request.getRequestURI.split("/")(1) == x.userName) => action(form)
|
||||
// case Some(x) => {
|
||||
// val paths = request.getRequestURI.split("/")
|
||||
// if(getCollaborators(paths(1), paths(2)).contains(x.userName)){
|
||||
// action(form)
|
||||
// } else {
|
||||
// redirect("/signin")
|
||||
// }
|
||||
// }
|
||||
// case None => redirect("/signin")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// protected def adminOnly()
|
||||
|
||||
}
|
||||
|
||||
case class Context(path: String, loginAccount: Option[Account])
|
||||
Reference in New Issue
Block a user