-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(users): handle external change of user email address by storing p…
…reviously known email addresses and falling back to search by former addresses when necessary introduce generic ids for users instead of using emails as ids closes #242
- Loading branch information
Showing
31 changed files
with
297 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,16 @@ | |
package org.eclipse.sw360.datahandler.db; | ||
|
||
import org.eclipse.sw360.components.summary.UserSummary; | ||
import org.eclipse.sw360.datahandler.common.CommonUtils; | ||
import org.eclipse.sw360.datahandler.couchdb.DatabaseConnector; | ||
import org.eclipse.sw360.datahandler.couchdb.SummaryAwareRepository; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.ektorp.support.View; | ||
import org.ektorp.support.Views; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* CRUD access for the User class | ||
|
@@ -26,7 +29,24 @@ | |
* @author [email protected] | ||
*/ | ||
|
||
@View(name = "all", map = "function(doc) { if (doc.type == 'user') emit(null, doc._id) }") | ||
@Views({ | ||
@View(name = "all", | ||
map = "function(doc) { if (doc.type == 'user') emit(null, doc._id) }"), | ||
@View(name = "byExternalId", | ||
map = "function(doc) { if (doc.type == 'user') emit(doc.externalid, doc._id) }"), | ||
@View(name = "byEmail", | ||
map = "function(doc) { " + | ||
" if (doc.type == 'user') {" + | ||
" emit(doc.email, doc._id); " + | ||
" if (doc.formerEmailAddresses && Array.isArray(doc.formerEmailAddresses)) {" + | ||
" var arr = doc.formerEmailAddresses;" + | ||
" for (var i = 0; i < arr.length; i++){" + | ||
" emit(arr[i], doc._id);" + | ||
" }" + | ||
" }" + | ||
" }" + | ||
"}"), | ||
}) | ||
public class UserRepository extends SummaryAwareRepository<User> { | ||
public UserRepository(DatabaseConnector databaseConnector) { | ||
super(User.class, databaseConnector, new UserSummary()); | ||
|
@@ -37,4 +57,18 @@ public UserRepository(DatabaseConnector databaseConnector) { | |
public List<User> get(Collection<String> ids) { | ||
return getConnector().get(User.class, ids, true); | ||
} | ||
|
||
public User getByExternalId(String externalId) { | ||
final Set<String> userIds = queryForIdsAsValue("byExternalId", externalId); | ||
if (userIds != null && !userIds.isEmpty()) | ||
return get(CommonUtils.getFirst(userIds)); | ||
return null; | ||
} | ||
|
||
public User getByEmail(String email) { | ||
final Set<String> userIds = queryForIdsAsValue("byEmail", email); | ||
if (userIds != null && !userIds.isEmpty()) | ||
return get(CommonUtils.getFirst(userIds)); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,8 @@ public class ComponentDatabaseHandlerTest { | |
private static final String email1 = "[email protected]"; | ||
private static final String email2 = "[email protected]"; | ||
|
||
private static final User user1 = new User().setEmail(email1).setDepartment("AB CD EF").setId(email1); | ||
private static final User user2 = new User().setEmail(email2).setDepartment("AB CD EF").setId(email2); | ||
private static final User user1 = new User().setEmail(email1).setDepartment("AB CD EF").setId("481489458"); | ||
private static final User user2 = new User().setEmail(email2).setDepartment("AB CD EF").setId("4786487647680"); | ||
|
||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public static void main(String[] args) throws TException, IOException { | |
TProtocol protocol = new TCompactProtocol(thriftClient); | ||
ModerationService.Iface client = new ModerationService.Client(protocol); | ||
|
||
List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(new User().setId("").setEmail("[email protected]").setDepartment("BB")); | ||
List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(new User().setId("58245y9845").setEmail("[email protected]").setDepartment("BB")); | ||
|
||
|
||
System.out.println("Fetched " + requestsByModerator.size() + " moderation requests from moderation service"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.