Readonly on online-editor

This commit is contained in:
nazoking
2015-12-04 14:51:39 +09:00
parent 9d6258861a
commit 89210985d4
6 changed files with 24 additions and 10 deletions

View File

@@ -28,7 +28,7 @@ abstract class ControllerBase extends ScalatraFilter
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.

View File

@@ -155,7 +155,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
}
JsonFormat(ApiBranch(branch, protection)(RepositoryName(repository)))
}) getOrElse NotFound
});
})
/**
* Display the Collaborators page.

View File

@@ -14,7 +14,7 @@ import gitbucket.core.util.ControlUtil._
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 @@ import org.scalatra._
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 @@ class RepositoryViewerController extends RepositoryViewerControllerBase
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 @@ trait RepositoryViewerControllerBase extends ControllerBase {
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 @@ trait RepositoryViewerControllerBase extends ControllerBase {
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
}
})

View File

@@ -22,6 +22,8 @@ trait ProtectedBrancheService {
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{

View File

@@ -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){
<div class="alert alert-danger">branch @branch is protected.</div>
}
<form method="POST" action="@url(repository)/@if(fileName.isEmpty){create}else{update}" validate="true">
<span class="error" id="error-newFileName"></span>
<div class="head">
@@ -82,6 +86,9 @@ $(function(){
@if(fileName.isDefined){
editor.getSession().setMode("ace/mode/@editorType(fileName.get)");
}
@if(protectedBranch){
editor.setReadOnly(true);
}
editor.on('change', function(){
updateCommitButtonStatus();

View File

@@ -55,8 +55,8 @@
function getValue(){
var v = {}, contexts=[];
$("input[type=checkbox]:checked").each(function(){
if(this.name == 'context'){
contexts.push(this.name);
if(this.name === 'contexts'){
contexts.push(this.value);
}else{
v[this.name] = true;
}