@@ -22,6 +22,7 @@ import au.org.ala.userdetails.IUserService
22
22
import au.org.ala.userdetails.LocationService
23
23
import au.org.ala.userdetails.PagedResult
24
24
import au.org.ala.userdetails.PasswordService
25
+ import au.org.ala.userdetails.ProfileService
25
26
import au.org.ala.userdetails.ResultStreamer
26
27
import au.org.ala.users.RoleRecord
27
28
import au.org.ala.users.UserPropertyRecord
@@ -54,6 +55,7 @@ class GormUserService implements IUserService {
54
55
LocationService locationService
55
56
MessageSource messageSource
56
57
WebService webService
58
+ ProfileService profileService
57
59
58
60
@Value (' ${attributes.affiliations.enabled:false}' )
59
61
boolean affiliationsEnabled = false
@@ -113,11 +115,6 @@ class GormUserService implements IUserService {
113
115
return user?. locked ?: false
114
116
}
115
117
116
- @Transactional (readOnly = true )
117
- boolean isEmailRegistered (String email ) {
118
- return User . findByEmailOrUserName(email?. toLowerCase(), email?. toLowerCase()) != null
119
- }
120
-
121
118
@Transactional (readOnly = true )
122
119
boolean isEmailInUse (String newEmail ) {
123
120
return User . findByEmailOrUserName(newEmail?. toLowerCase(), newEmail?. toLowerCase())
@@ -155,7 +152,7 @@ class GormUserService implements IUserService {
155
152
return User . findAllByEmailLikeOrLastNameLikeOrFirstNameLike(q, q, q, [offset : paginationToken as int , max : maxResults ])
156
153
}
157
154
158
- return User . list([offset : paginationToken as int , max : maxResults ])
155
+ return User . list([offset : ( paginationToken ?: 0 ) as int , max : maxResults ])
159
156
}
160
157
161
158
@Override
@@ -253,7 +250,7 @@ class GormUserService implements IUserService {
253
250
254
251
// Now send a temporary password to the user...
255
252
try {
256
- resetAndSendTemporaryPassword(userInstance, emailSubject, emailTitle, emailBody, password)
253
+ passwordService . resetAndSendTemporaryPassword(userInstance, emailSubject, emailTitle, emailBody, password)
257
254
} catch (PasswordResetFailedException ex) {
258
255
// Catching the checked exception should prevent the transaction from failing
259
256
log. error(" Failed to send temporary password via email!" , ex)
@@ -274,7 +271,7 @@ class GormUserService implements IUserService {
274
271
275
272
properties. keySet(). each { String propName ->
276
273
def propValue = properties[propName] ?: ' '
277
- setUserProperty(user, propName, propValue)
274
+ setUserProperty(user, propName, propValue as String )
278
275
}
279
276
}
280
277
@@ -530,39 +527,44 @@ class GormUserService implements IUserService {
530
527
@Override
531
528
void addRoles (Collection<RoleRecord > roleRecords ) {
532
529
Role . saveAll(roleRecords. collect { new Role (role : it. role, description : it. description) })
533
-
534
530
}
535
531
536
- @Override
537
- List<UserPropertyRecord > findAllAttributesByName (String s ) {
538
- UserProperty . findAllByName(" flickrId" )
539
- }
532
+ // *********** Property related services *************
540
533
541
534
@Override
542
- void addOrUpdateProperty (UserRecord userRecord , String name , String value ) {
535
+ UserPropertyRecord addOrUpdateProperty (UserRecord userRecord , String name , String value ) {
543
536
assert userRecord instanceof User
544
- UserProperty . addOrUpdateProperty(userRecord, name, value)
537
+ return UserProperty . addOrUpdateProperty(userRecord, name, value)
545
538
}
546
539
547
540
@Override
548
- void removeUserAttributes (UserRecord user , ArrayList<String > attrs ) {
549
- def props = UserProperty . findAllByUserAndNameInList(user, attrs)
541
+ void removeUserProperty (UserRecord user , ArrayList<String > attrs ) {
542
+ def props = UserProperty . findAllByUserAndNameInList(user as User , attrs)
550
543
if (props) UserProperty . deleteAll(props)
551
544
}
552
545
553
546
@Override
554
- void getUserAttribute (UserRecord userRecord , String attribute ) {
555
- UserProperty . findAllByUserAndName(userRecord, attribute)
556
- }
547
+ List<UserPropertyRecord > searchProperty (UserRecord userRecord , String attribute ) {
548
+ List<UserPropertyRecord > propList = []
557
549
558
- @Override
559
- List<UserProperty > getAllAvailableProperties () {
560
- UserProperty . withCriteria {
561
- projections {
562
- distinct(" name" )
563
- }
564
- order(" name" )
550
+ if (userRecord && attribute){
551
+ List properties = UserProperty . findAllByUserAndName(userRecord as User , attribute)
552
+ propList = properties. collect {new UserPropertyRecord (user : userRecord, name : it. name, value : it. value) }
565
553
}
554
+ else if (attribute){
555
+ propList = UserProperty . findAllByName(attribute)
556
+ }
557
+ else {
558
+ List properties = UserProperty . withCriteria {
559
+ projections {
560
+ distinct(" name" )
561
+ }
562
+ order(" name" )
563
+ } as List
564
+
565
+ propList = properties. collect { new UserPropertyRecord (user : it. user, name : it. name, value : it. value) }
566
+ }
567
+ return propList
566
568
}
567
569
568
570
@Override
@@ -652,6 +654,8 @@ class GormUserService implements IUserService {
652
654
emailService. sendAccountActivation(user, user. tempAuthKey)
653
655
}
654
656
657
+ // *********** MFA services *************
658
+
655
659
@Override
656
660
String getSecretForMfa () {}
657
661
@@ -660,4 +664,12 @@ class GormUserService implements IUserService {
660
664
661
665
@Override
662
666
void enableMfa (String userId , boolean enable ){}
667
+
668
+ def getUserDetailsFromIdList (List idList ){
669
+ def c = User . createCriteria()
670
+ def results = c. list() {
671
+ ' in' (" id" , idList. collect { userId -> userId as long } )
672
+ }
673
+ return results
674
+ }
663
675
}
0 commit comments