mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
Readonly on online-editor
This commit is contained in:
@@ -28,7 +28,7 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
with ClientSideValidationFormSupport with JacksonJsonSupport with I18nSupport with FlashMapSupport with Validations
|
with ClientSideValidationFormSupport with JacksonJsonSupport with I18nSupport with FlashMapSupport with Validations
|
||||||
with SystemSettingsService {
|
with SystemSettingsService {
|
||||||
|
|
||||||
implicit val jsonFormats = DefaultFormats
|
implicit val jsonFormats = gitbucket.core.api.JsonFormat.jsonFormats
|
||||||
|
|
||||||
// TODO Scala 2.11
|
// TODO Scala 2.11
|
||||||
// // Don't set content type via Accept header.
|
// // Don't set content type via Accept header.
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
JsonFormat(ApiBranch(branch, protection)(RepositoryName(repository)))
|
JsonFormat(ApiBranch(branch, protection)(RepositoryName(repository)))
|
||||||
}) getOrElse NotFound
|
}) getOrElse NotFound
|
||||||
});
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the Collaborators page.
|
* Display the Collaborators page.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import gitbucket.core.util.ControlUtil._
|
|||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.model.{Account, CommitState, WebHook}
|
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.service.WebHookService._
|
||||||
import gitbucket.core.view
|
import gitbucket.core.view
|
||||||
import gitbucket.core.view.helpers
|
import gitbucket.core.view.helpers
|
||||||
@@ -34,7 +34,7 @@ import org.scalatra._
|
|||||||
class RepositoryViewerController extends RepositoryViewerControllerBase
|
class RepositoryViewerController extends RepositoryViewerControllerBase
|
||||||
with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
|
with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
|
||||||
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService
|
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService
|
||||||
with WebHookPullRequestService with WebHookPullRequestReviewCommentService
|
with WebHookPullRequestService with WebHookPullRequestReviewCommentService with ProtectedBrancheService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The repository viewer.
|
* The repository viewer.
|
||||||
@@ -42,7 +42,7 @@ class RepositoryViewerController extends RepositoryViewerControllerBase
|
|||||||
trait RepositoryViewerControllerBase extends ControllerBase {
|
trait RepositoryViewerControllerBase extends ControllerBase {
|
||||||
self: RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
|
self: RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
|
||||||
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService
|
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("zip", new ZipFormat)
|
||||||
ArchiveCommand.registerFormat("tar.gz", new TgzFormat)
|
ArchiveCommand.registerFormat("tar.gz", new TgzFormat)
|
||||||
@@ -221,12 +221,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/new/*")(collaboratorsOnly { repository =>
|
get("/:owner/:repository/new/*")(collaboratorsOnly { repository =>
|
||||||
val (branch, path) = splitPath(repository, multiParams("splat").head)
|
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,
|
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 =>
|
get("/:owner/:repository/edit/*")(collaboratorsOnly { repository =>
|
||||||
val (branch, path) = splitPath(repository, multiParams("splat").head)
|
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 =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
@@ -234,7 +238,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
val paths = path.split("/")
|
val paths = path.split("/")
|
||||||
html.editor(branch, repository, paths.take(paths.size - 1).toList, Some(paths.last),
|
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
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ trait ProtectedBrancheService {
|
|||||||
new ProtectedBranchInfo(owner, repository, requireStatusChecksToPass, includeAdministrators)
|
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] = {
|
def getProtectedBranchList(owner: String, repository: String)(implicit session: Session): List[String] = {
|
||||||
// TODO: mock
|
// TODO: mock
|
||||||
MockDB.data.filter{
|
MockDB.data.filter{
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||||
pathList: List[String],
|
pathList: List[String],
|
||||||
fileName: Option[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 context._
|
||||||
@import gitbucket.core.view.helpers._
|
@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.main(if(fileName.isEmpty) "New File" else s"Editing ${fileName.get} at ${branch} - ${repository.owner}/${repository.name}", Some(repository)) {
|
||||||
@html.menu("code", repository){
|
@html.menu("code", repository){
|
||||||
|
@if(protectedBranch){
|
||||||
|
<div class="alert alert-danger">branch @branch is protected.</div>
|
||||||
|
}
|
||||||
<form method="POST" action="@url(repository)/@if(fileName.isEmpty){create}else{update}" validate="true">
|
<form method="POST" action="@url(repository)/@if(fileName.isEmpty){create}else{update}" validate="true">
|
||||||
<span class="error" id="error-newFileName"></span>
|
<span class="error" id="error-newFileName"></span>
|
||||||
<div class="head">
|
<div class="head">
|
||||||
@@ -82,6 +86,9 @@ $(function(){
|
|||||||
@if(fileName.isDefined){
|
@if(fileName.isDefined){
|
||||||
editor.getSession().setMode("ace/mode/@editorType(fileName.get)");
|
editor.getSession().setMode("ace/mode/@editorType(fileName.get)");
|
||||||
}
|
}
|
||||||
|
@if(protectedBranch){
|
||||||
|
editor.setReadOnly(true);
|
||||||
|
}
|
||||||
|
|
||||||
editor.on('change', function(){
|
editor.on('change', function(){
|
||||||
updateCommitButtonStatus();
|
updateCommitButtonStatus();
|
||||||
|
|||||||
@@ -55,8 +55,8 @@
|
|||||||
function getValue(){
|
function getValue(){
|
||||||
var v = {}, contexts=[];
|
var v = {}, contexts=[];
|
||||||
$("input[type=checkbox]:checked").each(function(){
|
$("input[type=checkbox]:checked").each(function(){
|
||||||
if(this.name == 'context'){
|
if(this.name === 'contexts'){
|
||||||
contexts.push(this.name);
|
contexts.push(this.value);
|
||||||
}else{
|
}else{
|
||||||
v[this.name] = true;
|
v[this.name] = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user