-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: Remove fetching users without organizationId #39656
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
Changes from all commits
e03a87c
a5e7c96
6ab1be1
e9ca470
84d3360
f0cb554
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.appsmith.server.helpers; | ||
|
|
||
| import com.appsmith.server.helpers.ce.UserOrganizationHelperCE; | ||
|
|
||
| public interface UserOrganizationHelper extends UserOrganizationHelperCE {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.appsmith.server.helpers; | ||
|
|
||
| import com.appsmith.server.helpers.ce.UserOrganizationHelperCEImpl; | ||
| import com.appsmith.server.repositories.OrganizationRepository; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class UserOrganizationHelperImpl extends UserOrganizationHelperCEImpl implements UserOrganizationHelper { | ||
| public UserOrganizationHelperImpl( | ||
| OrganizationRepository organizationRepository, | ||
| InMemoryCacheableRepositoryHelper inMemoryCacheableRepositoryHelper) { | ||
| super(organizationRepository, inMemoryCacheableRepositoryHelper); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.appsmith.server.helpers.ce; | ||
|
|
||
| import reactor.core.publisher.Mono; | ||
|
|
||
| public interface UserOrganizationHelperCE { | ||
| /** | ||
| * Gets the organization ID for the current user. If not found in user context, falls back to default organization. | ||
| * @return Mono containing the organization ID | ||
| */ | ||
| Mono<String> getCurrentUserOrganizationId(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.appsmith.server.helpers.ce; | ||
|
|
||
| import com.appsmith.server.domains.Organization; | ||
| import com.appsmith.server.helpers.InMemoryCacheableRepositoryHelper; | ||
| import com.appsmith.server.repositories.OrganizationRepository; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.util.StringUtils; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import static com.appsmith.server.constants.FieldName.DEFAULT; | ||
|
|
||
| @Slf4j | ||
| public class UserOrganizationHelperCEImpl implements UserOrganizationHelperCE { | ||
|
|
||
| private final OrganizationRepository organizationRepository; | ||
| private final InMemoryCacheableRepositoryHelper inMemoryCacheableRepositoryHelper; | ||
|
|
||
| public UserOrganizationHelperCEImpl( | ||
| OrganizationRepository organizationRepository, | ||
| InMemoryCacheableRepositoryHelper inMemoryCacheableRepositoryHelper) { | ||
| this.organizationRepository = organizationRepository; | ||
| this.inMemoryCacheableRepositoryHelper = inMemoryCacheableRepositoryHelper; | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<String> getCurrentUserOrganizationId() { | ||
| return getDefaultOrganizationId(); | ||
| } | ||
|
|
||
| protected Mono<String> getDefaultOrganizationId() { | ||
| // If the value exists in cache, return it as is | ||
| if (StringUtils.hasLength(inMemoryCacheableRepositoryHelper.getDefaultOrganizationId())) { | ||
| return Mono.just(inMemoryCacheableRepositoryHelper.getDefaultOrganizationId()); | ||
| } | ||
| return organizationRepository | ||
| .findBySlug(DEFAULT) | ||
| .map(Organization::getId) | ||
| .map(organizationId -> { | ||
| // Set the cache value before returning. | ||
| inMemoryCacheableRepositoryHelper.setDefaultOrganizationId(organizationId); | ||
| return organizationId; | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.appsmith.server.migrations.db.ce; | ||
|
|
||
| import io.mongock.api.annotations.ChangeUnit; | ||
| import io.mongock.api.annotations.Execution; | ||
| import io.mongock.api.annotations.RollbackExecution; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.bson.Document; | ||
| import org.springframework.data.mongodb.core.MongoTemplate; | ||
| import org.springframework.data.mongodb.core.query.Query; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.springframework.data.mongodb.core.query.Criteria.where; | ||
|
|
||
| @Slf4j | ||
| @ChangeUnit(id = "add-organization-id-to-password-reset-token", order = "068") | ||
| public class Migration068_AddOrganizationIdToPasswordResetToken { | ||
|
|
||
| private final MongoTemplate mongoTemplate; | ||
|
|
||
| public Migration068_AddOrganizationIdToPasswordResetToken(MongoTemplate mongoTemplate) { | ||
| this.mongoTemplate = mongoTemplate; | ||
| } | ||
|
|
||
| @RollbackExecution | ||
| public void rollbackExecution() {} | ||
|
|
||
| @Execution | ||
| public void execute() { | ||
| try { | ||
| // Get the organization ID from the organization collection | ||
| Document organization = mongoTemplate.findOne(new Query(), Document.class, "organization"); | ||
| if (organization == null) { | ||
| log.info("No organization found to migrate password reset tokens"); | ||
| return; | ||
| } | ||
| String organizationId = organization.getObjectId("_id").toString(); | ||
|
|
||
| // Update all password reset tokens that don't have an organizationId | ||
| Query query = new Query(where("organizationId").exists(false)); | ||
| List<Document> pipeline = | ||
| Arrays.asList(new Document("$set", new Document("organizationId", organizationId))); | ||
|
|
||
| long updatedCount = mongoTemplate | ||
| .getCollection("passwordResetToken") | ||
| .updateMany(query.getQueryObject(), pipeline) | ||
| .getModifiedCount(); | ||
|
|
||
| log.info("Successfully set organizationId for {} password reset token documents", updatedCount); | ||
| } catch (Exception e) { | ||
| log.error("Error while setting organizationId for password reset tokens: ", e); | ||
| throw e; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,10 @@ | ||
| package com.appsmith.server.repositories.ce; | ||
|
|
||
| import com.appsmith.server.acl.AclPermission; | ||
| import com.appsmith.server.constants.FieldName; | ||
| import com.appsmith.server.domains.User; | ||
| import com.appsmith.server.exceptions.AppsmithError; | ||
| import com.appsmith.server.exceptions.AppsmithException; | ||
| import com.appsmith.server.helpers.ce.bridge.Bridge; | ||
| import com.appsmith.server.helpers.ce.bridge.BridgeQuery; | ||
| import com.appsmith.server.projections.IdOnly; | ||
| import com.appsmith.server.repositories.BaseAppsmithRepositoryImpl; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
@@ -19,12 +17,6 @@ | |
| @Slf4j | ||
| public class CustomUserRepositoryCEImpl extends BaseAppsmithRepositoryImpl<User> implements CustomUserRepositoryCE { | ||
|
|
||
| @Override | ||
| public Mono<User> findByEmail(String email, AclPermission aclPermission) { | ||
| BridgeQuery<User> emailCriteria = Bridge.equal(User.Fields.email, email); | ||
| return queryBuilder().criteria(emailCriteria).permission(aclPermission).one(); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<User> findByEmailAndOrganizationId(String email, String organizationId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want to introduce the permission check here considering we are swithing the unique constraints to email + orgId.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this wasn't being used at all in the code. So, jsut removed it. The day we need it, we can add it back with organizationId also as a parameter. |
||
| return queryBuilder() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Private field added but not initialized in constructor.
The private field
userOrganizationHelperhas been added but isn't being initialized in the constructor. Since it's passed to the superclass, it should also be assigned to the field.public CustomOidcUserServiceImpl( UserRepository repository, UserService userService, UserOrganizationHelper userOrganizationHelper) { super(repository, userService, userOrganizationHelper); this.repository = repository; this.userService = userService; + this.userOrganizationHelper = userOrganizationHelper; }📝 Committable suggestion