From 9b11c3e32037a77e53551127d26dbf54139aa2fc Mon Sep 17 00:00:00 2001
From: Divyam Bhasin <divbest99@gmail.com>
Date: Fri, 23 Oct 2020 19:01:58 -0400
Subject: [PATCH] #13091 - add new mirror button (#13105)

* added button

* got URL params to carry through to service specific migrate pages

* do not display add mirror button if mirroring turned off

* added corrections by reviewers

* Add silverwind's suggestion

Co-authored-by: silverwind <me@silverwind.io>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: silverwind <me@silverwind.io>
---
 routers/org/home.go                 | 2 ++
 routers/repo/migrate.go             | 3 +++
 templates/org/home.tmpl             | 3 +++
 templates/repo/migrate/migrate.tmpl | 4 ++--
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/routers/org/home.go b/routers/org/home.go
index 0a9f176bdc..9ca0258784 100644
--- a/routers/org/home.go
+++ b/routers/org/home.go
@@ -127,6 +127,8 @@ func Home(ctx *context.Context) {
 	ctx.Data["Members"] = members
 	ctx.Data["Teams"] = org.Teams
 
+	ctx.Data["DisabledMirrors"] = setting.Repository.DisableMirrors
+
 	pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
 	pager.SetDefaultParams(ctx)
 	ctx.Data["Page"] = pager
diff --git a/routers/repo/migrate.go b/routers/repo/migrate.go
index 9b10970bf0..d843a043a7 100644
--- a/routers/repo/migrate.go
+++ b/routers/repo/migrate.go
@@ -28,6 +28,9 @@ func Migrate(ctx *context.Context) {
 	ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...)
 	serviceType := ctx.QueryInt("service_type")
 	if serviceType == 0 {
+		ctx.Data["Org"] = ctx.Query("org")
+		ctx.Data["Mirror"] = ctx.Query("mirror")
+
 		ctx.HTML(200, tplMigrate)
 		return
 	}
diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl
index 024be119bd..fba7de3f1f 100644
--- a/templates/org/home.tmpl
+++ b/templates/org/home.tmpl
@@ -28,6 +28,9 @@
 			<div class="ui eleven wide column">
 				{{if .CanCreateOrgRepo}}
 					<div class="text right">
+            {{if not .DisabledMirrors}}
+						  <a class="ui green button" href="{{AppSubUrl}}/repo/migrate?org={{.Org.ID}}&mirror=1">{{.i18n.Tr "new_migrate"}}</a>
+            {{end}}
 						<a class="ui green button" href="{{AppSubUrl}}/repo/create?org={{.Org.ID}}">{{.i18n.Tr "new_repo"}}</a>
 					</div>
 					<div class="ui divider"></div>
diff --git a/templates/repo/migrate/migrate.tmpl b/templates/repo/migrate/migrate.tmpl
index 1521620b0e..a8b1244523 100644
--- a/templates/repo/migrate/migrate.tmpl
+++ b/templates/repo/migrate/migrate.tmpl
@@ -5,11 +5,11 @@
 			<div class="ui three stackable cards">
 				{{range .Services}}
 					<div class="ui card">
-						<a class="image" href="{{AppSubUrl}}/repo/migrate?service_type={{.}}">
+						<a class="image" href="{{AppSubUrl}}/repo/migrate?service_type={{.}}&org={{$.Org}}&mirror={{$.Mirror}}">
 							{{svg (Printf "gitea-%s" .Name) 184}}
 						</a>
 						<div class="content">
-							<a class="header" href="{{AppSubUrl}}/repo/migrate?service_type={{.}}">{{.Title}}</a>
+							<a class="header" href="{{AppSubUrl}}/repo/migrate?service_type={{.}}&org={{$.Org}}&mirror={{$.Mirror}}">{{.Title}}</a>
 							<div class="description">
 								{{(Printf "repo.migrate.%s.description" .Name) | $.i18n.Tr }}
 							</div>