From 579e5e4fee59f01f8a438e7ef977f34fa5dba72c Mon Sep 17 00:00:00 2001 From: Unknwon 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 5ca6c4dfd..b7c5c90d6 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 85fc01962..df7e970af 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 2be982047..723b6dbfb 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 aab35785f..a8cc47885 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 0bbb321a1..721eb5bc1 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 5c6a536c2..7ef75277e 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -33,18 +33,22 @@
-
- {{if .CanAddFile}} - - {{.i18n.Tr "repo.editor.new_file"}} - - {{end}} - {{if .UploadFileLink}} - - {{end}} -
+ {{if .Repository.CanEnableEditor}} +
+ {{if .CanAddFile}} + + {{.i18n.Tr "repo.editor.new_file"}} + + {{end}} + {{if .UploadFileLink}} + + {{end}} +
+ {{end}} + + {{if eq $n 0}}
- {{if .CanEditFile}} - - {{else}} - - {{end}} - {{if .CanDeleteFile}} - - {{else}} - + {{if .Repository.CanEnableEditor}} + {{if .CanEditFile}} + + {{else}} + + {{end}} + {{if .CanDeleteFile}} + + {{else}} + + {{end}} {{end}}
{{end}}