Skip to content

Commit 47aeadb

Browse files
authored
Merge pull request #88 from AtlasOfLivingAustralia/hotfix_87_duplicate_myannotations
Fixed #87 2 'my annotations' displayed in myAlerts
2 parents bff408a + 11c193b commit 47aeadb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

grails-app/services/au/org/ala/alerts/UserService.groovy

+10-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UserService {
2222

2323
static transactional = true
2424

25-
def authService, messageSource, grailsApplication
25+
def authService, queryService, messageSource, grailsApplication
2626

2727
def siteLocale = new Locale.Builder().setLanguageTag(Holders.config.siteDefaultLanguage as String).build()
2828

@@ -37,9 +37,15 @@ class UserService {
3737
def enabledQueries = notificationInstanceList.collect { it.query }
3838
def enabledIds = enabledQueries.collect { it.id }
3939

40-
// all standard queries
40+
// all standard queries + 'my annotations' queries
41+
// this might include 'my annotations' that belongs to others
42+
// we need to filter those out
4143
def allAlertTypes = Query.findAllByCustom(false)
4244

45+
def myAnnotationQuery = queryService.createMyAnnotationQuery(user.getUserId())
46+
// collect standard queries + 'my annotations' belongs to current user
47+
allAlertTypes = allAlertTypes.findAll { it.name != myAnnotationQuery.name || it.queryPath == myAnnotationQuery.queryPath }
48+
4349
allAlertTypes.removeAll { enabledIds.contains(it.id) }
4450
def customQueries = enabledQueries.findAll { it.custom }
4551
def standardQueries = enabledQueries.findAll { !it.custom }
@@ -51,10 +57,8 @@ class UserService {
5157
user : user]
5258

5359
if (grailsApplication.config.getProperty('myannotation.enabled', Boolean, false)) {
54-
def myannotationName = messageSource.getMessage("query.myannotations.title", null, siteLocale)
55-
def myannotation = userConfig.enabledQueries.findAll { it.name == myannotationName }
56-
userConfig.enabledQueries.removeAll { it.name == myannotationName }
57-
userConfig.myannotation = myannotation
60+
userConfig.myannotation = userConfig.enabledQueries.findAll { it.name == myAnnotationQuery.name }
61+
userConfig.enabledQueries.removeAll { it.name == myAnnotationQuery.name }
5862
}
5963

6064
userConfig

0 commit comments

Comments
 (0)