diff --git a/src/main/scala/gitbucket/core/controller/ControllerBase.scala b/src/main/scala/gitbucket/core/controller/ControllerBase.scala index 63949ab..f98e9cb 100644 --- a/src/main/scala/gitbucket/core/controller/ControllerBase.scala +++ b/src/main/scala/gitbucket/core/controller/ControllerBase.scala @@ -28,7 +28,7 @@ with ClientSideValidationFormSupport with JacksonJsonSupport with I18nSupport with FlashMapSupport with Validations with SystemSettingsService { - implicit val jsonFormats = DefaultFormats + implicit val jsonFormats = gitbucket.core.api.JsonFormat.jsonFormats // TODO Scala 2.11 // // Don't set content type via Accept header. diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala index dca1b6b..d2af068 100644 --- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala @@ -155,7 +155,7 @@ } JsonFormat(ApiBranch(branch, protection)(RepositoryName(repository))) }) getOrElse NotFound - }); + }) /** * Display the Collaborators page. diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 2e63b17..824860e 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -14,7 +14,7 @@ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Directory._ import gitbucket.core.model.{Account, CommitState, WebHook} -import gitbucket.core.service.CommitStatusService +import gitbucket.core.service.{CommitStatusService, ProtectedBrancheService} import gitbucket.core.service.WebHookService._ import gitbucket.core.view import gitbucket.core.view.helpers @@ -34,7 +34,7 @@ class RepositoryViewerController extends RepositoryViewerControllerBase with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService - with WebHookPullRequestService with WebHookPullRequestReviewCommentService + with WebHookPullRequestService with WebHookPullRequestReviewCommentService with ProtectedBrancheService /** * The repository viewer. @@ -42,7 +42,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { self: RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService - with WebHookPullRequestService with WebHookPullRequestReviewCommentService => + with WebHookPullRequestService with WebHookPullRequestReviewCommentService with ProtectedBrancheService => ArchiveCommand.registerFormat("zip", new ZipFormat) ArchiveCommand.registerFormat("tar.gz", new TgzFormat) @@ -221,12 +221,16 @@ get("/:owner/:repository/new/*")(collaboratorsOnly { repository => val (branch, path) = splitPath(repository, multiParams("splat").head) + val protectedBranch = isProtectedBranchNeedStatusCheck(repository.owner, repository.name, branch, context.loginAccount.get.userName) html.editor(branch, repository, if(path.length == 0) Nil else path.split("/").toList, - None, JGitUtil.ContentInfo("text", None, Some("UTF-8"))) + None, JGitUtil.ContentInfo("text", None, Some("UTF-8")), + protectedBranch) }) get("/:owner/:repository/edit/*")(collaboratorsOnly { repository => val (branch, path) = splitPath(repository, multiParams("splat").head) + val protectedBranch = isProtectedBranchNeedStatusCheck(repository.owner, repository.name, branch, context.loginAccount.get.userName) + println(s"protectedBranch=${protectedBranch}") using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git => val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch)) @@ -234,7 +238,8 @@ getPathObjectId(git, path, revCommit).map { objectId => val paths = path.split("/") html.editor(branch, repository, paths.take(paths.size - 1).toList, Some(paths.last), - JGitUtil.getContentInfo(git, path, objectId)) + JGitUtil.getContentInfo(git, path, objectId), + protectedBranch) } getOrElse NotFound } }) diff --git a/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala b/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala index 6fb9bde..cafcd7a 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala @@ -22,6 +22,8 @@ new ProtectedBranchInfo(owner, repository, requireStatusChecksToPass, includeAdministrators) } } + def isProtectedBranchNeedStatusCheck(owner: String, repository: String, branch: String, user: String)(implicit session: Session): Boolean = + getProtectedBranchInfo(owner, repository, branch).map{a => println(a); a.needStatusCheck(user)}.getOrElse(false) def getProtectedBranchList(owner: String, repository: String)(implicit session: Session): List[String] = { // TODO: mock MockDB.data.filter{ diff --git a/src/main/twirl/gitbucket/core/repo/editor.scala.html b/src/main/twirl/gitbucket/core/repo/editor.scala.html index 8639ae8..98601de 100644 --- a/src/main/twirl/gitbucket/core/repo/editor.scala.html +++ b/src/main/twirl/gitbucket/core/repo/editor.scala.html @@ -2,11 +2,15 @@ repository: gitbucket.core.service.RepositoryService.RepositoryInfo, pathList: List[String], fileName: Option[String], - content: gitbucket.core.util.JGitUtil.ContentInfo)(implicit context: gitbucket.core.controller.Context) + content: gitbucket.core.util.JGitUtil.ContentInfo, + protectedBranch: Boolean)(implicit context: gitbucket.core.controller.Context) @import context._ @import gitbucket.core.view.helpers._ @html.main(if(fileName.isEmpty) "New File" else s"Editing ${fileName.get} at ${branch} - ${repository.owner}/${repository.name}", Some(repository)) { @html.menu("code", repository){ + @if(protectedBranch){ +