From ac06cc9668de9a4d9c64231d928924a548447441 Mon Sep 17 00:00:00 2001 From: Trisha Anand Date: Tue, 9 Jun 2020 20:25:13 +0530 Subject: [PATCH] 1. user permissions during create/update of actions and datasources would now be set. 2. During update, policies are set to null in the update object to ensure that the policies are not overwritten to empty set. --- .../repositories/AppsmithRepository.java | 3 +++ .../services/ActionCollectionServiceImpl.java | 4 ++++ .../server/services/DatasourceServiceImpl.java | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) 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 53d184d5e7..5d57ac9576 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 @@ -1,6 +1,7 @@ package com.appsmith.server.repositories; import com.appsmith.server.acl.AclPermission; +import com.appsmith.server.domains.User; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.query.Criteria; import reactor.core.publisher.Flux; @@ -17,4 +18,6 @@ public interface AppsmithRepository { Flux queryAll(List criterias, AclPermission permission); Flux queryAll(List criterias, AclPermission permission, Sort sort); + + T setUserPermissionsInObject(T obj, User user); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionCollectionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionCollectionServiceImpl.java index e319bbd5af..31644a6fb3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionCollectionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionCollectionServiceImpl.java @@ -87,6 +87,10 @@ public class ActionCollectionServiceImpl implements ActionCollectionService { @Override public Mono updateAction(String id, Action action) { + + // Since the policies are server only concept, we should first set this to null. + action.setPolicies(null); + //The change was not in CollectionId, just go ahead and update normally if (action.getCollectionId() == null) { return layoutActionService.updateAction(id, action); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java index 080c249c40..41b972920c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java @@ -10,6 +10,7 @@ import com.appsmith.server.constants.AnalyticsEvents; import com.appsmith.server.constants.FieldName; import com.appsmith.server.domains.Datasource; import com.appsmith.server.domains.Organization; +import com.appsmith.server.domains.User; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.helpers.PluginExecutorHelper; @@ -93,8 +94,6 @@ public class DatasourceServiceImpl extends BaseService sessionUserService.getCurrentUser() @@ -130,6 +129,10 @@ public class DatasourceServiceImpl extends BaseService datasourceMono = repository.findById(id) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.DATASOURCE, id))); @@ -184,9 +187,18 @@ public class DatasourceServiceImpl extends BaseService validateAndSaveDatasourceToRepository(Datasource datasource) { + + Mono currentUserMono = sessionUserService.getCurrentUser(); + return Mono.just(datasource) .flatMap(this::validateDatasource) - .flatMap(repository::save); + .zipWith(currentUserMono) + .flatMap(tuple -> { + Datasource savedDatasource = tuple.getT1(); + User user = tuple.getT2(); + Datasource userPermissionsInDatasource = repository.setUserPermissionsInObject(savedDatasource, user); + return repository.save(userPermissionsInDatasource); + }); } @Override