From 579e5e4fee59f01f8a438e7ef977f34fa5dba72c Mon Sep 17 00:00:00 2001
From: Unknwon <u@gogs.io>
Date: Sun, 28 Aug 2016 04:56:41 -0700
Subject: [PATCH] Web editor: disallow edit mirror repository

---
 README.md                     |  2 +-
 cmd/web.go                    |  2 +-
 gogs.go                       |  2 +-
 models/repo.go                |  5 +++++
 templates/.VERSION            |  2 +-
 templates/repo/home.tmpl      | 28 ++++++++++++++++------------
 templates/repo/view_file.tmpl | 20 +++++++++++---------
 7 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md
index 5ca6c4dfd0..b7c5c90d60 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
 
 ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
 
-##### Current tip version: 0.9.91 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
+##### Current tip version: 0.9.92 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
 
 | Web | UI  | Preview  |
 |:-------------:|:-------:|:-------:|
diff --git a/cmd/web.go b/cmd/web.go
index 85fc01962e..df7e970afd 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -511,7 +511,7 @@ func runWeb(ctx *cli.Context) error {
 			// m.Post("/upload-file", repo.UploadFileToServer)
 			// m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
 		}, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
-			if ctx.Repo.IsViewCommit {
+			if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
 				ctx.Handle(404, "", nil)
 				return
 			}
diff --git a/gogs.go b/gogs.go
index 2be982047c..723b6dbfb9 100644
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
 	"github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.9.91.0828"
+const APP_VER = "0.9.92.0828"
 
 func init() {
 	runtime.GOMAXPROCS(runtime.NumCPU())
diff --git a/models/repo.go b/models/repo.go
index aab35785fc..a8cc47885f 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -444,6 +444,11 @@ func (repo *Repository) AllowsPulls() bool {
 	return repo.CanEnablePulls() && repo.EnablePulls
 }
 
+// CanEnableEditor returns true if repository meets the requirements of web editor.
+func (repo *Repository) CanEnableEditor() bool {
+	return !repo.IsMirror
+}
+
 // FIXME: should have a mutex to prevent producing same index for two issues that are created
 // closely enough.
 func (repo *Repository) NextIssueIndex() int64 {
diff --git a/templates/.VERSION b/templates/.VERSION
index 0bbb321a1f..721eb5bc11 100644
--- a/templates/.VERSION
+++ b/templates/.VERSION
@@ -1 +1 @@
-0.9.91.0828
\ No newline at end of file
+0.9.92.0828
\ No newline at end of file
diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl
index 5c6a536c2c..7ef75277e6 100644
--- a/templates/repo/home.tmpl
+++ b/templates/repo/home.tmpl
@@ -33,18 +33,22 @@
 				</div>
 			</div>
 			<div class="right fitted item">
-				<div id="file-buttons" class="ui tiny buttons">
-					{{if .CanAddFile}}
-						<a href="{{.RepoLink}}/_new/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}" class="ui button">
-							{{.i18n.Tr "repo.editor.new_file"}}
-						</a>
-					{{end}}
-					{{if .UploadFileLink}}
-						<!-- <a href="{{EscapePound .UploadFileLink}}" class="ui button nowrap">
-							<i class="upload icon"></i> {{.i18n.Tr "repo.upload_file"}}
-						</a> -->
-					{{end}}
-				</div>
+				{{if .Repository.CanEnableEditor}}
+					<div id="file-buttons" class="ui tiny buttons">
+						{{if .CanAddFile}}
+							<a href="{{.RepoLink}}/_new/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}" class="ui button">
+								{{.i18n.Tr "repo.editor.new_file"}}
+							</a>
+						{{end}}
+						{{if .UploadFileLink}}
+							<!-- <a href="{{EscapePound .UploadFileLink}}" class="ui button nowrap">
+								<i class="upload icon"></i> {{.i18n.Tr "repo.upload_file"}}
+							</a> -->
+						{{end}}
+					</div>
+				{{end}}
+				
+				<!-- Only show colne panel in repository home page -->
 				{{if eq $n 0}}
 					<div class="ui action small input" id="clone-panel">
 						<button class="ui basic clone button" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl
index 5e1faf36ec..d0b793b0e7 100644
--- a/templates/repo/view_file.tmpl
+++ b/templates/repo/view_file.tmpl
@@ -20,15 +20,17 @@
 					<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
 					<a class="ui button" href="{{EscapePound .FileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
 				</div>
-				{{if .CanEditFile}}
-					<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-pencil btn-octicon poping up"  data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
-				{{else}}
-					<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
-				{{end}}
-				{{if .CanDeleteFile}}
-					<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up"  data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
-				{{else}}
-					<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
+				{{if .Repository.CanEnableEditor}}
+					{{if .CanEditFile}}
+						<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-pencil btn-octicon poping up"  data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
+					{{else}}
+						<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
+					{{end}}
+					{{if .CanDeleteFile}}
+						<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up"  data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
+					{{else}}
+						<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
+					{{end}}
 				{{end}}
 			</div>
 		{{end}}