Skip to content

Commit

Permalink
fix: Super user cache eviction when user is added via env variable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
abhvsn authored Nov 28, 2024
2 parents 455abf8 + 9a285aa commit 6c5fc61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
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

0 comments on commit 6c5fc61

Please sign in to comment.