Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
temi committed Dec 4, 2023
2 parents 0938253 + fbe7951 commit 44cedf9
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ groovyVersion=3.0.11
mongodbDriverVersion=4.5.1
grailsGradlePluginVersion=5.2.3
gormMongoVersion=7.3.0
alaSecurityLibsVersion=6.0.0
alaSecurityLibsVersion=6.2.0
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1024M
Expand Down
10 changes: 10 additions & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,13 @@ elasticSearch {
maxBulkRequest = 250
}

attachement {
categories = [
[key:"General", value:"General"],
[key:"Management", value:"Management"],
[key:"National Best Practice Manual", value:"National Best Practice Manual"],
[key:"National Strategic Plan", value:"National Strategic Plan"],
[key:"National Weed Management Guide", value:"National Weed Management Guide"],
[key:"Other Management Resources", value:"Other Management Resources"]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ class OpusController extends BaseController {
}
}

def getCategories() {
def categories = grailsApplication.config.getProperty('attachement.categories', List)
render(categories as JSON)
}

def getTags() {
render([tags: Tag.list()] as JSON)
}
Expand Down
4 changes: 2 additions & 2 deletions grails-app/controllers/au/org/ala/profile/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class UrlMappings {
"/opus/$opusId/attachment/$attachmentId/download" controller: "opus", action: [GET: "downloadAttachment"]
"/opus/$opusId/attachment/$attachmentId" controller: "opus", action: [GET: "getAttachmentMetadata", DELETE: "deleteAttachment"]
"/opus/$opusId/attachment/" controller: "opus", action: [GET: "getAttachmentMetadata", POST: "saveAttachment"]
"/attachment/categories" controller: "opus", action: [GET: "getCategories"]

"/opus/$opusId" controller: "opus", action: [GET: "show", POST: "updateOpus", DELETE: "deleteOpus"]

Expand Down Expand Up @@ -99,8 +100,7 @@ class UrlMappings {
"/opus/$opusId/profile/$profileId/specimen" controller: "profile", action: [POST: "saveSpecimens"]

"/opus/$opusId/profile/$profileId/classification" controller: "profile", action: [GET: "classification"]

"/opus/$opusId/profile/$profileId/publication" controller: "profile", action: [GET: "listPublications", POST: "savePublication"]
"/opus/$opusId/profile/$profileId/publication" controller: "profile", action: [GET: "listPublications"]
"/opus/$opusId/profile/$profileId/publication/$publicationId/file" controller: "profile", action: [GET: "getPublicationFile"]

"/opus/$opusId/profile/$profileId/profileSettings" controller: "profile", action: [GET: "getProfileSettings", POST: "saveProfileSettings"]
Expand Down
2 changes: 1 addition & 1 deletion grails-app/domain/au/org/ala/profile/Attachment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class Attachment {
}

static constraints = {
category blank: true, inList: ['Management', 'General']
category blank: true, validator: {grailsApplication.config.getProperty('attachement.categories',List).value.contains(val)}
}
}
4 changes: 4 additions & 0 deletions grails-app/services/au/org/ala/profile/OpusService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class OpusService extends BaseDataAccessService {
opus.markDirty('approvedLists')
}
opus.approvedLists.addAll(json.approvedLists)
} else {
opus.approvedLists.removeAll(opus.approvedLists)
}

if (json.featureLists) {
Expand All @@ -82,6 +84,8 @@ class OpusService extends BaseDataAccessService {
opus.markDirty('featureLists')
}
opus.featureLists.addAll(json.featureLists)
} else {
opus.featureLists.removeAll(opus.featureLists)
}
opus.featureListSectionName = json.featureListSectionName ? json.featureListSectionName : null;

Expand Down
18 changes: 12 additions & 6 deletions grails-app/services/au/org/ala/profile/SearchService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class SearchService extends BaseDataAccessService {

Map search(List<String> opusIds, String term, int offset, int pageSize, SearchOptions options) {
log.debug("Searching for ${term} in collection(s) ${opusIds} with options ${options}")

List<Opus> opusList = getAccessibleCollections(opusIds)
List<Opus> opusList = getAccessibleCollections(opusIds, isAlaAdmin())
String[] accessibleCollections = opusList?.collect { it.uuid } as String[]
boolean isAccessible = alaAdmin? true : (accessibleCollections? true : false)
List<Vocab> vocabs = Vocab.findAllByUuidInList(opusList*.attributeVocabUuid)
String[] summaryTerms = Term.findAllByVocabInListAndSummary(vocabs, true)*.uuid
String[] nameTerms = Term.findAllByVocabInListAndContainsName(vocabs, true)*.uuid
Map<String, List<String>> filterLists = opusList.collectEntries { [(it.uuid) : masterListService.getCombinedLowerCaseNamesListForUser(it) ]}

Map results = [:]
if (accessibleCollections) {
if (isAccessible) {
Map params = [
indices: Profile,
types: Profile,
Expand Down Expand Up @@ -123,6 +123,11 @@ class SearchService extends BaseDataAccessService {
results
}

private boolean isAlaAdmin() {
boolean alaAdmin = userService.userInRole("ROLE_ADMIN")
return alaAdmin
}

private Map getProfileMatchReason (String term, Profile profile, Map nslResult) {
Map matchReason = [:]
if (profile.scientificNameLower == term.toLowerCase()) {
Expand Down Expand Up @@ -287,7 +292,7 @@ class SearchService extends BaseDataAccessService {
wildcard = '\\s*$' // regex end of line to ensure full word matching
}

List<Opus> accessibleCollections = getAccessibleCollections(opusIds)
List<Opus> accessibleCollections = getAccessibleCollections(opusIds, isAlaAdmin())
Map<Long, Opus> opusMap = accessibleCollections?.collectEntries { [(it.id): it] }

if (max == -1) {
Expand Down Expand Up @@ -729,11 +734,10 @@ class SearchService extends BaseDataAccessService {
match
}

private List<Opus> getAccessibleCollections(List<String> opusIds) {
private List<Opus> getAccessibleCollections(List<String> opusIds, boolean alaAdmin) {
List<Opus> opusList = opusIds?.findResults { Opus.findByUuidOrShortName(it, it) }

// search results from private collections can only be seen by ALA Admins or users registered with the collection
boolean alaAdmin = userService.userInRole("ROLE_ADMIN")
String userId = userService.getCurrentUserDetails()?.userId

// if the user is ala admin, do nothing
Expand All @@ -746,6 +750,8 @@ class SearchService extends BaseDataAccessService {
filteredOpusList = (opusList ?: Opus.list()).findAll {
!it?.privateCollection || it?.authorities?.find { auth -> auth.user.userId == userId }
}
} else if (alaAdmin && !opusList) {
filteredOpusList = Opus.list()
}

filteredOpusList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import au.org.ala.web.UserDetails
import grails.gorm.transactions.Rollback
import grails.gsp.PageRenderer
import grails.testing.mixin.integration.Integration
import net.sf.json.JSONObject
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.multipart.commons.CommonsMultipartFile

Expand Down Expand Up @@ -271,4 +272,92 @@ class OpusServiceSpec extends BaseIntegrationSpec {
1 * service.attachmentService.saveAttachment(_, _, _, _, _)
0 * service.attachmentService.deleteAttachment(_, _, _, _)
}
}

def "update opus for approved lists"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: ["dr123", "dr345"])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
approvedLists : ["dr123"],
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.approvedLists.size() == json1.approvedLists.size()
}

def "update opus for featured lists"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), featureLists: ["dr123", "dr345", "dr678"])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
featureLists : ["dr345"],
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.featureLists.size() == json1.featureLists.size()
}

def "update opus for approved lists and feature lists"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: ["dr123", "dr345"], featureLists: ["fl123","fl456","fl789"])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
approvedLists : ["dr123"],
featureLists : ["fl123", "fl456"]
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.approvedLists.size() == json1.approvedLists.size()
updateOpus.featureLists.size() == json1.featureLists.size()
}

def "update opus for approved lists and feature lists are empty"() {
given:
Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: [], featureLists: [])

def opus2 = [
title : "opus1",
dataResourceUid : "123",
approvedLists : [],
featureLists : []
]


JSONObject json1 = new JSONObject(opus2)
save opus1

when:
Opus updateOpus = service.updateOpus(opus1.uuid, json1)

then:
updateOpus.approvedLists.size() == json1.approvedLists.size()
updateOpus.featureLists.size() == json1.featureLists.size()
}
}
14 changes: 7 additions & 7 deletions src/scripts/mangrove-watch-images/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/scripts/mangrove-watch-images/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "profiles-image-upload",
"dependencies": {
"axios": "^1.4.0",
"axios": "^1.6.0",
"csvtojson": "^2.0.10",
"form-data": "^4.0.0",
"yargs": "^17.7.2"
Expand Down

0 comments on commit 44cedf9

Please sign in to comment.