diff --git a/application-ldapuserimport-api/src/main/java/com/xwiki/ldapuserimport/internal/DefaultLDAPUserImportManager.java b/application-ldapuserimport-api/src/main/java/com/xwiki/ldapuserimport/internal/DefaultLDAPUserImportManager.java index 3c8f6f6..5f15a44 100644 --- a/application-ldapuserimport-api/src/main/java/com/xwiki/ldapuserimport/internal/DefaultLDAPUserImportManager.java +++ b/application-ldapuserimport-api/src/main/java/com/xwiki/ldapuserimport/internal/DefaultLDAPUserImportManager.java @@ -190,6 +190,8 @@ private StringBuilder getFilter(String searchInput, String searchFields) private Map> getUsers(Set fieldsToReturn, PagedLDAPSearchResults result, String uidFieldName, Map fieldsMap) { + XWikiContext xcontext = contextProvider.get(); + XWiki xwiki = xcontext.getWiki(); SortedMap> users = new TreeMap<>(); LDAPEntry resultEntry = null; try { @@ -198,6 +200,8 @@ private Map> getUsers(Set fieldsToReturn, Pa do { String uidFieldValue = getAttributeValue(uidFieldName, resultEntry); if (StringUtils.isNoneBlank(uidFieldValue)) { + DocumentReference userReference = + new DocumentReference(xcontext.getMainXWiki(), XWIKI, uidFieldValue); Map user = new HashMap<>(); for (String field : fieldsToReturn) { // For first_name=givenName in the LDAP fields mapping, store the LDAP attribute value in @@ -208,7 +212,15 @@ private Map> getUsers(Set fieldsToReturn, Pa user.put(field, getAttributeValue(field, resultEntry)); } } - user.put("exists", checkUser(uidFieldValue)); + + boolean userExists = xwiki.exists(userReference, xcontext); + String userProfile = userReference.toString(); + if (userExists) { + String userProfileURL = xwiki.getURL(userReference, xcontext); + user.put("userProfileURL", userProfileURL); + } + user.put("userProfile", userProfile); + user.put("exists", Boolean.toString(userExists)); users.put(uidFieldValue, user); } resultEntry = result.hasMore() ? result.next() : null; @@ -227,14 +239,6 @@ private Map> getUsers(Set fieldsToReturn, Pa return users; } - private String checkUser(String uidFieldValue) - { - XWikiContext xcontext = contextProvider.get(); - XWiki xwiki = xcontext.getWiki(); - DocumentReference userReference = new DocumentReference(xcontext.getMainXWiki(), XWIKI, uidFieldValue); - return Boolean.toString(xwiki.exists(userReference, xcontext)); - } - private String getAttributeValue(String fieldName, LDAPEntry resultEntry) { String value = ""; diff --git a/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportService.xml b/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportService.xml index c863d80..ef1f9be 100644 --- a/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportService.xml +++ b/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportService.xml @@ -52,6 +52,15 @@ $jsontool.serialize($users) #else #set ($users = $services.ldapuserimport.getUsers($request.singleField, $request.allFields, $request.searchInput)) + #foreach ($user in $users.entrySet()) + #set ($params = [$user.value.first_name, $user.value.last_name, $user.key, $user.value.email]) + #if ($user.value.exists == true) + #set ($message = $services.localization.render('importUsers.modal.user.alreadyImported', $params)) + #else + #set ($message = $services.localization.render('importUsers.modal.user.toImport', $params)) + #end + #set ($user.value.displayMessage = $message) + #end #set ($statusCode = 200) $jsontool.serialize($users) #end diff --git a/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportTranslations.xml b/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportTranslations.xml index 936e992..7668e80 100644 --- a/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportTranslations.xml +++ b/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportTranslations.xml @@ -46,9 +46,9 @@ importUsers.modal.fieldValue.label=Search text importUsers.modal.fieldValue.search=Search importUsers.modal.fieldValue.noResults=No users were found for the searched value! importUsers.modal.fieldValue.loadingResults=Loading results ... -importUsers.modal.user.imported=imported -importUsers.modal.user.notImported=not imported importUsers.modal.user.failedImport=Failed to import users! +importUsers.modal.user.alreadyImported={0} {1} ({2}, {3}) already imported in +importUsers.modal.user.toImport={0} {1} ({2}, {3}) to import in admin.ldapuserimport=LDAP User Import diff --git a/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportUIX.xml b/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportUIX.xml index d195fb6..4d409fc 100644 --- a/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportUIX.xml +++ b/application-ldapuserimport-ui/src/main/resources/LDAPUserImport/LDAPUserImportUIX.xml @@ -304,16 +304,21 @@ var resultsList = $('<ul/>').attr({'id': 'usersList'}); var displayImportButton = false; $.each(users, function(index, value) { - var displayedText = 'xwiki:' + 'XWiki.' + index + ' [' + value['first_name'] + ' ' + value['last_name'] + ', ' + value['email'] + ']'; - var mention = 'notImported'; - var mentionText = "$services.localization.render('importUsers.modal.user.notImported')"; + var tooltipInfo = ''; + $.each(value, function(i, v) { + if (i !== 'displayMessage') + tooltipInfo += i + ' = ' + v + '\n'; + }) + var displayedText = value['displayMessage'] + ' '; + var itemCSSClass = 'notImported'; var listItem = $('<li/>'); // If the user exists, it will be represented as plain text. // If the user doesn't exist, it will be represented as a label and a checkbox to be selected for import. if (value.exists === 'true') { - listItem.text(displayedText); - mention = 'imported'; - mentionText = "$services.localization.render('importUsers.modal.user.imported')"; + var userProfile = $('<a/>').attr({'href': value['userProfileURL']}).text(value['userProfile']); + listItem.html(displayedText); + listItem.append(userProfile) + itemCSSClass = 'imported'; } else { displayImportButton = true; var checkbox = $('<input/>').attr({ @@ -323,14 +328,13 @@ 'value': index }); var label = $('<label/>').attr({ - 'for': index - }).text(displayedText); + 'for': index, + 'title': tooltipInfo + }).text(displayedText + value['userProfile']); listItem.append(checkbox); listItem.append(label); } - listItem.attr({'class': mention}); - var mentionSpan = $('<span/>').text(mentionText); - listItem.append(mentionSpan); + listItem.attr({'class': itemCSSClass}); resultsList.append(listItem); }); resultsContainer.html(resultsList);