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

fix: Super user cache eviction when user is added via env variable #37785

Merged
merged 1 commit into from
Nov 28, 2024
Merged
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 @@ -28,7 +28,6 @@
import com.appsmith.server.helpers.TextUtils;
import com.appsmith.server.migrations.solutions.UpdateSuperUserMigrationHelper;
import com.appsmith.server.repositories.CacheableRepositoryHelper;
import com.appsmith.server.repositories.PermissionGroupRepository;
import com.appsmith.server.solutions.PolicySolution;
import com.github.cloudyrock.mongock.ChangeLog;
import com.github.cloudyrock.mongock.ChangeSet;
Expand Down Expand Up @@ -451,7 +450,7 @@ public static void doAddPermissionGroupIndex(MongoTemplate mongoTemplate) {
@ChangeSet(order = "10000", id = "update-super-users", author = "", runAlways = true)
public void updateSuperUsers(
MongoTemplate mongoTemplate,
PermissionGroupRepository permissionGroupRepository,
CacheableRepositoryHelper cacheableRepositoryHelper,
PolicySolution policySolution,
PolicyGenerator policyGenerator) {
// Read the admin emails from the environment and update the super users accordingly
Expand Down Expand Up @@ -497,7 +496,7 @@ public void updateSuperUsers(

Set<String> oldSuperUsers = instanceAdminPG.getAssignedToUserIds();
Set<String> updatedUserIds = findSymmetricDiff(oldSuperUsers, userIds);
evictPermissionCacheForUsers(updatedUserIds, mongoTemplate, permissionGroupRepository);
evictPermissionCacheForUsers(updatedUserIds, mongoTemplate, cacheableRepositoryHelper);

Update update = new Update().set(PermissionGroup.Fields.assignedToUserIds, userIds);
mongoTemplate.updateFirst(permissionGroupQuery, update, PermissionGroup.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.helpers.CollectionUtils;
import com.appsmith.server.repositories.PermissionGroupRepository;
import com.appsmith.server.repositories.CacheableRepositoryHelper;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.minidev.json.JSONObject;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void migrateGoogleSheetsActionsToUqi(ApplicationJson applicationJs
}

public static void evictPermissionCacheForUsers(
Set<String> userIds, MongoTemplate mongoTemplate, PermissionGroupRepository permissionGroupRepository) {
Set<String> userIds, MongoTemplate mongoTemplate, CacheableRepositoryHelper cacheableRepositoryHelper) {

if (userIds == null || userIds.isEmpty()) {
// Nothing to do here.
Expand All @@ -223,8 +223,8 @@ public static void evictPermissionCacheForUsers(
User user = mongoTemplate.findOne(query, User.class);
if (user != null) {
// blocking call for cache eviction to ensure its subscribed immediately before proceeding further.
permissionGroupRepository
.evictAllPermissionGroupCachesForUser(user.getEmail(), user.getTenantId())
cacheableRepositoryHelper
.evictPermissionGroupsUser(user.getEmail(), user.getTenantId())
.block();
}
});
Expand Down
Loading