diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java index 50cb44cf670..1ded87b5925 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java @@ -32,7 +32,7 @@ Optional updateById( T setUserPermissionsInObject(T obj, Collection permissionGroups); - T setUserPermissionsInObject(T obj, User user); + T setUserPermissionsInObject(T obj, User user, EntityManager entityManager); T updateAndReturn( String id, BridgeUpdate updateObj, AclPermission permission, User currentUser, EntityManager entityManager); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/cakes/BaseCake.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/cakes/BaseCake.java index 7f3382cffa3..19ef1dc018a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/cakes/BaseCake.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/cakes/BaseCake.java @@ -8,14 +8,12 @@ import com.appsmith.server.repositories.BaseRepository; import com.appsmith.server.repositories.CacheableRepositoryHelper; import jakarta.persistence.EntityManager; -import jakarta.persistence.Transient; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.security.core.context.ReactiveSecurityContextHolder; @@ -24,13 +22,10 @@ import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; -import java.lang.reflect.Field; import java.time.Instant; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.UUID; @@ -202,45 +197,6 @@ public Mono save(T entity) { }); } - /** - * Copy the values of fields marked with {@link Transient} annotation from {@code source} to {@code target}. - * This is also done recursively, for nested object fields as well, unless {@code nest} is 0. - */ - private static void copyTransientFieldValues(T source, T target, int nest) throws IllegalAccessException { - final Class cls = source.getClass(); - - // Get all non-transient field names - final List nonTransientFields = getAllFields(cls).stream() - .filter(field -> field.getAnnotation(Transient.class) == null) - .toList(); - - final List nonTransientFieldNames = - nonTransientFields.stream().map(Field::getName).toList(); - - // merge latest database updated source object with the transient fields - BeanUtils.copyProperties(source, target, nonTransientFieldNames.toArray(new String[0])); - - if (nest > 0) { - --nest; - for (final Field nonTransientField : nonTransientFields) { - nonTransientField.setAccessible(true); - final Object sourceValue = nonTransientField.get(source); - if (sourceValue == null) { - continue; - } - copyTransientFieldValues(sourceValue, nonTransientField.get(target), nest); - } - } - } - - public static List getAllFields(Class type) { - List fields = new ArrayList<>(); - for (Class c = type; c != null; c = c.getSuperclass()) { - fields.addAll(Arrays.asList(c.getDeclaredFields())); - } - return fields; - } - private String generateId() { return UUID.randomUUID().toString(); } @@ -248,11 +204,11 @@ private String generateId() { public Mono findById(String id, AclPermission permission) { return ReactiveSecurityContextHolder.getContext() .map(ctx -> (User) ctx.getAuthentication().getPrincipal()) - .flatMap(this::getAllPermissionGroupsForUser) - .map(ArrayList::new) .zipWith(Mono.deferContextual(ctx -> Mono.just(ctx.getOrDefault(TX_CONTEXT, entityManager)))) + .flatMap(tuple -> this.getAllPermissionGroupsForUser(tuple.getT1(), tuple.getT2()) + .zipWith(Mono.just(tuple.getT2()))) .map(tuple2 -> { - final ArrayList permissionGroups = tuple2.getT1(); + final ArrayList permissionGroups = new ArrayList<>(tuple2.getT1()); final EntityManager em = tuple2.getT2(); final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaQuery cq = cb.createQuery(genericDomain); @@ -278,13 +234,13 @@ public Mono findById(String id, AclPermission permission) { } // FIXME: Duplicate from BaseAppsmithRepositoryCEImpl - private Mono> getAllPermissionGroupsForUser(User user) { + private Mono> getAllPermissionGroupsForUser(User user, EntityManager em) { if (user.getTenantId() == null) { user.setTenantId(cacheableRepositoryHelper.getDefaultTenantId().block()); } return Mono.zip( - cacheableRepositoryHelper.getPermissionGroupsOfUser(user), + cacheableRepositoryHelper.getPermissionGroupsOfUser(user, em), cacheableRepositoryHelper.getPermissionGroupsOfAnonymousUser()) .map(tuple -> { final Set permissionGroups = new HashSet<>(tuple.getT1()); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java index 671613db4c6..4a8c1d62999 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java @@ -254,30 +254,32 @@ public Optional updateFieldById( return Optional.of(count); } - protected Set getCurrentUserPermissionGroupsIfRequired(AclPermission permission, User user) { - return getCurrentUserPermissionGroupsIfRequired(Optional.ofNullable(permission), user, true); + protected Set getCurrentUserPermissionGroupsIfRequired( + AclPermission permission, User user, EntityManager em) { + return getCurrentUserPermissionGroupsIfRequired(Optional.ofNullable(permission), user, true, em); } protected Set getCurrentUserPermissionGroupsIfRequired( - Optional permission, User user, boolean includeAnonymousUserPermissions) { + Optional permission, User user, boolean includeAnonymousUserPermissions, EntityManager em) { // Expect a valid AclPermission and a user to fetch valid permission groups if (permission.isEmpty()) { return Set.of(); } - return getPermissionGroupsForUser(user, includeAnonymousUserPermissions); + return getPermissionGroupsForUser(user, includeAnonymousUserPermissions, em); } - public Set getPermissionGroupsForUser(User user) { - return getPermissionGroupsForUser(user, true); + public Set getPermissionGroupsForUser(User user, EntityManager em) { + return getPermissionGroupsForUser(user, true, em); } - protected Set getPermissionGroupsForUser(User user, boolean includeAnonymousUserPermissions) { + protected Set getPermissionGroupsForUser( + User user, boolean includeAnonymousUserPermissions, EntityManager em) { if (!isValidUser(user)) { return Set.of(); } final Set permissionGroups = includeAnonymousUserPermissions - ? getAllPermissionGroupsForUser(user) - : getStrictPermissionGroupsForUser(user); + ? getAllPermissionGroupsForUser(user, em) + : getStrictPermissionGroupsForUser(user, em); return permissionGroups == null ? Collections.emptySet() : permissionGroups; } @@ -295,16 +297,15 @@ public List queryAllExecute(QueryAllParams params) { @SneakyThrows @SuppressWarnings("unchecked") public

List

queryAllExecute(QueryAllParams params, Class

projectionClass) { + EntityManager em = getEntityManager(params); return Mono.justOrEmpty(params.getPermissionGroups()) - .switchIfEmpty(Mono.defer(() -> - Mono.just(getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser())))) + .switchIfEmpty(Mono.defer(() -> Mono.just( + getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser(), em)))) .map(ArrayList::new) .flatMap(permissionGroups -> { if (params.getPermission() != null && permissionGroups.isEmpty()) { return Mono.just(Collections.

emptyList()); } - - EntityManager em = params.getEntityManager() == null ? entityManager : params.getEntityManager(); final CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(projectionClass); @@ -383,15 +384,15 @@ public Optional queryOneExecute(QueryAllParams params) { @SuppressWarnings("unchecked") public

Optional

queryOneExecute(QueryAllParams params, Class

projectionClass) { + EntityManager em = getEntityManager(params); return Mono.justOrEmpty(params.getPermissionGroups()) - .switchIfEmpty(Mono.defer(() -> - Mono.just(getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser())))) + .switchIfEmpty(Mono.defer(() -> Mono.just( + getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser(), em)))) .map(ArrayList::new) .flatMap(permissionGroups -> { if (params.getPermission() != null && permissionGroups.isEmpty()) { return Mono.empty(); } - EntityManager em = params.getEntityManager() == null ? entityManager : params.getEntityManager(); final CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(projectionClass); // We are creating the query with generic return type as Object[] and then mapping it to the @@ -445,15 +446,15 @@ public Optional queryFirstExecute(QueryAllParams params) { } public Optional countExecute(QueryAllParams params) { + EntityManager em = getEntityManager(params); return Mono.justOrEmpty(params.getPermissionGroups()) - .switchIfEmpty(Mono.defer(() -> - Mono.just(getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser())))) + .switchIfEmpty(Mono.defer(() -> Mono.just( + getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser(), em)))) .map(ArrayList::new) .flatMap(permissionGroups -> { if (params.getPermission() != null && permissionGroups.isEmpty()) { return Mono.just(0L); } - EntityManager em = params.getEntityManager() == null ? entityManager : params.getEntityManager(); final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaQuery cq = cb.createQuery(Long.class); final Root root = cq.from(genericDomain); @@ -482,6 +483,8 @@ public Optional countExecute(QueryAllParams params) { .blockOptional(); } + @Transactional + @Modifying public int updateExecute(@NonNull QueryAllParams params, @NonNull T resource) { // In case the update is not used to update the policies, then set the policies to null to ensure that the // existing policies are not overwritten. @@ -535,12 +538,12 @@ private Mono ensurePermissionGroupsInParams(QueryAllParams params) { if (!CollectionUtils.isEmpty(params.getPermissionGroups())) { return Mono.empty(); } - return Mono.justOrEmpty(params.getPermissionGroups()) .switchIfEmpty(Mono.fromSupplier(() -> getCurrentUserPermissionGroupsIfRequired( Optional.ofNullable(params.getPermission()), params.getUser(), - params.isIncludeAnonymousUserPermissions()))) + params.isIncludeAnonymousUserPermissions(), + getEntityManager(params)))) .doOnSuccess(params::permissionGroups) .then(); } @@ -550,16 +553,14 @@ private Mono ensurePermissionGroupsInParams(QueryAllParams params) { public int updateExecute(QueryAllParams params, BridgeUpdate update) { Set permissionGroupsSet = params.getPermissionGroups(); ArrayList permissionGroups; - + EntityManager em = getEntityManager(params); if (CollectionUtils.isEmpty(permissionGroupsSet)) { - permissionGroups = - new ArrayList<>(getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser())); + permissionGroups = new ArrayList<>( + getCurrentUserPermissionGroupsIfRequired(params.getPermission(), params.getUser(), em)); } else { permissionGroups = new ArrayList<>(permissionGroupsSet); } - final EntityManager em = params.getEntityManager() == null ? getEntityManager() : params.getEntityManager(); - final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaQuery cq = cb.createQuery(genericDomain); final CriteriaUpdate cu = cb.createCriteriaUpdate(genericDomain); @@ -709,10 +710,10 @@ public int updateFirst(BridgeQuery query, T resource, EntityManager entityMan return queryBuilder().entityManager(entityManager).criteria(query).updateFirst(resource); } - public T setUserPermissionsInObject(T obj, User user) { + public T setUserPermissionsInObject(T obj, User user, EntityManager em) { Set permissionGroups = new HashSet<>(); if (isValidUser(user)) { - permissionGroups = getPermissionGroupsForUser(user); + permissionGroups = getPermissionGroupsForUser(user, em); } return setUserPermissionsInObject(obj, permissionGroups); } @@ -748,7 +749,7 @@ public T setUserPermissionsInObject(T obj, Collection permissionGroups) * 2. Get all the permission groups associated with anonymous user * 3. Return the set of all the permission groups. */ - protected Set getAllPermissionGroupsForUser(User user) { + protected Set getAllPermissionGroupsForUser(User user, EntityManager em) { if (!isValidUser(user)) { return Collections.emptySet(); } else if (user.getTenantId() == null) { @@ -756,7 +757,7 @@ protected Set getAllPermissionGroupsForUser(User user) { } Set permissionGroups = new HashSet<>( - cacheableRepositoryHelper.getPermissionGroupsOfUser(user).block()); + cacheableRepositoryHelper.getPermissionGroupsOfUser(user, em).block()); permissionGroups.addAll(getAnonymousUserPermissionGroups().block()); return permissionGroups; @@ -767,7 +768,7 @@ protected Set getAllPermissionGroupsForUser(User user) { * 2. Get all the permission groups associated with anonymous user * 3. Return the set of all the permission groups. */ - protected Set getStrictPermissionGroupsForUser(User user) { + protected Set getStrictPermissionGroupsForUser(User user, EntityManager em) { if (!isValidUser(user)) { return Collections.emptySet(); @@ -775,7 +776,7 @@ protected Set getStrictPermissionGroupsForUser(User user) { String tenantId = cacheableRepositoryHelper.getDefaultTenantId().block(); user.setTenantId(tenantId); } - return cacheableRepositoryHelper.getPermissionGroupsOfUser(user).block(); + return cacheableRepositoryHelper.getPermissionGroupsOfUser(user, em).block(); } protected Mono> getAnonymousUserPermissionGroups() { @@ -886,4 +887,8 @@ private static boolean isValidUser(User user) { && StringUtils.hasLength(user.getEmail()) && (user.isAnonymous() || StringUtils.hasLength(user.getId())); } + + private EntityManager getEntityManager(QueryAllParams params) { + return params.getEntityManager() == null ? entityManager : params.getEntityManager(); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCE.java index fc66e5e2eee..20266c98d24 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCE.java @@ -1,7 +1,9 @@ package com.appsmith.server.repositories.ce; +import com.appsmith.caching.annotations.Cache; import com.appsmith.server.domains.Tenant; import com.appsmith.server.domains.User; +import jakarta.persistence.EntityManager; import reactor.core.publisher.Mono; import java.util.List; @@ -9,8 +11,11 @@ public interface CacheableRepositoryHelperCE { + @Cache(cacheName = "permissionGroupsForUser", key = "{#user.email + #user.tenantId}") Mono> getPermissionGroupsOfUser(User user); + Mono> getPermissionGroupsOfUser(User user, EntityManager entityManager); + Mono> preFillAnonymousUserPermissionGroupIdsCache(); Mono> getPermissionGroupsOfAnonymousUser(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCEImpl.java index 061f8fbaacf..ea9425be84b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CacheableRepositoryHelperCEImpl.java @@ -47,7 +47,7 @@ @Component @RequiredArgsConstructor public class CacheableRepositoryHelperCEImpl implements CacheableRepositoryHelperCE { - private final EntityManager entityManager; + private final EntityManager defaultEntityManager; private final InMemoryCacheableRepositoryHelper inMemoryCacheableRepositoryHelper; private final ObservationRegistry observationRegistry; private static final String CACHE_DEFAULT_PAGE_ID_TO_DEFAULT_APPLICATION_ID = "pageIdToAppId"; @@ -55,6 +55,21 @@ public class CacheableRepositoryHelperCEImpl implements CacheableRepositoryHelpe @Cache(cacheName = "permissionGroupsForUser", key = "{#user.email + #user.tenantId}") @Override public Mono> getPermissionGroupsOfUser(User user) { + return getPermissionGroupsOfUser(user, defaultEntityManager); + } + /** + * Returns the permission groups of the user. If the user is anonymous, then it returns the permission groups of + * the anonymous user. + * @param user The user whose permission groups are + * @param entityManager The entity manager to use for fetching the permission groups, as we expect the permission + * groups will change over time for the user we are making requests with custom entity manager + * that can be passed by the consumer. This is helpful if the consumer wants to fetch the + * permission groups in a transactional context. + * @return A set of permission group ids + */ + @Cache(cacheName = "permissionGroupsForUser", key = "{#user.email + #user.tenantId}") + @Override + public Mono> getPermissionGroupsOfUser(User user, EntityManager entityManager) { // If the user is anonymous, then we don't need to fetch the permission groups from the database. We can just // return the cached permission group ids. @@ -65,9 +80,17 @@ public Mono> getPermissionGroupsOfUser(User user) { if (user.getEmail() == null || user.getEmail().isEmpty() || user.getId() == null) { return Mono.error(new AppsmithException(AppsmithError.SESSION_BAD_STATE)); } + Mono entityManagerMono; + if (entityManager == null) { + entityManagerMono = Mono.deferContextual(ctx -> Mono.just(ctx.getOrDefault(TX_CONTEXT, entityManager))); + } else { + entityManagerMono = Mono.just(entityManager); + } - return getInstanceAdminPermissionGroupId().map(instanceAdminPermissionGroupId -> { - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + return getInstanceAdminPermissionGroupId().zipWith(entityManagerMono).map(tuple2 -> { + final String instanceAdminPermissionGroupId = tuple2.getT1(); + EntityManager em = tuple2.getT2(); + final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaQuery cq = cb.createQuery(PermissionGroup.class); final Root root = cq.from(PermissionGroup.class); @@ -89,7 +112,7 @@ public Mono> getPermissionGroupsOfUser(User user) { cq.where(predicate); // cq.select(root.get(PermissionGroup.Fields.id)); - return entityManager.createQuery(cq).getResultList().stream() + return em.createQuery(cq).getResultList().stream() .map(PermissionGroup::getId) .collect(Collectors.toSet()); }); @@ -106,11 +129,11 @@ public Mono> preFillAnonymousUserPermissionGroupIdsCache() { log.debug( "In memory cache miss for anonymous user permission groups. Fetching from DB and adding it to in memory storage."); - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaBuilder cb = defaultEntityManager.getCriteriaBuilder(); final CriteriaQuery cq = cb.createQuery(Config.class); final Root config = cq.from(Config.class); cq.where(cb.equal(config.get(Config.Fields.name), FieldName.PUBLIC_PERMISSION_GROUP)); - final TypedQuery query = entityManager.createQuery(cq); + final TypedQuery query = defaultEntityManager.createQuery(cq); // All public access is via a single permission group. Fetch the same and set the cache with it. return Mono.fromSupplier(query::getSingleResult) @@ -145,14 +168,14 @@ public Mono getDefaultTenantId() { return Mono.just(defaultTenantId); } - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaBuilder cb = defaultEntityManager.getCriteriaBuilder(); final CriteriaQuery cq = cb.createQuery(String.class); final Root root = cq.from(Tenant.class); cq.where(cb.equal(root.get(Tenant.Fields.slug), FieldName.DEFAULT)); cq.select(root.get(Tenant.Fields.id)); - final String id = entityManager.createQuery(cq).getSingleResult(); + final String id = defaultEntityManager.createQuery(cq).getSingleResult(); if (id != null) { inMemoryCacheableRepositoryHelper.setDefaultTenantId(id); @@ -168,13 +191,13 @@ public Mono getInstanceAdminPermissionGroupId() { return Mono.just(instanceAdminPermissionGroupId); } - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaBuilder cb = defaultEntityManager.getCriteriaBuilder(); final CriteriaQuery cq = cb.createQuery(Config.class); final Root root = cq.from(Config.class); cq.where(cb.equal(root.get(Config.Fields.name), INSTANCE_CONFIG)); - return asMono(() -> Optional.of(entityManager.createQuery(cq).getSingleResult())) + return asMono(() -> Optional.of(defaultEntityManager.createQuery(cq).getSingleResult())) .map(instanceConfig -> { JSONObject config = instanceConfig.getConfig(); return (String) config.getOrDefault(DEFAULT_PERMISSION_GROUP, ""); @@ -194,7 +217,7 @@ public Mono getInstanceAdminPermissionGroupId() { public Mono fetchDefaultTenant(String tenantId) { log.info("Fetching tenant from database as it couldn't be found in the cache!"); - return Mono.deferContextual(ctx -> Mono.just(ctx.getOrDefault(TX_CONTEXT, entityManager))) + return Mono.deferContextual(ctx -> Mono.just(ctx.getOrDefault(TX_CONTEXT, defaultEntityManager))) .flatMap(em -> { BridgeQuery defaultTenantCriteria = Bridge.equal(Tenant.Fields.slug, FieldName.DEFAULT); BridgeQuery notDeletedCriteria = notDeleted(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java index cef19dc9030..b10f03fd95c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java @@ -86,7 +86,7 @@ public List findByMultipleWorkspaceIds( @Override public List findAllUserApps(AclPermission permission, User currentUser, EntityManager entityManager) { return cacheableRepositoryHelper - .getPermissionGroupsOfUser(currentUser) + .getPermissionGroupsOfUser(currentUser, entityManager) .flatMapMany(permissionGroups -> asFlux(() -> queryBuilder() .permission(permission, currentUser) .permissionGroups(permissionGroups) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomConfigRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomConfigRepositoryCEImpl.java index 6c63e056763..56bf3f730b2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomConfigRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomConfigRepositoryCEImpl.java @@ -35,7 +35,7 @@ public Optional findByName( @Override public Optional findByNameAsUser( String name, User user, AclPermission permission, User currentUser, EntityManager entityManager) { - final Set permissionGroups = getAllPermissionGroupsForUser(user); + final Set permissionGroups = getAllPermissionGroupsForUser(user, entityManager); return queryBuilder() .criteria(Bridge.equal(Config.Fields.name, name)) .permission(permission, currentUser) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomPermissionGroupRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomPermissionGroupRepositoryCEImpl.java index 2acd0d22c34..24c4baeb075 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomPermissionGroupRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomPermissionGroupRepositoryCEImpl.java @@ -105,12 +105,12 @@ public Optional evictAllPermissionGroupCachesForUser( @Override public Set getPermissionGroupsForUser(User user, EntityManager entityManager) { - return super.getPermissionGroupsForUser(user); + return super.getPermissionGroupsForUser(user, entityManager); } @Override public Set getAllPermissionGroupsIdsForUser(User user, EntityManager entityManager) { - return super.getAllPermissionGroupsForUser(user); + return super.getAllPermissionGroupsForUser(user, entityManager); } @Override diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java index ff9ad9f32fb..4170bd9561a 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java @@ -201,9 +201,6 @@ public void setup() { return; } User currentUser = sessionUserService.getCurrentUser().block(); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); installedPlugin = pluginRepository.findByPackageName("installed-plugin").block(); Workspace workspace = new Workspace(); workspace.setName("Import-Export-Test-Workspace"); @@ -212,9 +209,6 @@ public void setup() { defaultEnvironmentId = workspaceService .getDefaultEnvironmentId(workspaceId, environmentPermission.getExecutePermission()) .block(); - Set afterCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating workspace: {}", afterCreatingWorkspace); log.info("Workspace ID: {}", workspaceId); log.info("Workspace Role Ids: {}", workspace.getDefaultPermissionGroups()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java index 44edce6dcf6..1c5fd338f04 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java @@ -244,9 +244,6 @@ public void setup() throws IOException, GitAPIException { Workspace toCreate = new Workspace(); toCreate.setName("Git Service Test"); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); Workspace workspace = workspaceService.create(toCreate, apiUser, Boolean.FALSE).block(); workspaceId = workspace.getId(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java index a4b15ad5416..14eeba67ae1 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java @@ -249,9 +249,6 @@ public void setup() { return; } User currentUser = sessionUserService.getCurrentUser().block(); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); installedPlugin = pluginRepository.findByPackageName("installed-plugin").block(); Workspace workspace = new Workspace(); workspace.setName("Import-Export-Test-Workspace"); @@ -260,9 +257,6 @@ public void setup() { defaultEnvironmentId = workspaceService .getDefaultEnvironmentId(workspaceId, environmentPermission.getExecutePermission()) .block(); - Set afterCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating workspace: {}", afterCreatingWorkspace); log.info("Workspace ID: {}", workspaceId); log.info("Workspace Role Ids: {}", workspace.getDefaultPermissionGroups()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryImplTest.java index f3674e220f3..dd9c3c6309c 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryImplTest.java @@ -28,7 +28,7 @@ void testSetUserPermissionsInObject_whenPoliciesIsEmptySet_emptyCollectionValueI // Test the method setPoliciesInObject when the policies are null // The method should set an empty collection value in the object // The method should return the object - TestClass obj = baseAppsmithRepositoryImpl.setUserPermissionsInObject(new TestClass(), new User()); + TestClass obj = baseAppsmithRepositoryImpl.setUserPermissionsInObject(new TestClass(), new User(), null); assertNotNull(obj); Assertions.assertEquals(0, obj.getPolicies().size()); } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java index 00c1263d30f..4b5a725cdd4 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java @@ -125,17 +125,11 @@ public void setup() { User apiUser = userService.findByEmail("api_user").block(); Workspace toCreate = new Workspace(); toCreate.setName("LayoutServiceTest"); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); Workspace workspace = workspaceService.create(toCreate, apiUser, Boolean.FALSE).block(); assertThat(workspace).isNotNull(); workspaceId = workspace.getId(); - Set afterCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating workspace: {}", afterCreatingWorkspace); log.info("Workspace ID: {}", workspaceId); log.info("Workspace Role Ids: {}", workspace.getDefaultPermissionGroups()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ThemeServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ThemeServiceTest.java index 98915306e04..fec1527523d 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ThemeServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ThemeServiceTest.java @@ -39,7 +39,6 @@ import reactor.util.function.Tuples; import java.util.List; -import java.util.Set; import java.util.UUID; import static com.appsmith.server.acl.AclPermission.MANAGE_APPLICATIONS; @@ -123,9 +122,6 @@ public void cleanup() { private Application createApplication() { User currentUser = sessionUserService.getCurrentUser().block(); - Set beforeCreatingApplication = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingApplication); Application application = new Application(); application.setName("ThemeTest_" + UUID.randomUUID()); application.setWorkspaceId(this.workspace.getId()); @@ -133,10 +129,6 @@ private Application createApplication() { .createApplication(application, this.workspace.getId()) .block(); - Set afterCreatingApplication = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating Application: {}", afterCreatingApplication); - log.info("Workspace ID: {}", this.workspace.getId()); log.info("Workspace Role Ids: {}", this.workspace.getDefaultPermissionGroups()); log.info("Policy for created Workspace: {}", this.workspace.getPolicies()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java index 9983148ade6..05007b08d9c 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java @@ -323,9 +323,6 @@ public void setup() { Workspace toCreate = new Workspace(); toCreate.setName("ApplicationServiceTest"); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); Workspace workspace = workspaceService.create(toCreate, apiUser, Boolean.FALSE).block(); workspaceId = workspace.getId(); @@ -395,9 +392,6 @@ public void setup() { datasource1.setDatasourceStorages(storages1); testDatasource1 = datasourceService.create(datasource1).block(); - Set afterCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating workspace: {}", afterCreatingWorkspace); log.info("Workspace ID: {}", workspaceId); log.info("Workspace Role Ids: {}", workspace.getDefaultPermissionGroups()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialExportServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialExportServiceTest.java index 2e70e687925..9292cad97ce 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialExportServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialExportServiceTest.java @@ -56,7 +56,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @@ -140,9 +139,6 @@ public void setup() { return; } User currentUser = sessionUserService.getCurrentUser().block(); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); installedPlugin = pluginRepository.findByPackageName("installed-plugin").block(); Workspace workspace = new Workspace(); workspace.setName("Import-Export-Test-Workspace"); @@ -151,9 +147,6 @@ public void setup() { defaultEnvironmentId = workspaceService .getDefaultEnvironmentId(workspaceId, environmentPermission.getExecutePermission()) .block(); - Set afterCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating workspace: {}", afterCreatingWorkspace); log.info("Workspace ID: {}", workspaceId); log.info("Workspace Role Ids: {}", workspace.getDefaultPermissionGroups()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialImportServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialImportServiceTest.java index 05d929cbb29..8571d0402a9 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialImportServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/PartialImportServiceTest.java @@ -160,9 +160,6 @@ public void setup() { return; } User currentUser = sessionUserService.getCurrentUser().block(); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); installedPlugin = pluginRepository.findByPackageName("installed-plugin").block(); Workspace workspace = new Workspace(); workspace.setName("Import-Export-Test-Workspace"); @@ -171,9 +168,6 @@ public void setup() { defaultEnvironmentId = workspaceService .getDefaultEnvironmentId(workspaceId, environmentPermission.getExecutePermission()) .block(); - Set afterCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating workspace: {}", afterCreatingWorkspace); log.info("Workspace ID: {}", workspaceId); log.info("Workspace Role Ids: {}", workspace.getDefaultPermissionGroups()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCETest.java index 5f3a5dd7bc0..0103f22baf8 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCETest.java @@ -85,7 +85,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; import static com.appsmith.server.acl.AclPermission.READ_PAGES; @@ -202,16 +201,9 @@ public void setup() { Workspace toCreate = new Workspace(); toCreate.setName("ActionServiceCE_Test"); - Set beforeCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User before creating workspace: {}", beforeCreatingWorkspace); - Workspace workspace = workspaceService.create(toCreate, apiUser, Boolean.FALSE).block(); workspaceId = workspace.getId(); - Set afterCreatingWorkspace = - cacheableRepositoryHelper.getPermissionGroupsOfUser(currentUser).block(); - log.info("Permission Groups for User after creating workspace: {}", afterCreatingWorkspace); log.info("Workspace ID: {}", workspaceId); log.info("Workspace Role Ids: {}", workspace.getDefaultPermissionGroups());