diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala index c555ec4..03f0e59 100644 --- a/src/main/scala/gitbucket/core/util/Authenticator.scala +++ b/src/main/scala/gitbucket/core/util/Authenticator.scala @@ -15,13 +15,11 @@ protected def oneselfOnly[T](action: T => Any) = (form: T) => { authenticate(action(form)) } private def authenticate(action: => Any) = { - { - defining(request.paths) { paths => - context.loginAccount match { - case Some(x) if (x.isAdmin) => action - case Some(x) if (paths(0) == x.userName) => action - case _ => Unauthorized() - } + defining(request.paths) { paths => + context.loginAccount match { + case Some(x) if (x.isAdmin) => action + case Some(x) if (paths(0) == x.userName) => action + case _ => Unauthorized() } } } @@ -35,23 +33,21 @@ protected def ownerOnly[T](action: (T, RepositoryInfo) => Any) = (form: T) => { authenticate(action(form, _)) } private def authenticate(action: (RepositoryInfo) => Any) = { - { - defining(request.paths) { paths => - getRepository(paths(0), paths(1)).map { repository => - context.loginAccount match { - case Some(x) if (x.isAdmin) => action(repository) - case Some(x) if (repository.owner == x.userName) => action(repository) - // TODO Repository management is allowed for only group managers? - case Some(x) if (getGroupMembers(repository.owner).exists { m => - m.userName == x.userName && m.isManager == true - }) => - action(repository) - case Some(x) if (getCollaboratorUserNames(paths(0), paths(1), Seq(Role.ADMIN)).contains(x.userName)) => - action(repository) - case _ => Unauthorized() - } - } getOrElse NotFound() - } + defining(request.paths) { paths => + getRepository(paths(0), paths(1)).map { repository => + context.loginAccount match { + case Some(x) if (x.isAdmin) => action(repository) + case Some(x) if (repository.owner == x.userName) => action(repository) + // TODO Repository management is allowed for only group managers? + case Some(x) if (getGroupMembers(repository.owner).exists { m => + m.userName == x.userName && m.isManager == true + }) => + action(repository) + case Some(x) if (getCollaboratorUserNames(paths(0), paths(1), Seq(Role.ADMIN)).contains(x.userName)) => + action(repository) + case _ => Unauthorized() + } + } getOrElse NotFound() } } } @@ -64,11 +60,9 @@ protected def usersOnly[T](action: T => Any) = (form: T) => { authenticate(action(form)) } private def authenticate(action: => Any) = { - { - context.loginAccount match { - case Some(x) => action - case None => Unauthorized() - } + context.loginAccount match { + case Some(x) => action + case None => Unauthorized() } } } @@ -81,11 +75,9 @@ protected def adminOnly[T](action: T => Any) = (form: T) => { authenticate(action(form)) } private def authenticate(action: => Any) = { - { - context.loginAccount match { - case Some(x) if (x.isAdmin) => action - case _ => Unauthorized() - } + context.loginAccount match { + case Some(x) if (x.isAdmin) => action + case _ => Unauthorized() } } } @@ -98,16 +90,14 @@ protected def referrersOnly[T](action: (T, RepositoryInfo) => Any) = (form: T) => { authenticate(action(form, _)) } private def authenticate(action: (RepositoryInfo) => Any) = { - { - defining(request.paths) { paths => - getRepository(paths(0), paths(1)).map { repository => - if (isReadable(repository.repository, context.loginAccount)) { - action(repository) - } else { - Unauthorized() - } - } getOrElse NotFound() - } + defining(request.paths) { paths => + getRepository(paths(0), paths(1)).map { repository => + if (isReadable(repository.repository, context.loginAccount)) { + action(repository) + } else { + Unauthorized() + } + } getOrElse NotFound() } } } @@ -122,19 +112,17 @@ } private def authenticate(action: (RepositoryInfo) => Any) = { - { - defining(request.paths) { paths => - getRepository(paths(0), paths(1)).map { repository => - context.loginAccount match { - case Some(x) if (x.isAdmin) => action(repository) - case Some(x) if (!repository.repository.isPrivate) => action(repository) - case Some(x) if (paths(0) == x.userName) => action(repository) - case Some(x) if (getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository) - case Some(x) if (getCollaboratorUserNames(paths(0), paths(1)).contains(x.userName)) => action(repository) - case _ => Unauthorized() - } - } getOrElse NotFound() - } + defining(request.paths) { paths => + getRepository(paths(0), paths(1)).map { repository => + context.loginAccount match { + case Some(x) if (x.isAdmin) => action(repository) + case Some(x) if (!repository.repository.isPrivate) => action(repository) + case Some(x) if (paths(0) == x.userName) => action(repository) + case Some(x) if (getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository) + case Some(x) if (getCollaboratorUserNames(paths(0), paths(1)).contains(x.userName)) => action(repository) + case _ => Unauthorized() + } + } getOrElse NotFound() } } } @@ -149,21 +137,19 @@ } private def authenticate(action: (RepositoryInfo) => Any) = { - { - defining(request.paths) { paths => - getRepository(paths(0), paths(1)).map { repository => - context.loginAccount match { - case Some(x) if (x.isAdmin) => action(repository) - case Some(x) if (paths(0) == x.userName) => action(repository) - case Some(x) if (getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository) - case Some(x) - if (getCollaboratorUserNames(paths(0), paths(1), Seq(Role.ADMIN, Role.DEVELOPER)) - .contains(x.userName)) => - action(repository) - case _ => Unauthorized() - } - } getOrElse NotFound() - } + defining(request.paths) { paths => + getRepository(paths(0), paths(1)).map { repository => + context.loginAccount match { + case Some(x) if (x.isAdmin) => action(repository) + case Some(x) if (paths(0) == x.userName) => action(repository) + case Some(x) if (getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository) + case Some(x) + if (getCollaboratorUserNames(paths(0), paths(1), Seq(Role.ADMIN, Role.DEVELOPER)) + .contains(x.userName)) => + action(repository) + case _ => Unauthorized() + } + } getOrElse NotFound() } } } @@ -176,15 +162,13 @@ protected def managersOnly[T](action: T => Any) = (form: T) => { authenticate(action(form)) } private def authenticate(action: => Any) = { - { - defining(request.paths) { paths => - context.loginAccount match { - case Some(x) if (getGroupMembers(paths(0)).exists { member => - member.userName == x.userName && member.isManager - }) => - action - case _ => Unauthorized() - } + defining(request.paths) { paths => + context.loginAccount match { + case Some(x) if (getGroupMembers(paths(0)).exists { member => + member.userName == x.userName && member.isManager + }) => + action + case _ => Unauthorized() } } }