Przeglądaj źródła

[DOI] Gin should not link to doid directly

Instead here a explicit doi route is added, which in turn, does a redirect
cgars 7 lat temu
rodzic
commit
dfac0e994f
3 zmienionych plików z 15 dodań i 1 usunięć
  1. 1 0
      cmd/web.go
  2. 13 0
      routes/doi.go
  3. 1 1
      templates/repo/header.tmpl

+ 1 - 0
cmd/web.go

@@ -494,6 +494,7 @@ func runWeb(c *cli.Context) error {
 		m.Get("/issues/:index", repo.ViewIssue)
 		m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
 		m.Get("/milestones", repo.Milestones)
+		m.Get("/doi", routes.RequestDoi)
 	}, ignSignIn, context.RepoAssignment(true))
 	m.Group("/:username/:reponame", func() {
 		// FIXME: should use different URLs but mostly same logic for comments of issue and pull reuqest.

+ 13 - 0
routes/doi.go

@@ -0,0 +1,13 @@
+package routes
+
+import (
+	"github.com/G-Node/gogs/pkg/context"
+	"github.com/G-Node/gogs/pkg/setting"
+	"fmt"
+)
+
+func RequestDoi(c *context.Context) {
+	token := c.GetCookie(setting.SessionConfig.CookieName)
+	c.Redirect(fmt.Sprintf("https://doi.gin.g-node.org/?repo=%s&user=%s&token=%s", c.Repo.Repository.FullName(),
+		c.User.Name, token))
+}

+ 1 - 1
templates/repo/header.tmpl

@@ -42,7 +42,7 @@
 							{{if and $.DOI $.IsRepositoryAdmin}}
 							<div class="ui labeled button" tabindex="0">
 								<a class="ui basic button"
-									 href="https://doi.gin.g-node.org/?repo={{.FullName}}&user={{.Owner.Name}}&token={{$.SessionID}}">
+									 href="/{{.Owner.Name}}/{{.Name}}/doi">
 									<i class="octicon octicon-squirrel"></i> DOIfy
 								</a>
 							</div>