Skip to content

GIN DOI changes #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/G-Node/gogs/models"
"github.com/G-Node/gogs/pkg/bindata"
"github.com/G-Node/gogs/pkg/context"
"github.com/G-Node/gogs/pkg/dav"
"github.com/G-Node/gogs/pkg/form"
"github.com/G-Node/gogs/pkg/mailer"
"github.com/G-Node/gogs/pkg/setting"
Expand All @@ -43,7 +44,6 @@ import (
"github.com/G-Node/gogs/routes/org"
"github.com/G-Node/gogs/routes/repo"
"github.com/G-Node/gogs/routes/user"
"github.com/G-Node/gogs/pkg/dav"
"golang.org/x/net/webdav"
)

Expand Down Expand Up @@ -173,7 +173,6 @@ func runWeb(c *cli.Context) error {

m := newMacaron()


reqSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: true})
ignSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: setting.Service.RequireSignInView})
ignSignInAndCsrf := context.Toggle(&context.ToggleOptions{DisableCSRF: true})
Expand Down Expand Up @@ -486,7 +485,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)
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.
Expand Down
1 change: 0 additions & 1 deletion conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ INDEX_URL = localhost/index
SEACH_URL = localhost/search

[doi]
DO = false
DOI_URL = https://doi.gin.g-node.org/
; AES key (eg. openssl enc -aes-128-cbc -k secret -P -md sha1)
DOI_KEY = WONTWORK
Expand Down
6 changes: 3 additions & 3 deletions pkg/bindata/bindata.go

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions pkg/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,10 @@ var (
SearchUrl string
}

Doi struct {
Do bool
DoiUrl string
DoiKey string
DoiBase string
DOI struct {
URL string `ini:"DOI_URL"`
Key string `ini:"DOI_KEY"`
Base string `ini:"DOI_BASE"`
}

CliConfig struct {
Expand Down Expand Up @@ -689,7 +688,7 @@ func NewContext() {
log.Fatal(2, "Fail to map UI settings: %v", err)
} else if err = Cfg.Section("search").MapTo(&Search); err != nil {
log.Fatal(2, "Fail to map Search settings: %v", err)
} else if err = Cfg.Section("doi").MapTo(&Doi); err != nil {
} else if err = Cfg.Section("doi").MapTo(&DOI); err != nil {
log.Fatal(2, "Fail to map Doi settings: %v", err)
} else if err = Cfg.Section("cliconfig").MapTo(&CliConfig); err != nil {
log.Fatal(2, "Fail to map Client config settings: %v", err)
Expand Down
9 changes: 4 additions & 5 deletions routes/doi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ import (
log "gopkg.in/clog.v1"
)

func RequestDoi(c *context.Context) {
func RequestDOI(c *context.Context) {
if !c.Repo.IsAdmin() {
c.Status(http.StatusUnauthorized)
return
}
token := c.GetCookie(setting.SessionConfig.CookieName)
token, err := encrypt([]byte(setting.Doi.DoiKey), token)
token, err := encrypt([]byte(setting.DOI.Key), token)
if err != nil {
log.Error(0, "Could not encrypt Secret key:%s", err)
log.Error(2, "Could not encrypt Secret key: %s", err)
c.Status(http.StatusInternalServerError)
return
}
url := fmt.Sprintf("%s/?repo=%s&user=%s&token=%s", setting.Doi.DoiUrl, c.Repo.Repository.FullName(),
c.User.Name, token)
url := fmt.Sprintf("%s/register?repo=%s&user=%s&token=%s", setting.DOI.URL, c.Repo.Repository.FullName(), c.User.Name, token)
c.Redirect(url)
}

Expand Down
2 changes: 1 addition & 1 deletion routes/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func renderDirectory(c *context.Context, treeLink string) {
}
c.Data["DOIInfo"] = &doiInfo

doi := GDoiRepo(c, setting.Doi.DoiBase)
doi := GDoiRepo(c, setting.DOI.Base)
//ddata, err := ginDoi.GDoiMData(doi, "https://api.datacite.org/works/") //todo configure URL?

c.Data["DOIReg"] = libgin.IsRegisteredDOI(doi)
Expand Down