From 6926aa7aec6c190fa6aecc63c28c21c7691f2e8d Mon Sep 17 00:00:00 2001 From: arimuraterutoshiMac Date: Thu, 19 Apr 2018 01:51:24 +0900 Subject: [PATCH 1/6] Fix #1871: Fixed breaking newlines when starting with multiple blank lines --- src/main/twirl/gitbucket/core/helper/diff.scala.html | 4 ++-- src/main/webapp/assets/common/js/gitbucket.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/twirl/gitbucket/core/helper/diff.scala.html b/src/main/twirl/gitbucket/core/helper/diff.scala.html index bf16270f6..c581c8b28 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 991b25423..3cbbcc467 100644 --- a/src/main/webapp/assets/common/js/gitbucket.js +++ b/src/main/webapp/assets/common/js/gitbucket.js @@ -78,9 +78,9 @@ function displayErrors(data, elem){ 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 @@ function JsDiffRender(params){ 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; From c1d6839c1899f2a062f926dbf908e537b476a9b9 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 20 Apr 2018 20:00:25 +0900 Subject: [PATCH 2/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59c0b078f..5b9b71443 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: From 7c10cb0ec7a3b32e92c5a1bd9a17e58e78854de2 Mon Sep 17 00:00:00 2001 From: Yan Su Date: Tue, 24 Apr 2018 13:40:23 +0800 Subject: [PATCH 3/6] update scalafmt --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index d0a6b26f3..6a4a3f354 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") From ea69463fd2921a9544f50b87072b3440400238ad Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Tue, 24 Apr 2018 17:52:36 +0900 Subject: [PATCH 4/6] Remove unnecessary braces --- .../gitbucket/core/util/Authenticator.scala | 146 ++++++++---------- 1 file changed, 65 insertions(+), 81 deletions(-) diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala index c555ec474..03f0e593c 100644 --- a/src/main/scala/gitbucket/core/util/Authenticator.scala +++ b/src/main/scala/gitbucket/core/util/Authenticator.scala @@ -15,13 +15,11 @@ trait OneselfAuthenticator { self: ControllerBase => 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 @@ trait OwnerAuthenticator { self: ControllerBase with RepositoryService with Acco 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 @@ trait UsersAuthenticator { self: ControllerBase => 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 @@ trait AdminAuthenticator { self: ControllerBase => 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 @@ trait ReferrerAuthenticator { self: ControllerBase with RepositoryService with A 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 @@ trait ReadableUsersAuthenticator { self: ControllerBase with RepositoryService w } 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 @@ trait WritableUsersAuthenticator { self: ControllerBase with RepositoryService w } 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 @@ trait GroupManagerAuthenticator { self: ControllerBase with AccountService => 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() } } } From 07182cf946e3341dea267c6214cb34e76d5ae782 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Tue, 24 Apr 2018 18:22:04 +0900 Subject: [PATCH 5/6] Use parameter name to get repository owner and name from requested path --- .../gitbucket/core/util/Authenticator.scala | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala index 03f0e593c..5cc52a90b 100644 --- a/src/main/scala/gitbucket/core/util/Authenticator.scala +++ b/src/main/scala/gitbucket/core/util/Authenticator.scala @@ -15,12 +15,10 @@ trait OneselfAuthenticator { self: ControllerBase => 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() } } } @@ -33,22 +31,23 @@ trait OwnerAuthenticator { self: ControllerBase with RepositoryService with Acco 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 paths = request.paths + val userName = params.getOrElse("owner", paths(0)) + val repoName = params.getOrElse("repository", paths(1)) + 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() } } @@ -90,15 +89,16 @@ trait ReferrerAuthenticator { self: ControllerBase with RepositoryService with A 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 paths = request.paths + val userName = params.getOrElse("owner", paths(0)) + val repoName = params.getOrElse("repository", paths(1)) + getRepository(userName, repoName).map { repository => + if (isReadable(repository.repository, context.loginAccount)) { + action(repository) + } else { + Unauthorized() + } + } getOrElse NotFound() } } @@ -112,18 +112,19 @@ trait ReadableUsersAuthenticator { self: ControllerBase with RepositoryService w } 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 paths = request.paths + val userName = params.getOrElse("owner", paths(0)) + val repoName = params.getOrElse("repository", paths(1)) + 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() } } @@ -137,20 +138,21 @@ trait WritableUsersAuthenticator { self: ControllerBase with RepositoryService w } 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 paths = request.paths + val userName = params.getOrElse("owner", paths(0)) + val repoName = params.getOrElse("repository", paths(1)) + 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() } } @@ -162,14 +164,12 @@ trait GroupManagerAuthenticator { self: ControllerBase with AccountService => 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() } } } From 8b2b36df0eac6d258c4d0271d122309b6b5c5bd5 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 25 Apr 2018 01:55:02 +0900 Subject: [PATCH 6/6] Remove code in authenticators which keeps backward compatibility --- .../gitbucket/core/util/Authenticator.scala | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala index 5cc52a90b..7dd8fd534 100644 --- a/src/main/scala/gitbucket/core/util/Authenticator.scala +++ b/src/main/scala/gitbucket/core/util/Authenticator.scala @@ -31,9 +31,8 @@ trait OwnerAuthenticator { self: ControllerBase with RepositoryService with Acco protected def ownerOnly[T](action: (T, RepositoryInfo) => Any) = (form: T) => { authenticate(action(form, _)) } private def authenticate(action: (RepositoryInfo) => Any) = { - val paths = request.paths - val userName = params.getOrElse("owner", paths(0)) - val repoName = params.getOrElse("repository", paths(1)) + val userName = params("owner") + val repoName = params("repository") getRepository(userName, repoName).map { repository => context.loginAccount match { case Some(x) if (x.isAdmin) => action(repository) @@ -89,9 +88,8 @@ trait ReferrerAuthenticator { self: ControllerBase with RepositoryService with A protected def referrersOnly[T](action: (T, RepositoryInfo) => Any) = (form: T) => { authenticate(action(form, _)) } private def authenticate(action: (RepositoryInfo) => Any) = { - val paths = request.paths - val userName = params.getOrElse("owner", paths(0)) - val repoName = params.getOrElse("repository", paths(1)) + val userName = params("owner") + val repoName = params("repository") getRepository(userName, repoName).map { repository => if (isReadable(repository.repository, context.loginAccount)) { action(repository) @@ -112,9 +110,8 @@ trait ReadableUsersAuthenticator { self: ControllerBase with RepositoryService w } private def authenticate(action: (RepositoryInfo) => Any) = { - val paths = request.paths - val userName = params.getOrElse("owner", paths(0)) - val repoName = params.getOrElse("repository", paths(1)) + val userName = params("owner") + val repoName = params("repository") getRepository(userName, repoName).map { repository => context.loginAccount match { case Some(x) if (x.isAdmin) => action(repository) @@ -138,9 +135,8 @@ trait WritableUsersAuthenticator { self: ControllerBase with RepositoryService w } private def authenticate(action: (RepositoryInfo) => Any) = { - val paths = request.paths - val userName = params.getOrElse("owner", paths(0)) - val repoName = params.getOrElse("repository", paths(1)) + val userName = params("owner") + val repoName = params("repository") getRepository(userName, repoName).map { repository => context.loginAccount match { case Some(x) if (x.isAdmin) => action(repository)