Browse Source

fix repo settings external tracker failed and check external urls (#1215)

Lunny Xiao 2 years ago
parent
commit
be5738243c
2 changed files with 16 additions and 2 deletions
  1. 2 0
      options/locale/locale_en-US.ini
  2. 14 2
      routers/repo/setting.go

+ 2 - 0
options/locale/locale_en-US.ini

@@ -718,11 +718,13 @@ settings.wiki_desc = Enable wiki system
718 718
 settings.use_internal_wiki = Use builtin wiki
719 719
 settings.use_external_wiki = Use external wiki
720 720
 settings.external_wiki_url = External Wiki URL
721
+settings.external_wiki_url_error = External Wiki URL is invalid
721 722
 settings.external_wiki_url_desc = Visitors will be redirected to the specified URL when they click on the tab.
722 723
 settings.issues_desc = Enable issue tracker
723 724
 settings.use_internal_issue_tracker = Use builtin issue tracker
724 725
 settings.use_external_issue_tracker = Use external issue tracker
725 726
 settings.external_tracker_url = External Issue Tracker URL
727
+settings.external_tracker_url_error = External Issue Tracker URL is invalid
726 728
 settings.external_tracker_url_desc = Visitors will be redirected to the specified URL when they click on the tab.
727 729
 settings.tracker_url_format = External Issue Tracker URL Format
728 730
 settings.tracker_issue_style = External Issue Tracker Naming Style:

+ 14 - 2
routers/repo/setting.go

@@ -72,6 +72,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
72 72
 			err := models.NewRepoRedirect(ctx.Repo.Owner.ID, repo.ID, repo.Name, newRepoName)
73 73
 			if err != nil {
74 74
 				ctx.Handle(500, "NewRepoRedirect", err)
75
+				return
75 76
 			}
76 77
 
77 78
 			log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName)
@@ -151,6 +152,12 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
151 152
 
152 153
 		if form.EnableWiki {
153 154
 			if form.EnableExternalWiki {
155
+				if !strings.HasPrefix(form.ExternalWikiURL, "http://") && !strings.HasPrefix(form.ExternalWikiURL, "https://") {
156
+					ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error"))
157
+					ctx.Redirect(repo.Link() + "/settings")
158
+					return
159
+				}
160
+
154 161
 				units = append(units, models.RepoUnit{
155 162
 					RepoID: repo.ID,
156 163
 					Type:   models.UnitTypeExternalWiki,
@@ -171,10 +178,15 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
171 178
 
172 179
 		if form.EnableIssues {
173 180
 			if form.EnableExternalTracker {
181
+				if !strings.HasPrefix(form.ExternalTrackerURL, "http://") && !strings.HasPrefix(form.ExternalTrackerURL, "https://") {
182
+					ctx.Flash.Error(ctx.Tr("repo.settings.external_tracker_url_error"))
183
+					ctx.Redirect(repo.Link() + "/settings")
184
+					return
185
+				}
174 186
 				units = append(units, models.RepoUnit{
175 187
 					RepoID: repo.ID,
176
-					Type:   models.UnitTypeExternalWiki,
177
-					Index:  int(models.UnitTypeExternalWiki),
188
+					Type:   models.UnitTypeExternalTracker,
189
+					Index:  int(models.UnitTypeExternalTracker),
178 190
 					Config: &models.ExternalTrackerConfig{
179 191
 						ExternalTrackerURL:    form.ExternalTrackerURL,
180 192
 						ExternalTrackerFormat: form.TrackerURLFormat,