Skip to content
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 @@ -280,13 +280,16 @@ public Mono<ActionCollectionDTO> update(String id, ActionCollectionDTO actionCol

@Override
public Mono<ActionCollectionDTO> deleteWithoutPermissionUnpublishedActionCollection(String id) {
return deleteUnpublishedActionCollection(id, null, actionPermission.getDeletePermission());
return actionPermission
.getDeletePermission()
.flatMap(permission -> deleteUnpublishedActionCollection(id, null, permission));
}

@Override
public Mono<ActionCollectionDTO> deleteUnpublishedActionCollection(String id) {
return deleteUnpublishedActionCollection(
id, actionPermission.getDeletePermission(), actionPermission.getDeletePermission());
return actionPermission
.getDeletePermission()
.flatMap(permission -> deleteUnpublishedActionCollection(id, permission, permission));
}

@Override
Expand Down Expand Up @@ -418,10 +421,12 @@ public Mono<ActionCollection> archiveById(String id) {
}

protected Mono<ActionCollection> archiveGivenActionCollection(ActionCollection actionCollection) {
Flux<NewAction> unpublishedJsActionsFlux = newActionService.findByCollectionIdAndViewMode(
actionCollection.getId(), false, actionPermission.getDeletePermission());
Flux<NewAction> publishedJsActionsFlux = newActionService.findByCollectionIdAndViewMode(
actionCollection.getId(), true, actionPermission.getDeletePermission());
Mono<AclPermission> deleteActionPermissionMono =
actionPermission.getDeletePermission().cache();
Flux<NewAction> unpublishedJsActionsFlux = deleteActionPermissionMono.flatMapMany(permission ->
newActionService.findByCollectionIdAndViewMode(actionCollection.getId(), false, permission));
Flux<NewAction> publishedJsActionsFlux = deleteActionPermissionMono.flatMapMany(permission ->
newActionService.findByCollectionIdAndViewMode(actionCollection.getId(), true, permission));
return unpublishedJsActionsFlux
.mergeWith(publishedJsActionsFlux)
.flatMap(toArchive -> newActionService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
Expand Down Expand Up @@ -172,84 +173,102 @@ private Mono<ImportActionCollectionResultDTO> importActionCollections(
// collections
resultDTO.setExistingActionCollections(actionsCollectionsInCurrentArtifact.values());

List<ActionCollection> newActionCollections = new ArrayList<>();
List<ActionCollection> existingActionCollections = new ArrayList<>();

for (ActionCollection actionCollection : importedActionCollectionList) {
final ActionCollectionDTO unpublishedCollection =
actionCollection.getUnpublishedCollection();
if (unpublishedCollection == null
|| StringUtils.isEmpty(unpublishedCollection.calculateContextId())) {
continue; // invalid action collection, skip it
}

String idFromJsonFile = actionCollection.getId();

ActionCollection branchedActionCollection = null;

if (actionsCollectionsInBranches.containsKey(actionCollection.getGitSyncId())) {
branchedActionCollection =
artifactBasedImportableService
.getExistingEntityInOtherBranchForImportedEntity(
mappedImportableResourcesDTO,
actionsCollectionsInBranches,
actionCollection);
}

Context baseContext = populateIdReferencesAndReturnBaseContext(
importingMetaDTO,
mappedImportableResourcesDTO,
artifact,
branchedActionCollection,
actionCollection);

// Check if the action has gitSyncId and if it's already in DB
if (existingArtifactContainsCollection(
actionsCollectionsInCurrentArtifact, actionCollection)) {

// Since the resource is already present in DB, just update resource
ActionCollection existingActionCollection =
artifactBasedImportableService
.getExistingEntityInCurrentBranchForImportedEntity(
mappedImportableResourcesDTO,
actionsCollectionsInCurrentArtifact,
actionCollection);

updateExistingCollection(
importingMetaDTO,
mappedImportableResourcesDTO,
actionCollection,
existingActionCollection);

existingActionCollections.add(existingActionCollection);
resultDTO.getSavedActionCollectionIds().add(existingActionCollection.getId());
resultDTO
.getSavedActionCollectionMap()
.put(idFromJsonFile, existingActionCollection);
} else {
artifactBasedImportableService.createNewResource(
importingMetaDTO, actionCollection, baseContext);

populateDomainMappedReferences(mappedImportableResourcesDTO, actionCollection);

// it's new actionCollection
newActionCollections.add(actionCollection);
resultDTO.getSavedActionCollectionIds().add(actionCollection.getId());
resultDTO.getSavedActionCollectionMap().put(idFromJsonFile, actionCollection);
}
}
log.info(
"Saving action collections in bulk. New: {}, Updated: {}",
newActionCollections.size(),
existingActionCollections.size());
return Mono.when(
actionCollectionService
.bulkValidateAndInsertActionCollectionInRepository(
newActionCollections),
actionCollectionService
.bulkValidateAndUpdateActionCollectionInRepository(
existingActionCollections))
.thenReturn(resultDTO);
// Use a synchronised list to avoid concurrent modification exception
List<ActionCollection> newActionCollections =
Collections.synchronizedList(new ArrayList<>());
List<ActionCollection> existingActionCollections =
Collections.synchronizedList(new ArrayList<>());

return Flux.fromIterable(importedActionCollectionList)
.flatMap(actionCollection -> {
final ActionCollectionDTO unpublishedCollection =
actionCollection.getUnpublishedCollection();
if (unpublishedCollection == null
|| StringUtils.isEmpty(
unpublishedCollection.calculateContextId())) {
return Mono.empty(); // invalid action collection, skip it
}

String idFromJsonFile = actionCollection.getId();

ActionCollection branchedActionCollection = null;

if (actionsCollectionsInBranches.containsKey(
actionCollection.getGitSyncId())) {
branchedActionCollection =
artifactBasedImportableService
.getExistingEntityInOtherBranchForImportedEntity(
mappedImportableResourcesDTO,
actionsCollectionsInBranches,
actionCollection);
}

Context baseContext = populateIdReferencesAndReturnBaseContext(
importingMetaDTO,
mappedImportableResourcesDTO,
artifact,
branchedActionCollection,
actionCollection);

// Check if the action has gitSyncId and if it's already in DB
if (existingArtifactContainsCollection(
actionsCollectionsInCurrentArtifact, actionCollection)) {

// Since the resource is already present in DB, just update resource
ActionCollection existingActionCollection =
artifactBasedImportableService
.getExistingEntityInCurrentBranchForImportedEntity(
mappedImportableResourcesDTO,
actionsCollectionsInCurrentArtifact,
actionCollection);

updateExistingCollection(
importingMetaDTO,
mappedImportableResourcesDTO,
actionCollection,
existingActionCollection);

existingActionCollections.add(existingActionCollection);
resultDTO
.getSavedActionCollectionIds()
.add(existingActionCollection.getId());
resultDTO
.getSavedActionCollectionMap()
.put(idFromJsonFile, existingActionCollection);
return Mono.just(existingActionCollection);
}
return artifactBasedImportableService
.createNewResource(importingMetaDTO, actionCollection, baseContext)
.flatMap(updatedActionCollection -> {
// populate the domain mapped references
populateDomainMappedReferences(
mappedImportableResourcesDTO, updatedActionCollection);

// it's new actionCollection
newActionCollections.add(updatedActionCollection);
resultDTO
.getSavedActionCollectionIds()
.add(updatedActionCollection.getId());
resultDTO
.getSavedActionCollectionMap()
.put(idFromJsonFile, updatedActionCollection);
return Mono.just(updatedActionCollection);
});
})
.then(Mono.defer(() -> {
log.info(
"Saving action collections in bulk. New: {}, Updated: {}",
newActionCollections.size(),
existingActionCollections.size());
return Mono.when(
actionCollectionService
.bulkValidateAndInsertActionCollectionInRepository(
newActionCollections),
actionCollectionService
.bulkValidateAndUpdateActionCollectionInRepository(
existingActionCollections))
.thenReturn(resultDTO);
}));
});
})
.onErrorResume(e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -88,26 +89,31 @@ public Context updateContextInResource(
}

@Override
public void createNewResource(
public Mono<ActionCollection> createNewResource(
ImportingMetaDTO importingMetaDTO, ActionCollection actionCollection, Context baseContext) {
if (!importingMetaDTO.getPermissionProvider().canCreateAction((NewPage) baseContext)) {
throw new AppsmithException(
AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.PAGE, ((NewPage) baseContext).getId());
}
Mono<Boolean> canCreateAction = importingMetaDTO.getPermissionProvider().canCreateAction((NewPage) baseContext);
return canCreateAction.flatMap(canCreate -> {
if (!canCreate) {
return Mono.error(new AppsmithException(
AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.PAGE, ((NewPage) baseContext).getId()));
}

// this will generate the id and other auto generated fields e.g. createdAt
actionCollection.updateForBulkWriteOperation();
actionCollectionService.generateAndSetPolicies((NewPage) baseContext, actionCollection);
// this will generate the id and other auto generated fields e.g. createdAt
actionCollection.updateForBulkWriteOperation();
actionCollectionService.generateAndSetPolicies((NewPage) baseContext, actionCollection);

// create or update base id for the action
// values already set to base id are kept unchanged
actionCollection.setBaseId(actionCollection.getBaseIdOrFallback());
actionCollection.setRefType(importingMetaDTO.getRefType());
actionCollection.setRefName(importingMetaDTO.getRefName());
// create or update base id for the action
// values already set to base id are kept unchanged
actionCollection.setBaseId(actionCollection.getBaseIdOrFallback());
actionCollection.setRefType(importingMetaDTO.getRefType());
actionCollection.setRefName(importingMetaDTO.getRefName());

// generate gitSyncId if it's not present
if (actionCollection.getGitSyncId() == null) {
actionCollection.setGitSyncId(actionCollection.getApplicationId() + "_" + UUID.randomUUID());
}
// generate gitSyncId if it's not present
if (actionCollection.getGitSyncId() == null) {
actionCollection.setGitSyncId(actionCollection.getApplicationId() + "_" + UUID.randomUUID());
}

return Mono.just(actionCollection);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,9 @@ protected List<Mono<Void>> updatePoliciesForIndependentDomains(
// the same level in the hierarchy. A user may have permission to change view on application, but
// may not have explicit permissions on the datasource.
Mono<Void> updatedDatasourcesMono = datasourceIdsMono
.flatMapMany(datasourceIds -> {
return policySolution.updateWithNewPoliciesToDatasourcesByDatasourceIdsWithoutPermission(
datasourceIds, datasourcePolicyMap, addViewAccess);
})
.flatMapMany(datasourceIds ->
policySolution.updateWithNewPoliciesToDatasourcesByDatasourceIdsWithoutPermission(
datasourceIds, datasourcePolicyMap, addViewAccess))
.then();

list.add(updatedDatasourcesMono);
Expand Down
Loading