Skip to content

Cherry picks from GIN DOI changes #44

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 5 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
1 change: 0 additions & 1 deletion conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,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
57 changes: 35 additions & 22 deletions conf/datacite/datacite.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,75 @@
# Required fields
# The main researchers involved working on the resource,
# or the authors of the publication in priority order.
# May be a corporate/institutional or personal name.
# Include digital identifier (e.g., ORCID) if possible
# Metadata for DOI registration according to DataCite Metadata Schema 4.1.
# For detailed schema description see https://doi.org/10.5438/0014

## Required fields

# The main researchers involved. Include digital identifier (e.g., ORCID)
# if possible, including the prefix to indicate its type.
authors:
-
firstname: "GivenName1"
lastname: "FamilyName1"
affiliation: "Affiliation1"
id: "AuthorID1 (e.g. ORCID)"
id: "ORCID:0000-0001-2345-6789"
-
firstname: "GivenName2"
lastname: "FamilyName2"
affiliation: "Affiliation2"
id: "ResearcherID:X-1234-5678"
-
firstname: "GivenName3"
lastname: "FamilyName3"

# A name or title to describe the published resource.
# A title to describe the published resource.
title: "Example Title"

# Any additional information. It is best practice to supply a description for the resource.
# Additional information about the resource, e.g., a brief abstract.
description: |
Example description
that can contain linebreaks
but has to maintain indentation.

# List of keywords the resource should be associated with.
# Lit of keywords the resource should be associated with.
# Give as many keywords as possible, to make the resource findable.
keywords:
- Neuroscience
- Electrophysiology

# Any rights information for this resource. Please provide both a license name and a link to the license.
# Please add also a LICENSE file to the repository
# License information for this resource. Please provide the license name and/or a link to the license.
# Please add also a corresponding LICENSE file to the repository.
license:
name: "Creative Commons CC0 1.0 Public Domain Dedication"
url: "https://creativecommons.org/publicdomain/zero/1.0/"



## Optional Fields

# Any funding reference for this resource. Separate funder name and grant number by comma
# Funding information for this resource.
# Separate funder name and grant number by comma.
funding:
- "DFG, DFG.12345"
- "EU, EU.12345"

# Related publications. reftype might be: IsCitedBy, IsSupplementTo, IsReferencedBy, IsPartOf
# for further valid types see https://schema.datacite.org/meta/kernel-4

# Related publications. reftype might be: IsSupplementTo, IsDescribedBy, IsReferencedBy.
# Please provide digital identifier (e.g., DOI) if possible.
# Add a prefix to the ID, separated by a colon, to indicate the source.
# Supported sources are: DOI, arXiv, PMID
references:
-
doi: "10.xxx/zzzz"
id: "doi:10.xxx/zzzz"
reftype: "IsSupplementTo"
name: "PublicationName1"
-
id: "arxiv:mmmm.nnnn"
reftype: "IsSupplementTo"
name: "PublicationName"
name: "PublicationName2"
-
reftype: "IsPartOf"
name: "PublicationName"
id: "pmid:nnnnnnnn"
reftype: "IsReferencedBy"
name: "PublicationName3"


# Type of the data in this repository (Dataset, Model, Software, Other see
# https://schema.datacite.org/meta/kernel-4.1/doc/DataCite-MetadataKernel_v4.1.pdf
# for examples
dtype: Dataset
# Resource type. Default is Dataset, other possible values are Software, DataPaper, Image, Text.
resourcetype: Dataset
7 changes: 3 additions & 4 deletions pkg/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,9 @@ var (
}

DOI struct {
Do bool
DOIURL string
DOIKey string
DOIBase string
URL string `ini:"DOI_URL"`
Key string `ini:"DOI_KEY"`
Base string `ini:"DOI_BASE"`
}

CLIConfig struct {
Expand Down
22 changes: 16 additions & 6 deletions routes/doi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"net/http"
"net/url"

"github.com/G-Node/gogs/pkg/context"
"github.com/G-Node/gogs/pkg/setting"
Expand All @@ -20,15 +20,25 @@ func RequestDOI(c *context.Context) {
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)
c.Redirect(url)
doiurl, err := url.Parse(setting.DOI.URL + "/register") // TODO: Handle error by notifying admin email
if err != nil {
log.Error(2, "Failed to parse DOI URL: %s", setting.DOI.URL)
}

params := url.Values{}
params.Add("repo", c.Repo.Repository.FullName())
params.Add("user", c.User.Name)
params.Add("token", token)
doiurl.RawQuery = params.Encode()
target, _ := url.PathUnescape(doiurl.String())
log.Trace(target)
c.RawRedirect(target)
}

// NOTE: TEMPORARY COPY FROM gin-doi
Expand Down
3 changes: 2 additions & 1 deletion routes/repo/repo_gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func serveAnnexedData(ctx *context.Context, name string, cpt *captcha.Captcha, b
}

func readDataciteFile(entry *git.TreeEntry, c *context.Context) {
log.Trace("Found datacite.yml file")
c.Data["HasDatacite"] = true
doiData, err := entry.Blob().Data()
if err != nil {
Expand All @@ -69,7 +70,7 @@ func readDataciteFile(entry *git.TreeEntry, c *context.Context) {
}
c.Data["DOIInfo"] = &doiInfo

doi := calcRepoDOI(c, setting.DOI.DOIBase)
doi := calcRepoDOI(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
4 changes: 3 additions & 1 deletion routes/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ func renderDirectory(c *context.Context, treeLink string) {
for _, entry := range entries {
if !entry.IsDir() && entry.Name() == "datacite.yml" {
readDataciteFile(entry, c)
continue
break
}
}
for _, entry := range entries {
if entry.IsDir() || !markup.IsReadmeFile(entry.Name()) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/doifile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<td>References</td>
<td>
{{range $index, $ref := .DOIInfo.References}}
{{ $ref.Name }} [{{ $ref.DOI }}] ({{ $ref.Reftype }})
{{ $ref.Name }} [{{ $ref.ID }}] ({{ $ref.Reftype }})
<br>
{{end}}
</td>
Expand Down
30 changes: 15 additions & 15 deletions vendor/github.com/G-Node/libgin/libgin/doi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.