Skip to content

Commit

Permalink
Made electFacet viewable by hub officers #3320
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Sep 9, 2024
1 parent 9e3cd22 commit 65a85c3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ class HomeController {

boolean canViewAdminFacetsAndDownloads = userService.userIsAlaOrFcAdmin() || userService.userHasReadOnlyAccess()
if (!canViewAdminFacetsAndDownloads) {
def adminFacetList = SettingService.getHubConfig().adminFacets ?: []
List adminFacetList = SettingService.getHubConfig().adminFacets ?: []
facetsList?.removeAll(adminFacetList)
mapFacets?.removeAll(adminFacetList)
}
boolean canViewOfficerFacets = userService.userIsSiteAdmin() || userService.userHasReadOnlyAccess()
if (!canViewOfficerFacets) {
List officerFacetList = SettingService.getHubConfig().officerFacets ?: []
facetsList?.removeAll(officerFacetList)
mapFacets?.removeAll(officerFacetList)
}

def fqList = params.getList('fq')
def allFacets = fqList + (SettingService.getHubConfig().defaultFacetQuery?:[])
Expand Down
5 changes: 5 additions & 0 deletions src/main/scripts/releases/4.0/changeMeritFacetConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let hub = db.hub.findOne({urlPath:'merit'});
const electFacetIndex = hub.adminFacets.indexOf('electFacet');
hub.adminFacets.splice(electFacetIndex, 1);
hub.officerFacets = ['electFacet'];
db.hub.replaceOne({hubId:hub.hubId}, hub);
39 changes: 35 additions & 4 deletions src/test/groovy/au/org/ala/merit/HomeControllerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom

SearchService searchService = Mock(SearchService)
UserService userService = Mock(UserService)
HubSettings hubSettings = new HubSettings(availableFacets:['nameFacet', 'descriptionFacet', 'admin'], availableMapFacets:['adminMap'], adminFacets:['admin', 'adminMap'])
HubSettings hubSettings = new HubSettings(availableFacets:['nameFacet', 'descriptionFacet', 'admin', 'elect'], availableMapFacets:['adminMap'], adminFacets:['admin', 'adminMap'], officerFacets:['elect'])
SettingService settingService = Mock(SettingService)
MetadataService metadataService = Mock(MetadataService)
ActivityService activityService = Mock(ActivityService)
Expand Down Expand Up @@ -190,17 +190,19 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
then:
if (admin) {
1 * userService.userIsAlaOrFcAdmin() >> true
1 * userService.userIsSiteAdmin() >> true
}
else if (readOnly) {
1 * userService.userIsAlaOrFcAdmin() >> false
1 * userService.userHasReadOnlyAccess() >> true
1 * userService.userIsSiteAdmin() >> false
2 * userService.userHasReadOnlyAccess() >> true
}
1 * searchService.HomePageFacets(params) >> resp
1 * settingService.getSettingText(_) >> "Project explorer description"
1 * metadataService.activityTypesList() >> activityTypes

and:
model.facetsList == ['nameFacet', 'descriptionFacet', 'admin']
model.facetsList == ['nameFacet', 'descriptionFacet', 'admin', 'elect']
model.mapFacets == ['adminMap']
model.geographicFacets == []
model.description == "Project explorer description"
Expand All @@ -215,7 +217,7 @@ class HomeControllerSpec extends Specification implements ControllerUnitTest<Hom
false | true
}

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

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

1 * searchService.HomePageFacets(params) >> resp
1 * settingService.getSettingText(_) >> "Project explorer description"
0 * metadataService.activityTypesList()

and:
model.facetsList == ['nameFacet', 'descriptionFacet', 'elect']
model.mapFacets == []
model.geographicFacets == []
model.description == "Project explorer description"
model.results == resp
model.projectCount == 0
model.includeDownloads == false
model.activityTypes == null

}

def "Users without MERIT admin or read only cannot view admin facets or downloads"() {
setup:
Map resp = [:]

when:
params.fq="status:active"
controller.projectExplorer()

then:
1 * userService.userIsAlaOrFcAdmin() >> false
2 * userService.userHasReadOnlyAccess() >> false
1 * userService.userIsSiteAdmin() >> false
1 * searchService.HomePageFacets(params) >> resp
1 * settingService.getSettingText(_) >> "Project explorer description"
0 * metadataService.activityTypesList()
Expand Down

0 comments on commit 65a85c3

Please sign in to comment.