Skip to content

Commit d33bcbd

Browse files
committed
Allow officers to view project explorer downloads #3440
1 parent a4711d8 commit d33bcbd

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

grails-app/controllers/au/org/ala/merit/DownloadController.groovy

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@ import grails.core.GrailsApplication
44

55
import javax.servlet.http.HttpServletResponse
66

7-
@PreAuthorise(accessLevel = 'siteReadOnly', redirectController = "home")
87
class DownloadController {
98

109
private List DOWNLOAD_EXTENSIONS = ['xls', 'xlsx', 'zip', 'json', 'xml', 'pdf', 'csv']
1110

1211
GrailsApplication grailsApplication
1312
WebService webService
13+
UserService userService
1414

1515
/**
1616
* Deliberately not add .format in urlMapping to support file.extension on purpose
1717
* @param id - including extension
1818
* @return
1919
*/
2020
def get(String id) {
21+
if (!userService.userIsSiteAdmin() && !userService.userHasReadOnlyAccess()) {
22+
redirect(controller:'home')
23+
return
24+
}
2125
if (!id) {
2226
response.setStatus(400)
2327
render "A download ID is required"

grails-app/controllers/au/org/ala/merit/HomeController.groovy

+5-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ class HomeController {
9191
def facetsList = new ArrayList(SettingService.getHubConfig().availableFacets ?:[])
9292
def mapFacets = new ArrayList(SettingService.getHubConfig().availableMapFacets ?: [])
9393

94-
boolean canViewAdminFacetsAndDownloads = userService.userIsAlaOrFcAdmin() || userService.userHasReadOnlyAccess()
95-
if (!canViewAdminFacetsAndDownloads) {
94+
boolean canViewAdminFacets = userService.userIsAlaOrFcAdmin() || userService.userHasReadOnlyAccess()
95+
if (!canViewAdminFacets) {
9696
List adminFacetList = SettingService.getHubConfig().adminFacets ?: []
9797
facetsList?.removeAll(adminFacetList)
9898
mapFacets?.removeAll(adminFacetList)
9999
}
100+
boolean canViewDownloads = canViewAdminFacets || userService.userIsSiteAdmin()
100101
boolean canViewOfficerFacets = userService.userIsSiteAdmin() || userService.userHasReadOnlyAccess()
101102
if (!canViewOfficerFacets) {
102103
List officerFacetList = SettingService.getHubConfig().officerFacets ?: []
@@ -117,10 +118,10 @@ class HomeController {
117118
description: settingService.getSettingText(SettingPageType.DESCRIPTION),
118119
results: resp,
119120
projectCount: resp?.hits?.total ?: 0,
120-
includeDownloads: canViewAdminFacetsAndDownloads
121+
includeDownloads: canViewDownloads
121122
]
122123

123-
if (canViewAdminFacetsAndDownloads) {
124+
if (canViewAdminFacets) {
124125
List activityTypes = metadataService.activityTypesList()
125126
Map activityTypesFacet = resp?.facets?.get(ACTIVITY_TYPE_FACET_NAME)
126127
model.activityTypes = filterActivityTypesToProjectSelection(activityTypes, activityTypesFacet)

grails-app/controllers/au/org/ala/merit/SearchController.groovy

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.apache.http.HttpStatus
77
class SearchController {
88
def searchService, webService, speciesService, commonService, documentService, reportService
99
GrailsApplication grailsApplication
10+
UserService userService
1011

1112
/**
1213
* Main search page that takes its input from the search bar in the header
@@ -33,8 +34,11 @@ class SearchController {
3334
render speciesService.searchSpeciesList(sort, max, offset) as JSON
3435
}
3536

36-
@PreAuthorise(accessLevel = 'siteReadOnly', redirectController ='home', redirectAction = 'index')
3737
def downloadAllData() {
38+
if (!userService.userIsSiteAdmin() && !userService.userHasReadOnlyAccess()) {
39+
redirect(controller:'home')
40+
return
41+
}
3842
params.putAll(downloadParams())
3943
params.max = 10000 // The default is 5000, and some downloads require more than that.
4044
def response = searchService.downloadAllData(params)

src/test/groovy/au/org/ala/merit/HomeControllerSpec.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
217217
false | true
218218
}
219219

220-
def "Users without MERIT admin or read only but with the hub officer role cannot view admin facets but can view officer facets"() {
220+
def "Users without MERIT admin or read only but with the hub officer role cannot view admin facets but can view officer facets and downloads"() {
221221
setup:
222222
Map resp = [:]
223223

@@ -228,7 +228,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
228228
then:
229229
1 * userService.userIsAlaOrFcAdmin() >> false
230230
1 * userService.userHasReadOnlyAccess() >> false
231-
1 * userService.userIsSiteAdmin() >> true
231+
2 * userService.userIsSiteAdmin() >> true
232232

233233
1 * searchService.HomePageFacets(params) >> resp
234234
1 * settingService.getSettingText(_) >> "Project explorer description"
@@ -241,7 +241,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
241241
model.description == "Project explorer description"
242242
model.results == resp
243243
model.projectCount == 0
244-
model.includeDownloads == false
244+
model.includeDownloads == true
245245
model.activityTypes == null
246246

247247
}
@@ -257,7 +257,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
257257
then:
258258
1 * userService.userIsAlaOrFcAdmin() >> false
259259
2 * userService.userHasReadOnlyAccess() >> false
260-
1 * userService.userIsSiteAdmin() >> false
260+
2 * userService.userIsSiteAdmin() >> false
261261
1 * searchService.HomePageFacets(params) >> resp
262262
1 * settingService.getSettingText(_) >> "Project explorer description"
263263
0 * metadataService.activityTypesList()

0 commit comments

Comments
 (0)