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

GH-171 Fix for folder search to include nested folders #190

Merged
merged 1 commit into from
Nov 25, 2021
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 @@ -118,7 +118,7 @@ class SearchService extends AbstractCatalogueItemSearchService<CatalogueItem> {
containedFolderIds.add(folderId)
modelServices.collectMany {service ->
containedFolderIds.collectMany {fId ->
(service.findAllByContainerId(folderId) as List<Model>).collect {model -> model.id}
(service.findAllByContainerId(fId) as List<Model>).collect {model -> model.id}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class BootStrap implements SecurityDefinition {
test {
Folder folder
Folder folder2
Folder parentFolder

CatalogueUser.withNewTransaction {

createModernSecurityUsers('functionalTest', false)
Expand All @@ -67,7 +69,12 @@ class BootStrap implements SecurityDefinition {
createBasicGroups('functionalTest', false)
checkAndSave(messageSource, editors, readers)

folder = new Folder(label: 'Functional Test Folder', createdBy: userEmailAddresses.functionalTest)
parentFolder = new Folder(label: 'Parent Functional Test Folder', createdBy: userEmailAddresses.functionalTest)
checkAndSave(messageSource, parentFolder)

folder = new Folder(label: 'Functional Test Folder',
parentFolder: parentFolder,
createdBy: userEmailAddresses.functionalTest)
checkAndSave(messageSource, folder)

// This folder will only be visible to admins as it has no rights
Expand All @@ -91,6 +98,12 @@ class BootStrap implements SecurityDefinition {
userGroup: editors,
groupRole: groupRoleService.getFromCache(GroupRole.CONTAINER_ADMIN_ROLE_NAME).groupRole)
)
checkAndSave(messageSource, new SecurableResourceGroupRole(
createdBy: userEmailAddresses.functionalTest,
securableResource: parentFolder,
userGroup: editors,
groupRole: groupRoleService.getFromCache(GroupRole.CONTAINER_ADMIN_ROLE_NAME).groupRole)
)
// Make readers reviewers of the test folder, this will allow "comment" adding testing
checkAndSave(messageSource, new SecurableResourceGroupRole(
createdBy: userEmailAddresses.functionalTest,
Expand All @@ -99,6 +112,13 @@ class BootStrap implements SecurityDefinition {
groupRole: groupRoleService.getFromCache(GroupRole.REVIEWER_ROLE_NAME).groupRole)
)

checkAndSave(messageSource, new SecurableResourceGroupRole(
createdBy: userEmailAddresses.functionalTest,
securableResource: parentFolder,
userGroup: readers,
groupRole: groupRoleService.getFromCache(GroupRole.REVIEWER_ROLE_NAME).groupRole)
)

// Make editors container admin (existing permissions) of the test versioned folder
checkAndSave(messageSource, new SecurableResourceGroupRole(
createdBy: userEmailAddresses.functionalTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class FolderFunctionalSpec extends UserAccessAndPermissionChangingFunctionalSpec
@Override
String getEditorIndexJson() {
'''{
"count": 3,
"count": 4,
"items": [
{
"id": "${json-unit.matches:id}",
Expand All @@ -238,6 +238,12 @@ class FolderFunctionalSpec extends UserAccessAndPermissionChangingFunctionalSpec
"lastUpdated": "${json-unit.matches:offsetDateTime}",
"domainType": "VersionedFolder",
"hasChildFolders": false
},
{ "lastUpdated": "${json-unit.matches:offsetDateTime}",
"id": "${json-unit.matches:id}",
"hasChildFolders": true,
"domainType": "Folder",
"label": "Parent Functional Test Folder"
}
]
}'''
Expand All @@ -246,8 +252,14 @@ class FolderFunctionalSpec extends UserAccessAndPermissionChangingFunctionalSpec
@Override
String getAdminIndexJson() {
'''{
"count": 4,
"count": 5,
"items": [
{ "lastUpdated": "${json-unit.matches:offsetDateTime}",
"id": "${json-unit.matches:id}",
"hasChildFolders": true,
"domainType": "Folder",
"label": "Parent Functional Test Folder"
},
{
"lastUpdated": "${json-unit.matches:offsetDateTime}",
"id": "${json-unit.matches:id}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import io.micronaut.http.HttpResponse

import java.util.regex.Pattern

import static io.micronaut.http.HttpStatus.OK
import static io.micronaut.http.HttpStatus.OK

/**
* <pre>
* Controller: folder
Expand Down Expand Up @@ -135,8 +138,90 @@ class NestedFolderFunctionalSpec extends UserAccessFunctionalSpec {
}'''
}

@Transactional
String getParentTestFolderId() {
Folder.findByLabel('Parent Functional Test Folder').id.toString()
}

void 'S01 : test searching for "simple" in the test folder with parent folder id'() {
given:
String term = 'simple'

when: 'logged in as reader user'
loginReader()
POST("folders/${getParentTestFolderId()}/search", [searchTerm: term], STRING_ARG, true)

then:
verifyJsonResponse OK, '''{
"count": 7,
"items": [
{
"id": "${json-unit.matches:id}",
"domainType": "Term",
"label": "STT01: Simple Test Term 01",
"model": "${json-unit.matches:id}",
"breadcrumbs": [
{
"id": "${json-unit.matches:id}",
"label": "Simple Test Terminology",
"domainType": "Terminology",
"finalised": false
}
]
},
{
"id": "${json-unit.matches:id}",
"domainType": "Term",
"label": "STT02: Simple Test Term 02",
"model": "${json-unit.matches:id}",
"breadcrumbs": [
{
"id": "${json-unit.matches:id}",
"label": "Simple Test Terminology",
"domainType": "Terminology",
"finalised": false
}
]
},
{
"id": "${json-unit.matches:id}",
"domainType": "ReferenceDataModel",
"label": "Second Simple Reference Data Model"
},
{
"id": "${json-unit.matches:id}",
"domainType": "ReferenceDataModel",
"label": "Simple Reference Data Model"
},
{
"id": "${json-unit.matches:id}",
"domainType": "DataModel",
"label": "Simple Test DataModel"
},
{
"id": "${json-unit.matches:id}",
"domainType": "Terminology",
"label": "Simple Test Terminology"
},
{
"id": "${json-unit.matches:id}",
"domainType": "DataClass",
"label": "simple",
"model": "${json-unit.matches:id}",
"breadcrumbs": [
{
"id": "${json-unit.matches:id}",
"label": "Simple Test DataModel",
"domainType": "DataModel",
"finalised": false
}
]
}
]
}'''
}

/**
/**
* Whilst this is actually tested in the user access tests we ignore the labels being created
* we need to make sure that folders and subsequent folders are named correctly
* We test this inside thie test folder.
Expand Down
Loading