Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yasima-csiro committed Aug 17, 2021
2 parents cddc05b + 4ab83e5 commit 13c698b
Show file tree
Hide file tree
Showing 21 changed files with 322 additions and 56 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ branches:
only:
- master
- dev
- develop
- /^feature\/.*$/
- /^hotfix\/.*$/
before_cache:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
plugins {
id 'war'
}
version "5.2"
version "5.2.1-SNAPSHOT"

group "au.org.ala"

Expand Down Expand Up @@ -107,7 +107,7 @@ dependencies {

if (!inplace) {
compile "org.grails.plugins:ala-map-plugin:3.0"
compile "org.grails.plugins:ecodata-client-plugin:3.0.5"
compile "org.grails.plugins:ecodata-client-plugin:3.1"
}
}

Expand Down
9 changes: 8 additions & 1 deletion grails-app/assets/javascripts/chartjsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ function ChartjsManagerViewModel() {
* Whether to show the list of charts.
*/
self.chartjsListShow = ko.computed(function () {
return self.chartjsList().length > 0;
var ifChartjsListShow = self.chartjsList().length > 0
if(ifChartjsListShow){
$('#chartGraphTab').show()
}
else {
$('#chartGraphTab').hide()
}
return ifChartjsListShow;
});

/**
Expand Down
3 changes: 3 additions & 0 deletions grails-app/assets/javascripts/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,9 @@ function decodeCamelCase(text) {
var result = text.replace( /([A-Z])/g, " $1" );
return result.charAt(0).toUpperCase() + result.slice(1); // capitalize the first letter - as an example.
}
else{
return text
}
}

function cleanName(text) {
Expand Down
6 changes: 1 addition & 5 deletions grails-app/assets/javascripts/projectActivities.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,8 @@ var ProjectActivitiesSettingsViewModel = function (pActivitiesVM, placeHolder) {
};

self.saveForm = function () {
return self.genericUpdate("form");
};

self.saveSpecies = function () {
if(self.current().areSpeciesValid()) {
self.genericUpdate("species");
self.genericUpdate("form");
} else {
showAlert("All species field(s) must be configured before saving.", "alert-error", self.placeHolder);
}
Expand Down
10 changes: 3 additions & 7 deletions grails-app/assets/javascripts/projectActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ var ProjectActivity = function (params) {
if (by == "form") {
jsData = {};
jsData.pActivityFormName = self.pActivityFormName();
jsData.speciesFields = $.map(self.speciesFields(), function (obj, i) {
return obj.asJson();
});
}
else if (by == "info") {
var ignore = self.ignore.concat(['current',
Expand All @@ -698,13 +701,6 @@ var ProjectActivity = function (params) {
jsData = ko.mapping.toJS(self, {ignore: ignore});
jsData.endDate = moment(self.endDate(), 'YYYY-MM-DDThh:mm:ssZ').isValid() ? self.endDate() : "";
}
else if (by == "species") {
jsData = {};

jsData.speciesFields = $.map(self.speciesFields(), function (obj, i) {
return obj.asJson();
});
}
else if (by == "sites") {
jsData = {};
var sites = [];
Expand Down
6 changes: 5 additions & 1 deletion grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,8 @@ if(!map.overlays) {
]
}

settings.surveyMethods="fielddata.survey.methods"
settings.surveyMethods="fielddata.survey.methods"
if (!app.file.script.path) {
app.file.script.path = "/data/biocollect/scripts"
}
script.read.extensions.list = ['js','min.js','png']
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.org.ala.biocollect

import au.org.ala.biocollect.merit.*
import au.org.ala.biocollect.merit.hub.HubSettings
import au.org.ala.ecodata.forms.ActivityFormService
import au.org.ala.web.AuthService
import au.org.ala.web.UserDetails
import grails.converters.JSON
Expand Down Expand Up @@ -33,6 +34,7 @@ class BioActivityController {
SettingService settingService
AuthService authService
UtilService utilService
ActivityFormService activityFormService

static int MAX_FLIMIT = 500
static allowedMethods = ['bulkDelete': 'POST', bulkRelease: 'POST', bulkEmbargo: 'POST']
Expand Down Expand Up @@ -883,10 +885,8 @@ class BioActivityController {
}

def addOutputModel(model) {
model.metaModel = metadataService.getActivityModel(model.activity.type)
model.outputModels = model.metaModel?.outputs?.collectEntries {
[it, metadataService.getDataModelFromOutputName(it)]
}
model.putAll(activityFormService.getActivityAndOutputMetadata(model.activity.type))
model
}

def defaultData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package au.org.ala.biocollect
import au.org.ala.biocollect.merit.CommonService
import au.org.ala.biocollect.merit.UserService
import au.org.ala.biocollect.merit.WebService
import org.apache.commons.io.FilenameUtils

class DownloadController {

WebService webService
Expand Down Expand Up @@ -38,4 +40,50 @@ class DownloadController {
}
}
}

/***
* This method is used to read custom Js files under /data/scripts directory.
* @return
*/
def getScriptFile() {
if (params.filename && params.hub && params.model) {
log.debug("Script name: " + params.filename)
log.debug("Hub: " + params.hub)
log.debug("Model: " + params.model)
String filename = FilenameUtils.getName(params.filename)

if (filename != params.filename) {
response.status = 404
return
}

def extension = FilenameUtils.getExtension(params.filename)?.toLowerCase()
if (extension && !grailsApplication.config.script.read.extensions.list.contains(extension)){
response.status = 404
return
}

String path = "${grailsApplication.config.app.file.script.path}${File.separator}${params.hub}${File.separator}${params.model}${File.separator}${params.filename}"
log.debug("Script path: " + path)

File file = new File(path)

if (!file.exists()) {
response.status = 404
return null
}

if(extension == 'js' || extension == 'min.js') {
response.setContentType('text/javascript')
}
response.outputStream << new FileInputStream(file)
response.outputStream.flush()

return null

} else {
response.status = 400
render status:400, text: 'filename, hub or model is missing'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class UrlMappings {
}
"/download/file"(controller: "download", action: [GET: "file"])
"/download/$id"(controller: "download", action: [GET: "downloadProjectDataFile"])
"/download/getScriptFile"(controller: "download", action: [GET: "getScriptFile"])
"500"(controller:'error', action:'response500')
"404"(controller:'error', action:'response404')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ class ProxyController {
def excelOutputTemplate() {
String url = "${grailsApplication.config.ecodata.service.url}/metadata/excelOutputTemplate"
String expandList = params.expandList?:""
String listName = params.listName?:null

if (params.data) {
webService.proxyPostRequest(response, url,
[listName:params.listName, type:params.type, data:params.data, editMode:params.editMode, allowExtraRows:params.allowExtraRows, autosizeColumns:false, expandList: expandList])
}
else {
url += "?type=${params.type?.encodeAsURL()}&listName=${params.listName?.encodeAsURL()}&listName=${expandList?.encodeAsURL()}"
url += "?type=${params.type?.encodeAsURL()}&expandList=${expandList?.encodeAsURL()}"
if(listName){
url += "&listName=${params.listName.encodeAsURL()}"
}
webService.proxyGetRequest(response, url)
}

Expand Down
2 changes: 1 addition & 1 deletion grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ project.myrecords.title=My sightings
project.userrecords.title=Sightings of
allrecords.title=All records
myrecords.title=My records
record.create.title=Record a sighting
record.create.title=Create a record
record.edit.title=Edit a sighting
record.view.title=View a sighting
record.edit.map.latLon=Latitude/longitude
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package au.org.ala.biocollect.merit

import au.org.ala.ecodata.forms.ActivityFormService

class FormSpeciesFieldParserService {
MetadataService metadataService
ActivityFormService activityFormService

/**
* Get the list of species fields, for the specified survey, grouped by outputs
Expand All @@ -13,15 +16,7 @@ class FormSpeciesFieldParserService {
* @return the list of species fields
*/
Map getSpeciesFieldsForSurvey(String id) {
def model = [:]

// the activity meta-model
model.metaModel = metadataService.getActivityModel(id)
// the array of output models
model.outputModels = model.metaModel?.outputs?.collectEntries {
[it, metadataService.getDataModelFromOutputName(it)]
}

def model = activityFormService.getActivityAndOutputMetadata(id)

def fields = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class MetadataService {


def clearEcodataCache() {
webService.get(grailsApplication.config.ecodata.service.url + "/admin/clearMetadataCache")
webService.doGet(grailsApplication.config.ecodata.service.url + "/admin/clearMetadataCache" , null)
}

def outputTypesList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,30 +154,14 @@ class SpeciesService {

def searchSpeciesList(String sort = 'listName', Integer max = 100, Integer offset = 0, String guid = null, String order = "asc", String searchTerm = null) {
def list
String url = "${grailsApplication.config.lists.baseURL}/ws/speciesList?sort=${sort}&max=${max}&offset=${offset}&order=${order}"
String url = "${grailsApplication.config.lists.baseURL}/ws/speciesList?sort=${sort}&max=${max}&offset=${offset}&order=${order}&q=${searchTerm?:''}"

if (!guid & !searchTerm) {
if (!guid) {
list = webService.getJson(url)
} else {
if (guid) {
// Search List by species in the list
url = "${url}&items=createAlias:items&items.guid=eq:${guid}"
list = webService.getJson(url)
}
if (searchTerm) {
// Search list by list name
def searchList = getAllSpeciesList()
def toLowerSearchTerm = searchTerm.toLowerCase()
// remove list that don't match the name
searchList.lists.removeAll { !(it.listName.toLowerCase() =~ /\A${toLowerSearchTerm}/) }
if (list) {
list.lists.addAll(searchList.lists)
} else {
list = searchList
}
list.lists.unique()
list.listCount = list.lists.size()
}
// Search List by species in the list
url = "${url}&items=createAlias:items&items.guid=eq:${guid}"
list = webService.getJson(url)
}

list
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/projectActivity/_species.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

<div class="span12">
<button class="btn-primary btn block btn-small"
data-bind="click: $parent.saveSpecies"><i class="icon-white icon-hdd" ></i>Save</button>
data-bind="click: $parent.saveForm"><i class="icon-white icon-hdd" ></i>Save</button>
<button class="btn-primary btn btn-small block" data-bind="showTabOrRedirect: {url:'', tabId: '#survey-form-tab'}"><i class="icon-white icon-chevron-left" ></i>Back</button>
<button class="btn-primary btn btn-small block" data-bind="showTabOrRedirect: {url:'', tabId: '#survey-locations-tab'}">Next <i class="icon-white icon-chevron-right" ></i></button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package au.org.ala.biocollect

import grails.test.mixin.TestFor
import org.apache.http.HttpStatus
import spock.lang.Specification

@TestFor(DownloadController)
class DownloadControllerSpec extends Specification {

File scriptsPath
File temp
File hubPath
File modelPath

void setup() {

temp = File.createTempDir("tmp", "")
scriptsPath = new File(temp, "scripts")
scriptsPath.mkdir()
hubPath = new File(scriptsPath, "tempHub")
hubPath.mkdir()
modelPath = new File(hubPath, "tempModel")
modelPath.mkdir()

controller.grailsApplication.config.app.file.script.path = scriptsPath.getAbsolutePath()

// Setup three files, one that should be accessible, and others that should not
File validFile = new File(modelPath, "validFile.js")
validFile.createNewFile()

File jsonFile = new File(modelPath, "validFile.json")
jsonFile.createNewFile()

File privateFile = new File(temp, "privateFile.js")
privateFile.createNewFile()
}

void "Files can be retrieved from the temporary scripts directory by filename"() {
when:
params.hub = "tempHub"
params.filename = "validFile.js"
params.model = "tempModel"
controller.getScriptFile()

then:
response.contentType == "text/javascript"
response.status == HttpStatus.SC_OK
}

void "If a file doesn't exist, a 404 will be returned"() {
when:
params.hub = "tempHub"
params.filename = "missingFile.js"
params.model = "tempModel"
controller.getScriptFile()

then:
response.status == HttpStatus.SC_NOT_FOUND
}

void "A file cannot be retrieved from outside the designated scripts directory"() {
when:
params.hub = "tempHub"
params.filename = "../../../privateFile.js"
params.model = "tempModel"
controller.getScriptFile()

then:
new File(modelPath, params.filename).exists()
response.status == HttpStatus.SC_NOT_FOUND
}

void "Tyring to read a file with extension which are not allowed to read"() {
when:
params.hub = "tempHub"
params.filename = "validFile.json"
params.model = "tempModel"
controller.getScriptFile()

then:
new File(modelPath, params.filename).exists()
response.status == HttpStatus.SC_NOT_FOUND
}
}
Loading

0 comments on commit 13c698b

Please sign in to comment.