Skip to content
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

Feature/issue3440 #3446

Merged
merged 4 commits into from
Feb 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import grails.core.GrailsApplication

import javax.servlet.http.HttpServletResponse

@PreAuthorise(accessLevel = 'siteReadOnly', redirectController = "home")
class DownloadController {

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

GrailsApplication grailsApplication
WebService webService
UserService userService

/**
* Deliberately not add .format in urlMapping to support file.extension on purpose
* @param id - including extension
* @return
*/
def get(String id) {
if (!userService.userIsSiteAdmin() && !userService.userHasReadOnlyAccess()) {
redirect(controller:'home')
return
}
if (!id) {
response.setStatus(400)
render "A download ID is required"
Expand Down
9 changes: 5 additions & 4 deletions grails-app/controllers/au/org/ala/merit/HomeController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ class HomeController {
def facetsList = new ArrayList(SettingService.getHubConfig().availableFacets ?:[])
def mapFacets = new ArrayList(SettingService.getHubConfig().availableMapFacets ?: [])

boolean canViewAdminFacetsAndDownloads = userService.userIsAlaOrFcAdmin() || userService.userHasReadOnlyAccess()
if (!canViewAdminFacetsAndDownloads) {
boolean canViewAdminFacets = userService.userIsAlaOrFcAdmin() || userService.userHasReadOnlyAccess()
if (!canViewAdminFacets) {
List adminFacetList = SettingService.getHubConfig().adminFacets ?: []
facetsList?.removeAll(adminFacetList)
mapFacets?.removeAll(adminFacetList)
}
boolean canViewDownloads = canViewAdminFacets || userService.userIsSiteAdmin()
boolean canViewOfficerFacets = userService.userIsSiteAdmin() || userService.userHasReadOnlyAccess()
if (!canViewOfficerFacets) {
List officerFacetList = SettingService.getHubConfig().officerFacets ?: []
Expand All @@ -117,10 +118,10 @@ class HomeController {
description: settingService.getSettingText(SettingPageType.DESCRIPTION),
results: resp,
projectCount: resp?.hits?.total ?: 0,
includeDownloads: canViewAdminFacetsAndDownloads
includeDownloads: canViewDownloads
]

if (canViewAdminFacetsAndDownloads) {
if (canViewAdminFacets) {
List activityTypes = metadataService.activityTypesList()
Map activityTypesFacet = resp?.facets?.get(ACTIVITY_TYPE_FACET_NAME)
model.activityTypes = filterActivityTypesToProjectSelection(activityTypes, activityTypesFacet)
Expand Down
11 changes: 9 additions & 2 deletions grails-app/controllers/au/org/ala/merit/SearchController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.apache.http.HttpStatus
class SearchController {
def searchService, webService, speciesService, commonService, documentService, reportService
GrailsApplication grailsApplication
UserService userService

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

@PreAuthorise(accessLevel = 'siteReadOnly', redirectController ='home', redirectAction = 'index')
def downloadAllData() {
if (!userService.userIsSiteAdmin() && !userService.userHasReadOnlyAccess()) {
redirect(controller:'home')
return
}
params.putAll(downloadParams())
params.max = 10000 // The default is 5000, and some downloads require more than that.
def response = searchService.downloadAllData(params)
Expand Down Expand Up @@ -78,8 +82,11 @@ class SearchController {
searchService.downloadSummaryData(params, response)
}

@PreAuthorise(accessLevel = 'siteReadOnly', redirectController ='home', redirectAction = 'index')
def downloadShapefile() {
if (!userService.userIsSiteAdmin() && !userService.userHasReadOnlyAccess()) {
redirect(controller:'home')
return
}
params.putAll(downloadParams())
boolean success = searchService.downloadShapefile(params)
Map resp = [status: success ? HttpStatus.SC_OK : HttpStatus.SC_INTERNAL_SERVER_ERROR]
Expand Down
5 changes: 0 additions & 5 deletions src/main/scripts/releases/4.2/addServiceFacet.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let hub = db.hub.findOne({urlPath:'merit'});
let servicesFacetIndex = hub.availableFacets.indexOf('services');
if (servicesFacetIndex < 0) {
hub.availableFacets.push('services');
}
hub.officerFacets = ['muFacet', 'projectElectFacet', 'services'];

servicesFacetIndex = hub.adminFacets.indexOf('services');
if (servicesFacetIndex >= 0) {
hub.adminFacets.splice(servicesFacetIndex, 1);
}
let muFacetIndex = hub.adminFacets.indexOf('muFacet');
if (muFacetIndex >= 0) {
hub.adminFacets.splice(muFacetIndex, 1);
}

db.hub.replaceOne({urlPath:'merit'}, hub);
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package au.org.ala.merit

import org.apache.http.HttpStatus
import org.h2.engine.User
import org.springframework.mock.web.MockMultipartFile
import spock.lang.Specification
import grails.testing.web.controllers.ControllerUnitTest

class DownloadControllerSpec extends Specification implements ControllerUnitTest<DownloadController>{

WebService webService = Mock(WebService)
UserService userService = Mock(UserService)
def setup() {
controller.userService = userService
controller.webService = webService
}

Expand All @@ -20,6 +23,7 @@ class DownloadControllerSpec extends Specification implements ControllerUnitTest
def resp = controller.get()

then:
1 * userService.userIsSiteAdmin() >> true
1 * webService.proxyGetRequest(_, {it.endsWith('download/uuid1234')}, true, true, _) >> [status:HttpStatus.SC_OK]

and: "We return null to inform grails to not attempt to process a view as we are proxying a response from ecodata"
Expand All @@ -32,6 +36,7 @@ class DownloadControllerSpec extends Specification implements ControllerUnitTest
controller.get()

then:
1 * userService.userIsSiteAdmin() >> true
response.status == HttpStatus.SC_BAD_REQUEST
}

Expand All @@ -45,6 +50,7 @@ class DownloadControllerSpec extends Specification implements ControllerUnitTest
controller.get()

then:
1 * userService.userIsSiteAdmin() >> true
1 * webService.proxyGetRequest(_, {it.contains('download/file')}, true, true, _) >> {
resp, url, userId, apiKey, timeout ->
formatPassedToEcodata = url.endsWith(format)
Expand Down
8 changes: 4 additions & 4 deletions src/test/groovy/au/org/ala/merit/HomeControllerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
false | true
}

def "Users without MERIT admin or read only but with the hub officer role cannot view admin facets but can view officer facets"() {
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"() {
setup:
Map resp = [:]

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

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

}
Expand All @@ -257,7 +257,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
then:
1 * userService.userIsAlaOrFcAdmin() >> false
2 * userService.userHasReadOnlyAccess() >> false
1 * userService.userIsSiteAdmin() >> false
2 * userService.userIsSiteAdmin() >> false
1 * searchService.HomePageFacets(params) >> resp
1 * settingService.getSettingText(_) >> "Project explorer description"
0 * metadataService.activityTypesList()
Expand Down
4 changes: 4 additions & 0 deletions src/test/groovy/au/org/ala/merit/SearchControllerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class SearchControllerSpec extends Specification implements ControllerUnitTest<S
SearchService searchService = Mock(SearchService)
WebService webService = Mock(WebService)
CommonService commonService = Mock(CommonService)
UserService userService = Mock(UserService)

void setup() {
controller.userService = userService
controller.searchService = searchService
controller.webService = webService
controller.commonService = commonService
Expand All @@ -21,6 +23,7 @@ class SearchControllerSpec extends Specification implements ControllerUnitTest<S
controller.downloadAllData()

then:
1 * userService.userIsSiteAdmin() >> true
1 * searchService.downloadAllData(params) >> [status:HttpStatus.SC_OK]

and:
Expand All @@ -37,6 +40,7 @@ class SearchControllerSpec extends Specification implements ControllerUnitTest<S
controller.downloadShapefile()

then:
1 * userService.userIsSiteAdmin() >> true
1 * searchService.downloadShapefile(params) >> true

and:
Expand Down
Loading