Browse Source

Web editor: disallow edit mirror repository

Unknwon 3 years ago
parent
commit
579e5e4fee
7 changed files with 36 additions and 25 deletions
  1. 1 1
      README.md
  2. 1 1
      cmd/web.go
  3. 1 1
      gogs.go
  4. 5 0
      models/repo.go
  5. 1 1
      templates/.VERSION
  6. 16 12
      templates/repo/home.tmpl
  7. 11 9
      templates/repo/view_file.tmpl

+ 1 - 1
README.md

@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
3 3
 
4 4
 ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
5 5
 
6
-##### Current tip version: 0.9.91 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
6
+##### Current tip version: 0.9.92 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
7 7
 
8 8
 | Web | UI  | Preview  |
9 9
 |:-------------:|:-------:|:-------:|

+ 1 - 1
cmd/web.go

@@ -511,7 +511,7 @@ func runWeb(ctx *cli.Context) error {
511 511
 			// m.Post("/upload-file", repo.UploadFileToServer)
512 512
 			// m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
513 513
 		}, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
514
-			if ctx.Repo.IsViewCommit {
514
+			if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
515 515
 				ctx.Handle(404, "", nil)
516 516
 				return
517 517
 			}

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
17 17
 	"github.com/gogits/gogs/modules/setting"
18 18
 )
19 19
 
20
-const APP_VER = "0.9.91.0828"
20
+const APP_VER = "0.9.92.0828"
21 21
 
22 22
 func init() {
23 23
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 5 - 0
models/repo.go

@@ -444,6 +444,11 @@ func (repo *Repository) AllowsPulls() bool {
444 444
 	return repo.CanEnablePulls() && repo.EnablePulls
445 445
 }
446 446
 
447
+// CanEnableEditor returns true if repository meets the requirements of web editor.
448
+func (repo *Repository) CanEnableEditor() bool {
449
+	return !repo.IsMirror
450
+}
451
+
447 452
 // FIXME: should have a mutex to prevent producing same index for two issues that are created
448 453
 // closely enough.
449 454
 func (repo *Repository) NextIssueIndex() int64 {

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
1
-0.9.91.0828
1
+0.9.92.0828

+ 16 - 12
templates/repo/home.tmpl

@@ -33,18 +33,22 @@
33 33
 				</div>
34 34
 			</div>
35 35
 			<div class="right fitted item">
36
-				<div id="file-buttons" class="ui tiny buttons">
37
-					{{if .CanAddFile}}
38
-						<a href="{{.RepoLink}}/_new/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}" class="ui button">
39
-							{{.i18n.Tr "repo.editor.new_file"}}
40
-						</a>
41
-					{{end}}
42
-					{{if .UploadFileLink}}
43
-						<!-- <a href="{{EscapePound .UploadFileLink}}" class="ui button nowrap">
44
-							<i class="upload icon"></i> {{.i18n.Tr "repo.upload_file"}}
45
-						</a> -->
46
-					{{end}}
47
-				</div>
36
+				{{if .Repository.CanEnableEditor}}
37
+					<div id="file-buttons" class="ui tiny buttons">
38
+						{{if .CanAddFile}}
39
+							<a href="{{.RepoLink}}/_new/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}" class="ui button">
40
+								{{.i18n.Tr "repo.editor.new_file"}}
41
+							</a>
42
+						{{end}}
43
+						{{if .UploadFileLink}}
44
+							<!-- <a href="{{EscapePound .UploadFileLink}}" class="ui button nowrap">
45
+								<i class="upload icon"></i> {{.i18n.Tr "repo.upload_file"}}
46
+							</a> -->
47
+						{{end}}
48
+					</div>
49
+				{{end}}
50
+				
51
+				<!-- Only show colne panel in repository home page -->
48 52
 				{{if eq $n 0}}
49 53
 					<div class="ui action small input" id="clone-panel">
50 54
 						<button class="ui basic clone button" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">

+ 11 - 9
templates/repo/view_file.tmpl

@@ -20,15 +20,17 @@
20 20
 					<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
21 21
 					<a class="ui button" href="{{EscapePound .FileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
22 22
 				</div>
23
-				{{if .CanEditFile}}
24
-					<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>
25
-				{{else}}
26
-					<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
27
-				{{end}}
28
-				{{if .CanDeleteFile}}
29
-					<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>
30
-				{{else}}
31
-					<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
23
+				{{if .Repository.CanEnableEditor}}
24
+					{{if .CanEditFile}}
25
+						<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>
26
+					{{else}}
27
+						<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
28
+					{{end}}
29
+					{{if .CanDeleteFile}}
30
+						<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>
31
+					{{else}}
32
+						<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
33
+					{{end}}
32 34
 				{{end}}
33 35
 			</div>
34 36
 		{{end}}