From bea3cc1598d430aa8d70565ef7d5cd18fdf18391 Mon Sep 17 00:00:00 2001 From: Abhijeet <41686026+abhvsn@users.noreply.github.com> Date: Fri, 3 May 2024 16:56:02 +0530 Subject: [PATCH] chore: Move to interface based projection as for columns with jsonb type record based projections does not work in PG (#32909) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description - Move away from record based projections to interface classes as record based projections does not work for jsonb column in PG branch. - Remove ID generation within testclass and let DB handle the generation to fix failing tests on the PG branch. ## Automation /ok-to-test tags="@tag.Sanity, @tag.GenerateCRUD, "@tag.Fork"" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: f43425a9c1e29a35dcaba3abf47f8e63cf607def > Cypress dashboard url: Click here! ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit - **Refactor** - Updated the method for generating workspace names to enhance uniqueness and reliability. - **Bug Fixes** - Improved the `updateCurrentUser` method to update the current user based on their ID for accuracy. --- .../ApplicationForkingServiceCEImpl.java | 8 ++++---- .../server/projections/IdPoliciesOnly.java | 7 +++++-- .../ce/ApplicationPageServiceCEImpl.java | 16 ++++++++-------- .../server/services/ce/UserServiceCEImpl.java | 2 +- .../services/UserWorkspaceServiceUnitTest.java | 3 +-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/fork/internal/ApplicationForkingServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/fork/internal/ApplicationForkingServiceCEImpl.java index 882d7ff017..d7d11ea8e1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/fork/internal/ApplicationForkingServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/fork/internal/ApplicationForkingServiceCEImpl.java @@ -595,8 +595,8 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic .findIdsAndPoliciesByApplicationIdIn(List.of(application.getId())) .map(idPoliciesOnly -> { NewPage newPage = new NewPage(); - newPage.setId(idPoliciesOnly.id()); - newPage.setPolicies(idPoliciesOnly.policies()); + newPage.setId(idPoliciesOnly.getId()); + newPage.setPolicies(idPoliciesOnly.getPolicies()); return newPage; }) .flatMap(newPageRepository::setUserPermissionsInObject)); @@ -605,8 +605,8 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic .findIdsAndPoliciesByApplicationIdIn(List.of(application.getId())) .map(idPoliciesOnly -> { NewAction newAction = new NewAction(); - newAction.setId(idPoliciesOnly.id()); - newAction.setPolicies(idPoliciesOnly.policies()); + newAction.setId(idPoliciesOnly.getId()); + newAction.setPolicies(idPoliciesOnly.getPolicies()); return newAction; }) .flatMap(newActionRepository::setUserPermissionsInObject)); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/projections/IdPoliciesOnly.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/projections/IdPoliciesOnly.java index 852cb022a6..2f5be1b8f8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/projections/IdPoliciesOnly.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/projections/IdPoliciesOnly.java @@ -1,8 +1,11 @@ package com.appsmith.server.projections; import com.appsmith.external.models.Policy; -import lombok.NonNull; import java.util.Set; -public record IdPoliciesOnly(@NonNull String id, Set policies) {} +public interface IdPoliciesOnly { + String getId(); + + Set getPolicies(); +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java index cca0502645..5cdb345ed3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java @@ -1470,8 +1470,8 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { .findIdsAndPoliciesByApplicationIdIn(List.of(application.getId())) .map(idPoliciesOnly -> { NewPage newPage = new NewPage(); - newPage.setId(idPoliciesOnly.id()); - newPage.setPolicies(idPoliciesOnly.policies()); + newPage.setId(idPoliciesOnly.getId()); + newPage.setPolicies(idPoliciesOnly.getPolicies()); return newPage; }) .flatMap(newPageRepository::setUserPermissionsInObject)); @@ -1479,8 +1479,8 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { .findIdsAndPoliciesByApplicationIdIn(List.of(application.getId())) .map(idPoliciesOnly -> { NewAction newAction = new NewAction(); - newAction.setId(idPoliciesOnly.id()); - newAction.setPolicies(idPoliciesOnly.policies()); + newAction.setId(idPoliciesOnly.getId()); + newAction.setPolicies(idPoliciesOnly.getPolicies()); return newAction; }) .flatMap(newActionRepository::setUserPermissionsInObject)); @@ -1488,8 +1488,8 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { .findIdsAndPoliciesByApplicationIdIn(List.of(application.getId())) .map(idPoliciesOnly -> { ActionCollection actionCollection = new ActionCollection(); - actionCollection.setId(idPoliciesOnly.id()); - actionCollection.setPolicies(idPoliciesOnly.policies()); + actionCollection.setId(idPoliciesOnly.getId()); + actionCollection.setPolicies(idPoliciesOnly.getPolicies()); return actionCollection; }) .flatMap(actionCollectionRepository::setUserPermissionsInObject)); @@ -1538,8 +1538,8 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { .findIdsAndPoliciesByIdIn(datasourceIds) .flatMap(idPolicy -> { Datasource datasource = new Datasource(); - datasource.setId(idPolicy.id()); - datasource.setPolicies(idPolicy.policies()); + datasource.setId(idPolicy.getId()); + datasource.setPolicies(idPolicy.getPolicies()); return datasourceRepository.setUserPermissionsInObject(datasource); })); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java index 7d0c0fa605..31ca2b39e6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java @@ -608,7 +608,7 @@ public class UserServiceCEImpl extends BaseService updates.setName(inputName); updatedUserMono = sessionUserService .getCurrentUser() - .flatMap(user -> update(user.getEmail(), updates, User.Fields.email) + .flatMap(user -> update(user.getId(), updates, User.Fields.id) .then( exchange == null ? repository.findByEmail(user.getEmail()) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserWorkspaceServiceUnitTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserWorkspaceServiceUnitTest.java index 27ab280072..139c87b94f 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserWorkspaceServiceUnitTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserWorkspaceServiceUnitTest.java @@ -103,8 +103,7 @@ public class UserWorkspaceServiceUnitTest { List workspaceList = new ArrayList<>(4); for (int i = 1; i <= 4; i++) { Workspace workspace = new Workspace(); - workspace.setId("org-" + i); - workspace.setName(workspace.getId()); + workspace.setName(UUID.randomUUID().toString()); workspaceList.add(workspace); } return Flux.fromIterable(workspaceList)