Skip to content

Commit

Permalink
Merge branch 'release/1.9.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
patkyn committed Aug 25, 2020
2 parents 963368f + 3a03e9a commit 378dae7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CollectoryGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CollectoryGrailsPlugin {
def authenticateService

// the plugin version
def version = "1.9.9"
def version = "1.9.10"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.5 > *"
// resources that are excluded from plugin packaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ class DataController {
render(status:403, text: 'You are not authorised to use this service')
}

def checkApiKey = {
def apiKey = {
if(params.api_key){
params.api_key
} else {
request.getHeader("Authorization")
}
}.call()
def keyCheck
if (apiKey) {
keyCheck = collectoryAuthService?.checkApiKey(apiKey)
}
if (!keyCheck?.valid) {
return false
}
return true
}

/**
* Should be added for any uri that returns multiple formats based on content negotiation.
* (So the content can be correctly cached by proxies.)
Expand Down Expand Up @@ -306,6 +324,7 @@ class DataController {
* @param uid - optional uid of an instance of entity
* @param pg - optional instance specified by uid (added in beforeInterceptor)
* @param summary - any non-null value will cause a richer summary to be returned for entity lists
* @param api_key - optional param for displaying any sensitive data
*/
def getEntity = {
if (params.entity == 'tempDataResource') {
Expand All @@ -317,7 +336,13 @@ class DataController {
// return specified entity
addContentLocation "/ws/${urlForm}/${params.pg.uid}"
def eTag = (params.pg.uid + ":" + params.pg.lastUpdated).encodeAsMD5()
def entityInJson = crudService."read${clazz}"(params.pg)
def entityInJson
if (clazz == 'DataResource') {
def keyCheck = checkApiKey()
entityInJson = crudService."read${clazz}"(params.pg, keyCheck)
} else {
entityInJson = crudService."read${clazz}"(params.pg)
}
entityInJson = metadataService.convertAnyLocalPaths(entityInJson)
response.setContentType("application/json")
response.setCharacterEncoding("UTF-8")
Expand Down Expand Up @@ -602,10 +627,16 @@ class DataController {

/**
* Returns a single contact (independent of any entity).
* A valid api key is needed to display contact information
* URI form: /contacts/{id}
* @param id the database id of the contact
*/
def contacts = {

if (!checkApiKey()) {
unauthorised()
return
}
if (params.id) {
def c = Contact.get(params.id)
if (c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class IptController {
def create = params.create != null && params.create.equalsIgnoreCase("true")
def check = params.check == null || !params.check.equalsIgnoreCase("false")
def keyName = params.key ?: 'catalogNumber'
def isShareableWithGBIF = params.isShareableWithGBIF ? params.isShareableWithGBIF.toBoolean(): true
def provider = ProviderGroup._get(params.uid)
def apiKey = request.cookies.find { cookie -> cookie.name == API_KEY_COOKIE }
def keyCheck = apiKey ? collectoryAuthService.checkApiKey(apiKey.value) : null
Expand All @@ -55,7 +56,7 @@ class IptController {
return
}
try {
def updates = provider == null ? null : iptService.scan(provider, create, check, keyName, username, admin)
def updates = provider == null ? null : iptService.scan(provider, create, check, keyName, username, admin, isShareableWithGBIF)
log.info "${updates.size()} data resources to update for ${params.uid}"
response.addHeader HttpHeaders.VARY, HttpHeaders.ACCEPT
withFormat {
Expand Down
6 changes: 3 additions & 3 deletions grails-app/services/au/org/ala/collectory/CrudService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CrudService {
]
static dataResourceNumberProperties = ['harvestFrequency','downloadLimit']
static dataResourceTimestampProperties = ['lastChecked','dataCurrency']
static dataResourceBooleanProperties = ['gbifDataset']
static dataResourceBooleanProperties = ['gbifDataset', 'isShareableWithGBIF']
static dataResourceJSONArrays = ['connectionParameters', 'contentTypes', 'defaultDarwinCoreValues', 'imageMetadata']
//static dataResourceObjectProperties = ['dataProvider']

Expand Down Expand Up @@ -269,7 +269,7 @@ class CrudService {

/* data resource */

def readDataResource(DataResource p) {
def readDataResource(DataResource p, apiKey = null) {
def builder = new JSONBuilder()

def result = builder.build {
Expand Down Expand Up @@ -351,7 +351,7 @@ class CrudService {
if (p.listConsumers()) {
linkedRecordConsumers = p.listConsumers().formatEntitiesFromUids()
}
if (p.connectionParameters) {
if (p.connectionParameters && apiKey) {
connectionParameters = p.connectionParameters.formatJSON()
}
if (p.imageMetadata) {
Expand Down
11 changes: 6 additions & 5 deletions grails-app/services/au/org/ala/collectory/IptService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class IptService {
* @return A list of data resources that need re-loading
*/
@org.springframework.transaction.annotation.Transactional(propagation = org.springframework.transaction.annotation.Propagation.REQUIRED)
def scan(DataProvider provider, boolean create, boolean check, String keyName, String username, boolean admin) {
def scan(DataProvider provider, boolean create, boolean check, String keyName, String username, boolean admin, boolean shareWithGbif) {
ActivityLog.log username, admin, provider.uid, Action.SCAN
def updates = this.rss(provider, keyName)
def updates = this.rss(provider, keyName, shareWithGbif)

return merge(provider, updates, create, check, username, admin)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class IptService {
*
* @return A list of (possibly new providers)
*/
def rss(DataProvider provider, String keyName) {
def rss(DataProvider provider, String keyName, Boolean isShareableWithGBIF) {

def url = provider.websiteUrl
if(!url.endsWith("/")){
Expand All @@ -180,7 +180,7 @@ class IptService {
rss.declareNamespace(NAMESPACES)
def items = rss.channel.item

return items.collect { item -> this.createDataResource(provider, item, keyName) }
return items.collect { item -> this.createDataResource(provider, item, keyName, isShareableWithGBIF) }
}

/**
Expand All @@ -192,7 +192,7 @@ class IptService {
*
* @return A created resource matching the information provided
*/
def createDataResource(DataProvider provider, GPathResult rssItem, String keyName) {
def createDataResource(DataProvider provider, GPathResult rssItem, String keyName, Boolean isShareableWithGBIF) {
def resource = new DataResource()
def eml = rssItem."ipt:eml"?.text()
def dwca = rssItem."ipt:dwca"?.text()
Expand All @@ -201,6 +201,7 @@ class IptService {
rssFields.each { name, accessor -> resource.setProperty(name, accessor(rssItem))}

resource.connectionParameters = dwca == null || dwca.isEmpty() ? null : "{ \"protocol\": \"DwCA\", \"url\": \"${dwca}\", \"automation\": true, \"termsForUniqueKey\": [ \"${keyName}\" ] }";
resource.isShareableWithGBIF = isShareableWithGBIF

def contacts = []
if (eml != null) {
Expand Down
1 change: 0 additions & 1 deletion web-app/js/taxonTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,5 @@ function showBie(node) {
if (rank == 'kingdoms') return;
var name = node.attr('id');
var sppUrl = CHARTS_CONFIG.bieWebappUrl + "/species/" + name;
if (rank != 'species') { sppUrl += "_(" + rank + ")"; }
document.location.href = sppUrl;
}

0 comments on commit 378dae7

Please sign in to comment.