Skip to content

Dev -> Main for Release 2.4.3 #1031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 9, 2024
Prev Previous commit
Next Next commit
Add email field to user and match users by email
  • Loading branch information
Thomasr authored and ludomikula committed Jul 9, 2024
commit ed66ed39221fad1d8e129e256c8be87d43c49f5b
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Mono<Organization> createDefault(User user, boolean isSuperAdmin) {

private Mono<Boolean> joinOrganizationInEnterpriseMode(String userId) {
return getOrganizationInEnterpriseMode()
.flatMap(organization -> orgMemberService.addMember(organization.getGid(), userId, MemberRole.MEMBER))
.flatMap(organization -> orgMemberService.addMember(organization.getId(), userId, MemberRole.MEMBER))
.defaultIfEmpty(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class AuthUser {

private String uid;
private String username;
private String email;
private String avatar;
private Map<String, Object> rawUserInfo;
private Map<String, Object> extra;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class User extends HasIdAndAuditing implements BeforeMongodbWrite, AfterM

private String name;

private String email;

private String uiLanguage;

private String avatar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public Mono<User> findByAuthUserRawId(AuthUser authUser) {
public Mono<User> createNewUserByAuthUser(AuthUser authUser) {
User.UserBuilder userBuilder = User.builder()
.name(authUser.getUsername())
.email(authUser.getEmail())
.state(UserState.ACTIVATED)
.isEnabled(true)
.tpAvatarLink(authUser.getAvatar());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static AuthUser mapToAuthUser(Map<String, Object> map, HashMap<String, St
return AuthUser.builder()
.uid(uid)
.username(username)
.email(email)
.avatar(avatar)
.rawUserInfo(map)
.build();
Expand All @@ -111,6 +112,7 @@ public static AuthUser mergeAuthUser(AuthUser low, AuthUser high) {
return AuthUser.builder()
.uid(high.getUid() != null ? high.getUid() : low.getUid())
.username(high.getUsername() != null ? high.getUsername() : low.getUsername())
.email(high.getEmail() != null ? high.getEmail() : low.getEmail())
.avatar(high.getAvatar() != null ? high.getAvatar() : low.getAvatar())
.rawUserInfo(high.getRawUserInfo() != null ? high.getRawUserInfo() : low.getRawUserInfo())
.authToken(high.getAuthToken() != null ? high.getAuthToken() : low.getAuthToken())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,30 @@ public void addGidToDBObjects(MongockTemplate mongoTemplate) {
}
}

@ChangeSet(order = "023", id = "add-email", author = "")
public void addEmailField(MongockTemplate mongoTemplate) {
// Create a query to match all documents
Query query = new Query();

// Use a DocumentCallbackHandler to iterate through each document
mongoTemplate.executeQuery(query, "user", new DocumentCallbackHandler() {
@Override
public void processDocument(Document document) {
// Generate a random UUID and ensure it is unique within the collection
String username = document.getString("name");
// Create an update object to add the 'gid' field
Update update = new Update();
update.set("email", username);

// Create a query to match the current document by its _id
Query idQuery = new Query(Criteria.where("_id").is(document.getObjectId("_id")));

// Update the document with the new 'gid' field
mongoTemplate.updateFirst(idQuery, update, "user");
}
});
}

private void addGidField(MongockTemplate mongoTemplate, String collectionName) {
// Create a query to match all documents
Query query = new Query();
Expand Down