diff --git a/README.md b/README.md index 59c0b07..5b9b714 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -GitBucket [![Gitter chat](https://badges.gitter.im/gitbucket/gitbucket.svg)](https://gitter.im/gitbucket/gitbucket) [![Build Status](https://travis-ci.org/gitbucket/gitbucket.svg?branch=master)](https://travis-ci.org/gitbucket/gitbucket) +GitBucket [![Gitter chat](https://badges.gitter.im/gitbucket/gitbucket.svg)](https://gitter.im/gitbucket/gitbucket) [![Build Status](https://travis-ci.org/gitbucket/gitbucket.svg?branch=master)](https://travis-ci.org/gitbucket/gitbucket) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.gitbucket/gitbucket_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.gitbucket/gitbucket_2.12) ========= GitBucket is a Git web platform powered by Scala offering: diff --git a/project/plugins.sbt b/project/plugins.sbt index d0a6b26..6a4a3f3 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature") -addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.4.0") +addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.0") addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.3.13") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5") //addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.0") diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala index c555ec4..7dd8fd5 100644 --- a/src/main/scala/gitbucket/core/util/Authenticator.scala +++ b/src/main/scala/gitbucket/core/util/Authenticator.scala @@ -15,14 +15,10 @@ 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() - } - } + context.loginAccount match { + case Some(x) if (x.isAdmin) => action + case Some(x) if (request.paths(0) == x.userName) => action + case _ => Unauthorized() } } } @@ -35,24 +31,22 @@ 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() + val userName = params("owner") + val repoName = params("repository") + getRepository(userName, repoName).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(userName, repoName, Seq(Role.ADMIN)).contains(x.userName)) => + action(repository) + case _ => Unauthorized() } - } + } getOrElse NotFound() } } @@ -64,11 +58,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 +73,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,17 +88,15 @@ 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() + val userName = params("owner") + val repoName = params("repository") + getRepository(userName, repoName).map { repository => + if (isReadable(repository.repository, context.loginAccount)) { + action(repository) + } else { + Unauthorized() } - } + } getOrElse NotFound() } } @@ -122,20 +110,18 @@ } 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() + val userName = params("owner") + val repoName = params("repository") + getRepository(userName, repoName).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 (userName == x.userName) => action(repository) + case Some(x) if (getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository) + case Some(x) if (getCollaboratorUserNames(userName, repoName).contains(x.userName)) => action(repository) + case _ => Unauthorized() } - } + } getOrElse NotFound() } } @@ -149,22 +135,20 @@ } 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() + val userName = params("owner") + val repoName = params("repository") + getRepository(userName, repoName).map { repository => + context.loginAccount match { + case Some(x) if (x.isAdmin) => action(repository) + case Some(x) if (userName == x.userName) => action(repository) + case Some(x) if (getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository) + case Some(x) + if (getCollaboratorUserNames(userName, repoName, Seq(Role.ADMIN, Role.DEVELOPER)) + .contains(x.userName)) => + action(repository) + case _ => Unauthorized() } - } + } getOrElse NotFound() } } @@ -176,16 +160,12 @@ 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() - } - } + context.loginAccount match { + case Some(x) if (getGroupMembers(request.paths(0)).exists { member => + member.userName == x.userName && member.isManager + }) => + action + case _ => Unauthorized() } } } diff --git a/src/main/twirl/gitbucket/core/helper/diff.scala.html b/src/main/twirl/gitbucket/core/helper/diff.scala.html index bf16270..c581c8b 100644 --- a/src/main/twirl/gitbucket/core/helper/diff.scala.html +++ b/src/main/twirl/gitbucket/core/helper/diff.scala.html @@ -103,8 +103,8 @@ } else { @if(diff.newContent != None || diff.oldContent != None){
- - + + } else { @if(diff.newIsImage || diff.oldIsImage){
diff --git a/src/main/webapp/assets/common/js/gitbucket.js b/src/main/webapp/assets/common/js/gitbucket.js index 991b254..3cbbcc4 100644 --- a/src/main/webapp/assets/common/js/gitbucket.js +++ b/src/main/webapp/assets/common/js/gitbucket.js @@ -78,9 +78,9 @@ function diffUsingJS(oldTextId, newTextId, outputId, viewType, ignoreSpace) { var old = $('#'+oldTextId), head = $('#'+newTextId); var render = new JsDiffRender({ - oldText: old.val(), + oldText: old.data('val'), oldTextName: old.data('file-name'), - newText: head.val(), + newText: head.data('val'), newTextName: head.data('file-name'), ignoreSpace: ignoreSpace, contextSize: 4 @@ -116,7 +116,7 @@ return function(ln){ if(dom===null){ var html = prettyPrintOne( - text.replace(/&/g,'&').replace(//g,'>'), + text.replace(/&/g,'&').replace(//g,'>').replace(/^\n/, '\n\n'), (/\.([^.]*)$/.exec(fileName)||[])[1], true); var re = /]*id="?L([0-9]+)"?[^>]*>(.*?)<\/li>/gi, h;