Skip to content

Commit

Permalink
Filter out data sets not of interest to the user #3058
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 13, 2023
1 parent 2de112a commit 7022b06
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class ProjectController {
boolean adminTabVisible = user?.isEditor || user?.isAdmin || user?.isCaseManager || user?.hasViewAccess
boolean showMeriPlanHistory = config.supportsMeriPlanHistory && userService.userIsSiteAdmin()
boolean datasetsVisible = config.includesContent(ProgramConfig.ProjectContent.DATA_SETS) && userHasViewAccess
if (datasetsVisible && project.custom?.dataSets) {
projectService.filterDataSetSummaries(project.custom?.dataSets)
}
def model = [overview : [label: 'Overview', visible: true, default: true, type: 'tab', publicImages: imagesModel, displayOutcomes: false, blog: blog, hasNewsAndEvents: hasNewsAndEvents, hasProjectStories: hasProjectStories, canChangeProjectDates: canChangeProjectDates, outcomes:project.outcomes, objectives:config.program?.config?.objectives],
documents : [label: 'Documents', visible: config.includesContent(ProgramConfig.ProjectContent.DOCUMENTS), type: 'tab', user:user, template:'docs', activityPeriodDescriptor:config.activityPeriodDescriptor ?: 'Stage'],
details : [label: 'MERI Plan', default: false, disabled: !meriPlanEnabled, visible: meriPlanVisible, meriPlanVisibleToUser: meriPlanVisibleToUser, risksAndThreatsVisible: canViewRisks, announcementsVisible: true, project:project, type: 'tab', template:'viewMeriPlan', meriPlanTemplate:MERI_PLAN_TEMPLATE+'View', config:config, activityPeriodDescriptor:config.activityPeriodDescriptor ?: 'Stage'],
Expand Down
10 changes: 10 additions & 0 deletions grails-app/services/au/org/ala/merit/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ class ProjectService {

}

void filterDataSetSummaries(List dataSetSummaries) {
List protocolNamesToHide = grailsApplication.config.getProperty('hidden.dataSet.protocols', List.class, ['Plot Selection', 'Plot Layout and Visit'])
List<Map> forms = activityService.monitoringProtocolForms()

dataSetSummaries.removeAll { Map dataSetSummary ->
Map protocolForm = forms.find{it.externalId == dataSetSummary.protocol}
protocolForm && (protocolForm.name in protocolNamesToHide)
}
}

/**
* Returns a filtered project view based on user needs. This will be implemented in ecodata as a part of the
* API changes but for now implementing it here is OK
Expand Down
19 changes: 19 additions & 0 deletions src/test/groovy/au/org/ala/merit/ProjectServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,25 @@ class ProjectServiceSpec extends Specification implements ServiceUnitTest<Projec
result == ['1':1, '2':2, '3':0]
}

def "Plot Selection / Visits should not be displayed in data sets"() {
setup:
List dataSets = [
[name:'Plot Selection', dataSetId:'d1', protocol:'1'],
[name:'Plot Layout and Visit', dataSetId:'d2', protocol:'2'],
[name:'Not a plot selection', dataSetId:'d3', protocol:'3']

]

when:
service.filterDataSetSummaries(dataSets)

then:
1 * activityService.monitoringProtocolForms() >> [[externalId:'1', name:"Plot Selection"], [externalId:'2', name: "Plot Layout and Visit"]]
and:
dataSets.size() == 1
dataSets[0].name == 'Not a plot selection'
}

private Map setupActivityModelForFiltering(List services) {
Map activityModel = [name:'output', outputs:[]]
services.each {
Expand Down

0 comments on commit 7022b06

Please sign in to comment.