Merge pull request #19295 from appsmithorg/merge/back-merge-v-1-8-15

chore: Back merge v.1.8.15
This commit is contained in:
Nidhi 2022-12-29 11:35:59 +05:30 committed by GitHub
commit 618c497aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 17 deletions

View File

@ -1049,6 +1049,7 @@ export const MANDATORY_FIELDS_ERROR = () => "Mandatory fields cannot be empty";
// Audit logs begin
export const AUDIT_LOGS = () => "Audit Logs";
export const TRY_AGAIN_WITH_YOUR_FILTER = () => "Try again with your filter";
// Audit logs Upgrade page begin
export const INTRODUCING = (featureName: string) =>

View File

@ -43,8 +43,8 @@ public class PageControllerCE {
@Autowired
public PageControllerCE(ApplicationPageService applicationPageService,
NewPageService newPageService,
CreateDBTablePageSolution createDBTablePageSolution
NewPageService newPageService,
CreateDBTablePageSolution createDBTablePageSolution
) {
this.applicationPageService = applicationPageService;
this.newPageService = newPageService;
@ -122,9 +122,10 @@ public class PageControllerCE {
* In case the page has never been published, the page gets deleted.
* In case the page has been published, this page would eventually get deleted whenever the application is published
* next.
*
* @param defaultPageId defaultPageId which will be needed to find the actual page that needs to be deleted
* @param branchName git branch to find the exact page which needs to be deleted
* @return deleted page DTO
* @return deleted page DTO
*/
@DeleteMapping("/{defaultPageId}")
public Mono<ResponseDTO<PageDTO>> deletePage(@PathVariable String defaultPageId,
@ -155,10 +156,11 @@ public class PageControllerCE {
* If Application ID is present, it'll fetch all pages of that application in the provided mode.
* if Page ID is present, it'll fetch all pages of the corresponding Application.
* If both IDs are present, it'll use the Application ID only and ignore the Page ID
*
* @param applicationId Id of the application
* @param pageId id of a page
* @param mode In which mode it's in
* @param branchName name of the current branch
* @param pageId id of a page
* @param mode In which mode it's in
* @param branchName name of the current branch
* @return List of ApplicationPagesDTO along with other meta data
*/
@GetMapping
@ -166,6 +168,7 @@ public class PageControllerCE {
@RequestParam(required = false) String pageId,
@RequestParam(required = true, defaultValue = "EDIT") ApplicationMode mode,
@RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) {
log.debug("Going to fetch applicationPageDTO for applicationId: {}, pageId: {}, branchName: {}, mode: {}", applicationId, pageId, branchName, mode);
return newPageService.findApplicationPages(applicationId, pageId, branchName, mode)
.map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null));
}

View File

@ -24,11 +24,13 @@ public interface CustomNewPageRepositoryCE extends AppsmithRepository<NewPage> {
Mono<NewPage> findByNameAndApplicationIdAndViewMode(String name, String applicationId, AclPermission aclPermission, Boolean viewMode);
Flux<NewPage> findAllByIds(List<String> ids, AclPermission aclPermission);
Flux<NewPage> findAllPageDTOsByIds(List<String> ids, AclPermission aclPermission);
Mono<String> getNameByPageId(String pageId, boolean isPublishedName);
Mono<NewPage> findPageByBranchNameAndDefaultPageId(String branchName, String defaultPageId, AclPermission permission);
Flux<NewPage> findSlugsByApplicationIds(List<String> applicationIds, AclPermission aclPermission);
Mono<NewPage> findRootApplicationIdById(String defaultPageId, AclPermission readPermission);
}

View File

@ -5,7 +5,10 @@ import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.NewPage;
import com.appsmith.server.domains.QLayout;
import com.appsmith.server.domains.QNewPage;
import com.appsmith.server.domains.User;
import com.appsmith.server.dtos.PageDTO;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.repositories.BaseAppsmithRepositoryImpl;
import com.appsmith.server.repositories.CacheableRepositoryHelper;
import lombok.extern.slf4j.Slf4j;
@ -13,6 +16,7 @@ import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@ -50,6 +54,27 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl<Ne
return queryAll(List.of(applicationIdCriteria, activeEditModeCriteria), aclPermission);
}
@Override
public Mono<NewPage> findRootApplicationIdById(String id, AclPermission permission) {
if (id == null) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID));
}
return ReactiveSecurityContextHolder.getContext()
.map(ctx -> ctx.getAuthentication())
.map(auth -> auth.getPrincipal())
.flatMap(principal -> getAllPermissionGroupsForUser((User) principal))
.flatMap(permissionGroups -> {
Query query = new Query(getIdCriteria(id));
query.fields().include(FieldName.APPLICATION_ID, FieldName.DEFAULT_RESOURCES);
query.addCriteria(new Criteria().andOperator(notDeleted(), userAcl(permissionGroups, permission)));
return mongoOperations.query(this.genericDomain)
.matching(query)
.one()
.flatMap(obj -> setUserPermissionsInObject(obj, permissionGroups));
});
}
@Override
public Mono<NewPage> findByIdAndLayoutsIdAndViewMode(String id, String layoutId, AclPermission aclPermission, Boolean viewMode) {
String layoutsIdKey;
@ -65,7 +90,7 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl<Ne
layoutsKey = fieldName(QNewPage.newPage.unpublishedPage) + "." + fieldName(QNewPage.newPage.unpublishedPage.layouts);
// In case a page has been deleted in edit mode, but still exists in deployed mode, NewPage object would exist. To handle this, only fetch non-deleted pages
Criteria deletedCriterion = where (fieldName(QNewPage.newPage.unpublishedPage) + "." + fieldName(QNewPage.newPage.unpublishedPage.deletedAt)).is(null);
Criteria deletedCriterion = where(fieldName(QNewPage.newPage.unpublishedPage) + "." + fieldName(QNewPage.newPage.unpublishedPage.deletedAt)).is(null);
criteria.add(deletedCriterion);
}
layoutsIdKey = layoutsKey + "." + fieldName(QLayout.layout.id);
@ -86,7 +111,7 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl<Ne
if (Boolean.FALSE.equals(viewMode)) {
// In case a page has been deleted in edit mode, but still exists in deployed mode, NewPage object would exist. To handle this, only fetch non-deleted pages
Criteria deletedCriterion = where (fieldName(QNewPage.newPage.unpublishedPage) + "." + fieldName(QNewPage.newPage.unpublishedPage.deletedAt)).is(null);
Criteria deletedCriterion = where(fieldName(QNewPage.newPage.unpublishedPage) + "." + fieldName(QNewPage.newPage.unpublishedPage.deletedAt)).is(null);
criteria.add(deletedCriterion);
}
@ -106,7 +131,7 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl<Ne
if (Boolean.FALSE.equals(viewMode)) {
// In case a page has been deleted in edit mode, but still exists in deployed mode, NewPage object would exist. To handle this, only fetch non-deleted pages
Criteria deletedCriteria = where (fieldName(QNewPage.newPage.unpublishedPage) + "." + fieldName(QNewPage.newPage.unpublishedPage.deletedAt)).is(null);
Criteria deletedCriteria = where(fieldName(QNewPage.newPage.unpublishedPage) + "." + fieldName(QNewPage.newPage.unpublishedPage.deletedAt)).is(null);
criteria.add(deletedCriteria);
}
@ -114,11 +139,27 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl<Ne
}
@Override
public Flux<NewPage> findAllByIds(List<String> ids, AclPermission aclPermission) {
Criteria idsCriterion = where("id")
.in(ids);
public Flux<NewPage> findAllPageDTOsByIds(List<String> ids, AclPermission aclPermission) {
ArrayList<String> includedFields = new ArrayList<>(List.of(
FieldName.APPLICATION_ID,
FieldName.DEFAULT_RESOURCES,
"unpublishedPage.name",
"unpublishedPage.isHidden",
"unpublishedPage.slug",
"unpublishedPage.customSlug",
"publishedPage.name",
"publishedPage.isHidden",
"publishedPage.slug",
"publishedPage.customSlug"
));
return queryAll(List.of(idsCriterion), aclPermission);
Criteria idsCriterion = where("id").in(ids);
return this.queryAll(
new ArrayList<>(List.of(idsCriterion)),
includedFields,
aclPermission,
null);
}
private Criteria getNameCriterion(String name, Boolean viewMode) {

View File

@ -244,6 +244,7 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
return Mono.just(application);
})
.flatMap(application -> {
log.debug("Fetched application data for id: {}", applicationId);
if (markApplicationAsRecentlyAccessed) {
// add this application and workspace id to the recently used list in UserData
return userDataService.updateLastUsedAppAndWorkspaceList(application)
@ -282,13 +283,15 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
}
return pages.stream().map(page -> page.getId()).collect(Collectors.toList());
})
.flatMapMany(pageIds -> repository.findAllByIds(pageIds, pagePermission.getReadPermission()))
.flatMapMany(pageIds -> repository.findAllPageDTOsByIds(pageIds, pagePermission.getReadPermission()))
.collectList()
.flatMap(pagesFromDb -> Mono.zip(
Mono.just(pagesFromDb),
defaultPageIdMono,
applicationMono
)).flatMap(tuple -> {
))
.flatMap(tuple -> {
log.debug("Retrieved Page DTOs from DB ...");
List<NewPage> pagesFromDb = tuple.getT1();
String defaultPageId = tuple.getT2();
@ -353,6 +356,7 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
return Mono.zip(applicationMono, pagesListMono)
.map(tuple -> {
log.debug("Populating applicationPagesDTO ...");
Application application = tuple.getT1();
application.setPages(null);
application.setPublishedPages(null);
@ -591,7 +595,7 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
if (!StringUtils.hasLength(defaultPageId)) {
return Mono.error(new AppsmithException(INVALID_PARAMETER, FieldName.PAGE_ID, defaultPageId));
}
getPageMono = repository.findById(defaultPageId, pagePermission.getReadPermission());
getPageMono = repository.findRootApplicationIdById(defaultPageId, pagePermission.getReadPermission());
} else {
getPageMono = repository.findPageByBranchNameAndDefaultPageId(branchName, defaultPageId, pagePermission.getReadPermission());
}
@ -600,6 +604,7 @@ public class NewPageServiceCEImpl extends BaseService<NewPageRepository, NewPage
new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.PAGE_ID, defaultPageId + ", " + branchName))
)
.map(newPage -> {
log.debug("Retrieved possible application ids for page, picking the appropriate one now");
if (newPage.getDefaultResources() != null) {
return newPage.getDefaultResources().getApplicationId();
} else {