Skip to content

Commit 33f28e1

Browse files
authored
fix: bulk migration to actually use the input value for the email verification (#1137)
1 parent 96def24 commit 33f28e1

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [10.1.4]
11+
12+
- Bulk migration now actually uses the `isVerified` field's value in the loginMethod input
13+
14+
1015
## [10.1.3]
1116

1217
- Version bumped for re-release

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
1919
// }
2020
//}
2121

22-
version = "10.1.3"
22+
version = "10.1.4"
2323

2424
repositories {
2525
mavenCentral()

src/main/java/io/supertokens/bulkimport/BulkImport.java

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import io.supertokens.userroles.UserRoles;
7474
import io.supertokens.utils.Utils;
7575
import jakarta.servlet.ServletException;
76+
import org.jetbrains.annotations.NotNull;
7677
import org.slf4j.Logger;
7778
import org.slf4j.LoggerFactory;
7879

@@ -672,31 +673,45 @@ public static void createMultipleUserRoles(Main main, AppIdentifier appIdentifie
672673
public static void verifyMultipleEmailForAllLoginMethods(AppIdentifier appIdentifier, Storage storage,
673674
List<BulkImportUser> users)
674675
throws StorageTransactionLogicException {
675-
Map<String, String> emailToUserId = new HashMap<>();
676-
for (BulkImportUser user : users) {
677-
for (LoginMethod lm : user.loginMethods) {
678-
emailToUserId.put(lm.getSuperTokenOrExternalUserId(), lm.email);
679-
}
680-
}
681676

677+
Map<String, String> emailToUserId = collectVerifiedEmailAddressesByUserIds(users);
682678
try {
683-
if(!emailToUserId.isEmpty()) {
684-
EmailVerificationSQLStorage emailVerificationSQLStorage = StorageUtils
685-
.getEmailVerificationStorage(storage);
686-
emailVerificationSQLStorage.startTransaction(con -> {
687-
emailVerificationSQLStorage
688-
.updateMultipleIsEmailVerified_Transaction(appIdentifier, con,
689-
emailToUserId, true);
690-
691-
emailVerificationSQLStorage.commitTransaction(con);
692-
return null;
693-
});
694-
}
679+
verifyCollectedEmailAddressesForUsers(appIdentifier, storage, emailToUserId);
695680
} catch (StorageQueryException e) {
696681
throw new StorageTransactionLogicException(e);
697682
}
698683
}
699684

685+
private static void verifyCollectedEmailAddressesForUsers(AppIdentifier appIdentifier, Storage storage, Map<String, String> emailToUserId)
686+
throws StorageQueryException, StorageTransactionLogicException {
687+
if(!emailToUserId.isEmpty()) {
688+
EmailVerificationSQLStorage emailVerificationSQLStorage = StorageUtils
689+
.getEmailVerificationStorage(storage);
690+
emailVerificationSQLStorage.startTransaction(con -> {
691+
emailVerificationSQLStorage
692+
.updateMultipleIsEmailVerified_Transaction(appIdentifier, con,
693+
emailToUserId, true); //only the verified email addresses are expected to be in the map
694+
695+
emailVerificationSQLStorage.commitTransaction(con);
696+
return null;
697+
});
698+
}
699+
}
700+
701+
@NotNull
702+
private static Map<String, String> collectVerifiedEmailAddressesByUserIds(List<BulkImportUser> users) {
703+
Map<String, String> emailToUserId = new HashMap<>();
704+
for (BulkImportUser user : users) {
705+
for (LoginMethod lm : user.loginMethods) {
706+
if(lm.isVerified) {
707+
//collect the verified email addresses for the userId
708+
emailToUserId.put(lm.getSuperTokenOrExternalUserId(), lm.email);
709+
}
710+
}
711+
}
712+
return emailToUserId;
713+
}
714+
700715
public static void createMultipleTotpDevices(Main main, AppIdentifier appIdentifier,
701716
Storage storage, List<BulkImportUser> users)
702717
throws StorageTransactionLogicException {

src/test/java/io/supertokens/test/bulkimport/BulkImportTestUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.IOException;
4646
import java.util.ArrayList;
4747
import java.util.List;
48+
import java.util.Random;
4849

4950
import static org.junit.Assert.*;
5051

@@ -79,13 +80,14 @@ public static List<BulkImportUser> generateBulkImportUserWithRoles(int numberOfU
7980

8081
List<LoginMethod> loginMethods = new ArrayList<>();
8182
long currentTimeMillis = System.currentTimeMillis();
82-
loginMethods.add(new LoginMethod(tenants, "emailpassword", true, true, currentTimeMillis, email, "$2a",
83+
Random random = new Random();
84+
loginMethods.add(new LoginMethod(tenants, "emailpassword", random.nextBoolean(), true, currentTimeMillis, email, "$2a",
8385
"BCRYPT", null, null, null, null, io.supertokens.utils.Utils.getUUID()));
8486
loginMethods
85-
.add(new LoginMethod(tenants, "thirdparty", true, false, currentTimeMillis, email, null, null, null,
87+
.add(new LoginMethod(tenants, "thirdparty", random.nextBoolean(), false, currentTimeMillis, email, null, null, null,
8688
"thirdPartyId" + i, "thirdPartyUserId" + i, null, io.supertokens.utils.Utils.getUUID()));
8789
loginMethods.add(
88-
new LoginMethod(tenants, "passwordless", true, false, currentTimeMillis, email, null, null, null,
90+
new LoginMethod(tenants, "passwordless", random.nextBoolean(), false, currentTimeMillis, email, null, null, null,
8991
null, null, null, io.supertokens.utils.Utils.getUUID()));
9092
id = loginMethods.get(0).superTokensUserId;
9193
users.add(new BulkImportUser(id, externalId, userMetadata, userRoles, totpDevices, loginMethods));

0 commit comments

Comments
 (0)