Skip to content
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

feat: plugin interface changes for ProcessBulkImportUsers cron #142

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ List<BulkImportUser> getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull In
*/
List<String> deleteBulkImportUsers(AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds) throws StorageQueryException;

/**
* Returns the users from the bulk_import_users table for processing
*/
List<BulkImportUser> getBulkImportUsersForProcessing(AppIdentifier appIdentifier, @Nonnull Integer limit) throws StorageQueryException;

public enum BULK_IMPORT_USER_STATUS {
NEW, PROCESSING, FAILED
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ public class BulkImportUser {
public String id;
public String externalUserId;
public JsonObject userMetadata;
public List<String> userRoles;
public List<UserRole> userRoles;
public List<TotpDevice> totpDevices;
public List<LoginMethod> loginMethods;

// Following fields come from the DB Record.
public BULK_IMPORT_USER_STATUS status;
public String errorMessage;
public Long createdAt;
public Long updatedAt;

public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List<String> userRoles,
public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List<UserRole> userRoles,
List<TotpDevice> totpDevices, List<LoginMethod> loginMethods) {
this.id = id;
this.externalUserId = externalUserId;
Expand All @@ -46,7 +47,7 @@ public BulkImportUser(String id, String externalUserId, JsonObject userMetadata,
this.loginMethods = loginMethods;
}

public static BulkImportUser fromTesting_fromJson(JsonObject jsonObject) {
public static BulkImportUser forTesting_fromJson(JsonObject jsonObject) {
return new Gson().fromJson(jsonObject, BulkImportUser.class);
}

Expand All @@ -60,10 +61,11 @@ public String toRawDataForDbStorage() {
return jsonObject.toString();
}

public static BulkImportUser fromRawDataFromDbStorage(String id, String rawData, BULK_IMPORT_USER_STATUS status, long createdAt, long updatedAt) {
public static BulkImportUser fromRawDataFromDbStorage(String id, String rawData, BULK_IMPORT_USER_STATUS status, String errorMessage, long createdAt, long updatedAt) {
BulkImportUser user = new Gson().fromJson(rawData, BulkImportUser.class);
user.id = id;
user.status = status;
user.errorMessage = errorMessage;
user.createdAt = createdAt;
user.updatedAt = updatedAt;
return user;
Expand All @@ -73,6 +75,16 @@ public JsonObject toJsonObject() {
return new Gson().fromJson(new Gson().toJson(this), JsonObject.class);
}

public static class UserRole {
public String role;
public List<String> tenantIds;

public UserRole(String role, List<String> tenantIds) {
this.role = role;
this.tenantIds = tenantIds;
}
}

public static class TotpDevice {
public String secretKey;
public int period;
Expand All @@ -88,7 +100,7 @@ public TotpDevice(String secretKey, int period, int skew, String deviceName) {
}

public static class LoginMethod {
public String tenantId;
public List<String> tenantIds;
public boolean isVerified;
public boolean isPrimary;
public long timeJoinedInMSSinceEpoch;
Expand All @@ -99,11 +111,12 @@ public static class LoginMethod {
public String thirdPartyId;
public String thirdPartyUserId;
public String phoneNumber;
public String superTokensOrExternalUserId;

public LoginMethod(String tenantId, String recipeId, boolean isVerified, boolean isPrimary,
public LoginMethod(List<String> tenantIds, String recipeId, boolean isVerified, boolean isPrimary,
long timeJoinedInMSSinceEpoch, String email, String passwordHash, String hashingAlgorithm,
String thirdPartyId, String thirdPartyUserId, String phoneNumber) {
this.tenantId = tenantId;
this.tenantIds = tenantIds;
this.recipeId = recipeId;
this.isVerified = isVerified;
this.isPrimary = isPrimary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.supertokens.pluginInterface.bulkimport.sqlStorage;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import io.supertokens.pluginInterface.bulkimport.BulkImportStorage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
Expand All @@ -30,5 +31,10 @@ public interface BulkImportSQLStorage extends BulkImportStorage, SQLStorage {
* Update the status of the users in the bulk_import_users table
*/
void updateBulkImportUserStatus_Transaction(AppIdentifier appIdentifier,
TransactionConnection con, @Nonnull String[] bulkImportUserIds, @Nonnull BULK_IMPORT_USER_STATUS status) throws StorageQueryException;
TransactionConnection con, @Nonnull String[] bulkImportUserIds, @Nonnull BULK_IMPORT_USER_STATUS status, @Nullable String errorMessage) throws StorageQueryException;

/**
* Delete users by id from the bulk_import_users table
*/
void deleteBulkImportUser_Transaction(AppIdentifier appIdentifier, TransactionConnection con, @Nonnull String bulkImportUserId) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package io.supertokens.pluginInterface.emailpassword.sqlStorage;

import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.emailpassword.EmailPasswordStorage;
import io.supertokens.pluginInterface.emailpassword.PasswordResetTokenInfo;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

Expand Down Expand Up @@ -49,4 +53,8 @@ void updateUsersEmail_Transaction(AppIdentifier appIdentifier, TransactionConnec
void deleteEmailPasswordUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean deleteUserIdMappingToo)
throws StorageQueryException;

AuthRecipeUserInfo bulkImport_signUp_Transaction(TransactionConnection con, TenantIdentifier tenantIdentifier, String id, String email, String passwordHash, long timeJoined)
throws StorageQueryException, DuplicateUserIdException, DuplicateEmailException,
TenantOrAppNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ void updateIsEmailVerified_Transaction(AppIdentifier appIdentifier, TransactionC
void deleteEmailVerificationUserInfo_Transaction(TransactionConnection con, AppIdentifier appIdentifier,
String userId) throws StorageQueryException;

void bulkImport_updateIsEmailVerifiedToExternalUserId_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String supertokensUserId, String externalUserId) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import io.supertokens.pluginInterface.session.SessionStorage;
import io.supertokens.pluginInterface.thirdparty.sqlStorage.ThirdPartySQLStorage;
import io.supertokens.pluginInterface.totp.sqlStorage.TOTPSQLStorage;
import io.supertokens.pluginInterface.useridmapping.UserIdMappingStorage;
import io.supertokens.pluginInterface.useridmapping.sqlStorage.UserIdMappingSQLStorage;
import io.supertokens.pluginInterface.usermetadata.sqlStorage.UserMetadataSQLStorage;
import io.supertokens.pluginInterface.userroles.sqlStorage.UserRolesSQLStorage;

Expand Down Expand Up @@ -120,13 +120,13 @@ public UserMetadataSQLStorage getUserMetadataStorage() {
return (UserMetadataSQLStorage) this.storage;
}

public UserIdMappingStorage getUserIdMappingStorage() {
public UserIdMappingSQLStorage getUserIdMappingStorage() {
if (this.storage.getType() != STORAGE_TYPE.SQL) {
// we only support SQL for now
throw new UnsupportedOperationException("");
}

return (UserIdMappingStorage) this.storage;
return (UserIdMappingSQLStorage) this.storage;
}

public UserRolesSQLStorage getUserRolesStorage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package io.supertokens.pluginInterface.passwordless.sqlStorage;

import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException;
import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.passwordless.PasswordlessCode;
import io.supertokens.pluginInterface.passwordless.PasswordlessDevice;
import io.supertokens.pluginInterface.passwordless.PasswordlessStorage;
Expand Down Expand Up @@ -85,4 +88,9 @@ void updateUserPhoneNumber_Transaction(AppIdentifier appIdentifier, TransactionC
void deletePasswordlessUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean deleteUserIdMappingToo)
throws StorageQueryException;

AuthRecipeUserInfo bulkImport_createUser_Transaction(TransactionConnection con, TenantIdentifier tenantIdentifier, String id,
@Nullable String email, @Nullable String phoneNumber, long timeJoined)
throws StorageQueryException, DuplicateEmailException, DuplicatePhoneNumberException,
DuplicateUserIdException, TenantOrAppNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package io.supertokens.pluginInterface.thirdparty.sqlStorage;

import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.authRecipe.LoginMethod;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.pluginInterface.thirdparty.ThirdPartyStorage;
import io.supertokens.pluginInterface.thirdparty.exception.DuplicateThirdPartyUserException;
import io.supertokens.pluginInterface.thirdparty.exception.DuplicateUserIdException;

public interface ThirdPartySQLStorage extends ThirdPartyStorage, SQLStorage {

Expand All @@ -31,4 +37,10 @@ void updateUserEmail_Transaction(AppIdentifier appIdentifier, TransactionConnect
void deleteThirdPartyUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean deleteUserIdMappingToo)
throws StorageQueryException;

AuthRecipeUserInfo bulkImport_signUp_Transaction(TransactionConnection con, TenantIdentifier tenantIdentifier,
String id, String email, LoginMethod.ThirdParty thirdParty,
long timeJoined)
throws StorageQueryException, DuplicateUserIdException, DuplicateThirdPartyUserException,
TenantOrAppNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@

package io.supertokens.pluginInterface.useridmapping.sqlStorage;

import javax.annotation.Nullable;

import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.pluginInterface.useridmapping.UserIdMapping;
import io.supertokens.pluginInterface.useridmapping.UserIdMappingStorage;
import io.supertokens.pluginInterface.useridmapping.exception.UnknownSuperTokensUserIdException;
import io.supertokens.pluginInterface.useridmapping.exception.UserIdMappingAlreadyExistsException;

public interface UserIdMappingSQLStorage extends UserIdMappingStorage, SQLStorage {
UserIdMapping getUserIdMapping_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId, boolean isSuperTokensUserId)
throws StorageQueryException;

UserIdMapping[] getUserIdMapping_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;

void bulkImport_createUserIdMapping_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String superTokensUserId, String externalUserId,
@Nullable String externalUserIdInfo)
throws StorageQueryException, UnknownSuperTokensUserIdException, UserIdMappingAlreadyExistsException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.pluginInterface.userroles.UserRolesStorage;
import io.supertokens.pluginInterface.userroles.exception.DuplicateUserRoleMappingException;
import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException;

public interface UserRolesSQLStorage extends UserRolesStorage, SQLStorage {
Expand Down Expand Up @@ -56,4 +57,8 @@ boolean doesRoleExist_Transaction(AppIdentifier appIdentifier, TransactionConnec

void deleteAllRolesForUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;

void bulkImport_addRoleToUser_Transaction(TransactionConnection con, TenantIdentifier tenantIdentifier, String userId, String role)
throws StorageQueryException, UnknownRoleException, DuplicateUserRoleMappingException,
TenantOrAppNotFoundException;
}
Loading