chore: Minor code refactor for seat based pricing (#38359)
## Description > [!TIP] > _Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team)._ > > _Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR._ Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /test sanity ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/12490386991> > Commit: a06c91677563b3b78d50f3a439ebb9b83196d130 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12490386991&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Wed, 25 Dec 2024 07:41:48 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced methods for user retrieval and signup conditions, enhancing user management capabilities. - Added functionality to retrieve system-generated user emails. - **Bug Fixes** - Improved user lookup process by centralizing logic into dedicated methods. - **Documentation** - Updated method visibility for better accessibility of user-related functionalities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
65391ab2e0
commit
f078ec0b32
|
|
@ -47,9 +47,7 @@ public class CustomOAuth2UserServiceCEImpl extends DefaultReactiveOAuth2UserServ
|
|||
|
||||
String username = oAuth2User.getName();
|
||||
|
||||
return repository
|
||||
.findByEmail(username)
|
||||
.switchIfEmpty(repository.findFirstByEmailIgnoreCaseOrderByCreatedAtDesc(username))
|
||||
return this.findByUsername(username)
|
||||
.switchIfEmpty(Mono.defer(() -> {
|
||||
User newUser = new User();
|
||||
newUser.setName(oAuth2User.getName());
|
||||
|
|
@ -76,4 +74,10 @@ public class CustomOAuth2UserServiceCEImpl extends DefaultReactiveOAuth2UserServ
|
|||
error -> new AppsmithOAuth2AuthenticationException(
|
||||
new OAuth2Error(error.getAppErrorCode().toString(), error.getMessage(), "")));
|
||||
}
|
||||
|
||||
protected Mono<User> findByUsername(String email) {
|
||||
return repository
|
||||
.findByEmail(email)
|
||||
.switchIfEmpty(repository.findFirstByEmailIgnoreCaseOrderByCreatedAtDesc(email));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,9 +49,7 @@ public class CustomOidcUserServiceCEImpl extends OidcReactiveOAuth2UserService {
|
|||
|
||||
String username = (!StringUtils.isEmpty(oidcUser.getEmail())) ? oidcUser.getEmail() : oidcUser.getName();
|
||||
|
||||
return repository
|
||||
.findByEmail(username)
|
||||
.switchIfEmpty(repository.findFirstByEmailIgnoreCaseOrderByCreatedAtDesc(username))
|
||||
return this.findByUsername(username)
|
||||
.switchIfEmpty(Mono.defer(() -> {
|
||||
User newUser = new User();
|
||||
if (oidcUser.getUserInfo() != null) {
|
||||
|
|
@ -82,4 +80,10 @@ public class CustomOidcUserServiceCEImpl extends OidcReactiveOAuth2UserService {
|
|||
error -> new AppsmithOAuth2AuthenticationException(
|
||||
new OAuth2Error(error.getAppErrorCode().toString(), error.getMessage(), "")));
|
||||
}
|
||||
|
||||
protected Mono<User> findByUsername(String email) {
|
||||
return repository
|
||||
.findByEmail(email)
|
||||
.switchIfEmpty(repository.findFirstByEmailIgnoreCaseOrderByCreatedAtDesc(email));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import com.appsmith.server.repositories.AppsmithRepository;
|
|||
import org.springframework.data.mongodb.core.query.UpdateDefinition;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface CustomUserRepositoryCE extends AppsmithRepository<User> {
|
||||
|
||||
Mono<User> findByEmail(String email, AclPermission aclPermission);
|
||||
|
|
@ -14,5 +16,7 @@ public interface CustomUserRepositoryCE extends AppsmithRepository<User> {
|
|||
|
||||
Mono<Boolean> isUsersEmpty();
|
||||
|
||||
Set<String> getSystemGeneratedUserEmails();
|
||||
|
||||
Mono<Integer> updateById(String id, UpdateDefinition updateObj);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ public class CustomUserRepositoryCEImpl extends BaseAppsmithRepositoryImpl<User>
|
|||
.map(count -> count == 0);
|
||||
}
|
||||
|
||||
protected Set<String> getSystemGeneratedUserEmails() {
|
||||
@Override
|
||||
public Set<String> getSystemGeneratedUserEmails() {
|
||||
Set<String> systemGeneratedEmails = new HashSet<>();
|
||||
systemGeneratedEmails.add(FieldName.ANONYMOUS_USER);
|
||||
return systemGeneratedEmails;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ public interface UserServiceCE extends CrudService<User, String> {
|
|||
|
||||
Flux<User> getAllByEmails(Set<String> emails, AclPermission permission);
|
||||
|
||||
Mono<User> signupIfAllowed(User user);
|
||||
|
||||
Mono<User> updateWithoutPermission(String id, User update);
|
||||
|
||||
Mono<Boolean> resendEmailVerification(ResendEmailVerificationDTO resendEmailVerificationDTO, String redirectUrl);
|
||||
|
|
|
|||
|
|
@ -510,7 +510,8 @@ public class UserServiceCEImpl extends BaseService<UserRepository, User, String>
|
|||
* @param user User object representing the user to be created/enabled.
|
||||
* @return Publishes the user object, after having been saved.
|
||||
*/
|
||||
private Mono<User> signupIfAllowed(User user) {
|
||||
@Override
|
||||
public Mono<User> signupIfAllowed(User user) {
|
||||
boolean isAdminUser = false;
|
||||
|
||||
if (!commonConfig.getAdminEmails().contains(user.getEmail())) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user