Skip to content

Commit f3354b9

Browse files
authored
Merge pull request #463 from AtlasOfLivingAustralia/species-list-auth
update species-list authentication
2 parents 7078fbd + 9239783 commit f3354b9

File tree

3 files changed

+54
-16
lines changed

3 files changed

+54
-16
lines changed

grails-app/assets/javascripts/spApp/controller/createSpeciesListCtrl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
$scope.addNewSpecies = function () {
157157
ListsService.createList($scope.newListName, $scope.newListDescription, $scope.matchedGuids(), $scope.makePrivate, $scope.newListType.id).then(function (resp) {
158158
if (resp.status >= 200 && resp.status < 300) {
159-
var json = JSON.parse(resp.data.text);
159+
var json = resp.data;
160160
var druid = json.druid;
161161

162162
LoggerService.log("Create", "createSpeciesList", {

grails-app/assets/javascripts/spApp/service/listsService.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
if ($SH.userId) {
3939
params += "&user=" + $SH.userId
4040
}
41-
return $http.get(this.url() + "/ws/speciesList" + params, _httpDescription('list')).then(function (response) {
41+
return $http.get($SH.baseUrl + "/portal/speciesList" + params, _httpDescription('list')).then(function (response) {
4242
if (response.data.lists) {
4343
return response.data.lists;
4444
} else {
@@ -63,7 +63,7 @@
6363
},
6464
items: function (listId, params) {
6565
params = params || {};
66-
return $http.get(this.url() + "/ws/speciesListItems/" + listId, _httpDescription('items', {
66+
return $http.get($SH.baseUrl + "/portal/speciesListItems/" + listId, _httpDescription('items', {
6767
params: params,
6868
withCredentials: true
6969
})).then(function (response) {
@@ -118,4 +118,4 @@
118118

119119
return scope;
120120
}])
121-
}(angular));
121+
}(angular));

grails-app/controllers/au/org/ala/spatial/portal/PortalController.groovy

+50-12
Original file line numberDiff line numberDiff line change
@@ -376,28 +376,67 @@ class PortalController {
376376

377377
def url = grailsApplication.config.lists.url
378378

379-
def header = [:]
380-
if (Holders.config.security.oidc.enabled) {
381-
header.put("userId", userId)
382-
header.put("X-ALA-userId", userId)
383-
header.put("apiKey", grailsApplication.config.api_key)
384-
//header.put('Cookie', 'ALA-Auth=' + URLEncoder.encode(authService.email, 'UTF-8'))
379+
def r = webService.post("${url}/ws/speciesList/", json)
380+
381+
if (r == null) {
382+
def status = response.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR)
383+
r = [status: status, error: 'Unknown error when creating list']
384+
}
385+
386+
def status = r.statusCode
387+
if (r.statusCode < 200 || r.statusCode > 300) {
388+
r = [error: r.resp ]
385389
}
386390

387-
def r = hubWebService.urlResponse(HttpPost.METHOD_NAME, "${url}/ws/speciesList/", null, header,
388-
new StringRequestEntity((json as JSON).toString()), true)
391+
render status: status, r.resp as JSON
392+
}
393+
}
394+
395+
def speciesListItems() {
396+
def userId = getValidUserId(params)
397+
398+
if (!userId) {
399+
notAuthorised()
400+
} else {
401+
def url = grailsApplication.config.lists.url
402+
403+
def r = webService.get("${url}/ws/speciesListItems/" + params.id, [:], org.apache.http.entity.ContentType.APPLICATION_JSON, false, true, [:])
389404

390405
if (r == null) {
391406
def status = response.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR)
392-
r = [status: status, error: 'Unknown error when creating list']
407+
r = [status: status, error: 'Unknown error when fetching list']
408+
}
409+
410+
def status = r.statusCode
411+
if (r.statusCode < 200 || r.statusCode > 300) {
412+
r = [error: r.resp ]
413+
}
414+
415+
render status: status, r.resp as JSON
416+
}
417+
}
418+
419+
def speciesList() {
420+
def userId = getValidUserId(params)
421+
422+
if (!userId) {
423+
notAuthorised()
424+
} else {
425+
def url = grailsApplication.config.lists.url
426+
427+
def r = webService.get("${url}/ws/speciesList", [user: params.user ? userId : null, max: params.max], org.apache.http.entity.ContentType.APPLICATION_JSON, false, true, [:])
428+
429+
if (r == null) {
430+
def status = response.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR)
431+
r = [status: status, error: 'Unknown error when fetching list']
393432
}
394433

395434
def status = r.statusCode
396435
if (r.statusCode < 200 || r.statusCode > 300) {
397-
r = [error: r.text ]
436+
r = [error: r.resp ]
398437
}
399438

400-
render status: status, r as JSON
439+
render status: status, r.resp as JSON
401440
}
402441
}
403442

@@ -421,7 +460,6 @@ class PortalController {
421460
json.fq[0] = json.q
422461
json.q = tmp
423462
} else if (json?.wkt || json?.qc) {
424-
log.error(getWkt(json?.wkt))
425463
json.fq = [json.q]
426464
json.q = '*:*'
427465
} else {

0 commit comments

Comments
 (0)