Skip to content

Commit

Permalink
Merge branch 'dev' into feature-funnelChart
Browse files Browse the repository at this point in the history
  • Loading branch information
raheeliftikhar5 authored Dec 31, 2024
2 parents 0531190 + 6e090b5 commit b0078ef
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 34 deletions.
2 changes: 1 addition & 1 deletion client/packages/lowcoder-comps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lowcoder-comps",
"version": "2.5.4",
"version": "2.5.5",
"type": "module",
"license": "MIT",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ function useSaveComp(
if (!comp || comp === prevComp) {
return;
}

const curJson = comp.toJsonValue();
const curJsonStr = JSON.stringify(curJson);


if (!Boolean(prevAppId) && Boolean(applicationId)) {
return setPrevAppId(applicationId);
}
if (prevAppId !== applicationId) {
return setPrevAppId(applicationId);
}
if (!Boolean(prevJsonStr) && Boolean(curJsonStr)) {
setPrevComp(comp)
return setPrevJsonStr(curJsonStr);
}
if (prevJsonStr === curJsonStr) {
Expand All @@ -84,7 +85,7 @@ function useSaveComp(
setPrevComp(comp);
setPrevJsonStr(curJsonStr);
setPrevAppId(applicationId);
}, [comp, prevAppId, applicationId, prevComp, prevJsonStr, readOnly, dispatch]);
}, [comp, applicationId, readOnly, dispatch]);
}

interface AppEditorInternalViewProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const StepHeader = (props : {
title: string,
}) => (
<Flex justify="center" style={{marginBottom: '22px'}}>
<h3 style={{margin: 0}}>{props.title}</h3>
<h3 style={{margin: 0, padding: '2px 0 0 8px'}}>{props.title}</h3>
</Flex>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ public interface ApplicationRepository extends ReactiveMongoRepository<Applicati
@Aggregation(pipeline = {"{ $match: { gid: ?0 } }", "{ $project: { 'editingApplicationDSL.settings': 1, _id: 1, gid: 1, organizationId: 1, name: 1, applicationType: 1, applicationStatus: 1, publicToAll: 1, publicToMarketplace: 1, agencyProfile: 1, editingUserId: 1, lastEditedAt: 1, createdAt: 1, updatedAt: 1, createdBy: 1, modifiedBy: 1, _class: 1}}"})
Flux<Application> findByGid(@Nonnull String gid);

@Aggregation(pipeline = {"{ $match: { slug: ?0 } }", "{ $project: { 'editingApplicationDSL.settings': 1, _id: 1, gid: 1, organizationId: 1, name: 1, applicationType: 1, applicationStatus: 1, publicToAll: 1, publicToMarketplace: 1, agencyProfile: 1, editingUserId: 1, lastEditedAt: 1, createdAt: 1, updatedAt: 1, createdBy: 1, modifiedBy: 1, _class: 1}}"})
Flux<Application> findBySlug(@Nonnull String slug);

Mono<Long> countByOrganizationIdAndApplicationStatus(String organizationId, ApplicationStatus applicationStatus);

@Query("{$or : [{'publishedApplicationDSL.queries.datasourceId':?0},{'editingApplicationDSL.queries.datasourceId':?0}]}")
Flux<Application> findByDatasourceId(String datasourceId);

Flux<Application> findByIdIn(Collection<String> ids);
Flux<Application> findByGidIn(Collection<String> ids);
Flux<Application> findBySlugIn(Collection<String> slugs);

Flux<Application> findByCreatedByAndIdIn(String userId, Collection<String> ids);
Flux<Application> findByCreatedByAndGidIn(String userId, Collection<String> gids);
Flux<Application> findByCreatedByAndSlugIn(String userId, Collection<String> slugs);

/**
* Filter public applications from list of supplied IDs
Expand Down Expand Up @@ -67,6 +72,8 @@ public interface ApplicationRepository extends ReactiveMongoRepository<Applicati
* Find all agency applications
*/
Flux<Application> findByPublicToAllIsTrueAndAgencyProfileIsTrue();
Mono<Boolean> existsBySlug(String slug);

@Query("{ 'organizationId': ?0, 'slug': ?1 }")
Mono<Boolean> existsByOrganizationIdAndSlug(String organizationId, String slug);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.lowcoder.domain.permission.model.ResourceType;
import org.lowcoder.domain.permission.service.ResourcePermissionService;
import org.lowcoder.domain.user.repository.UserRepository;
import org.lowcoder.domain.util.SlugUtils;
import org.lowcoder.infra.annotation.NonEmptyMono;
import org.lowcoder.infra.mongo.MongoUpsertHelper;
import org.lowcoder.sdk.constants.FieldName;
Expand Down Expand Up @@ -60,9 +61,13 @@ public Mono<Application> findByIdWithoutDsl(String id) {
return Mono.error(new BizException(BizError.INVALID_PARAMETER, "INVALID_PARAMETER", FieldName.ID));
}

if(FieldName.isGID(id))
return Mono.from(repository.findByGid(id)).switchIfEmpty(Mono.error(new BizException(BizError.NO_RESOURCE_FOUND, "CANT_FIND_APPLICATION", id)));
return repository.findById(id)
return Mono.from(repository.findBySlug(id))
.switchIfEmpty(
Mono.defer(() -> {
if (FieldName.isGID(id))
return Mono.from(repository.findByGid(id));
return repository.findById(id);
}))
.switchIfEmpty(Mono.error(new BizException(BizError.NO_RESOURCE_FOUND, "CANT_FIND_APPLICATION", id)));
}

Expand Down Expand Up @@ -123,7 +128,7 @@ public Mono<Long> countByOrganizationId(String orgId, ApplicationStatus applicat
public Flux<Application> findByIdIn(List<String> applicationIds) {
if(!applicationIds.isEmpty() && FieldName.isGID(applicationIds.get(0)))
return repository.findByGidIn(applicationIds);
return repository.findByIdIn(applicationIds);
return repository.findBySlugIn(applicationIds).switchIfEmpty(repository.findByIdIn(applicationIds));
}

@Override
Expand Down Expand Up @@ -279,7 +284,7 @@ public Mono<Set<String>> getPrivateApplicationIds(Collection<String> application
.map(Application::getGid)
.collect(Collectors.toSet());

return repository.findByCreatedByAndIdIn(userId, applicationIds)
return repository.findByCreatedByAndSlugIn(userId, applicationIds).switchIfEmpty(repository.findByCreatedByAndIdIn(userId, applicationIds))
.map(HasIdAndAuditing::getId)
.collect(Collectors.toSet());
}
Expand Down Expand Up @@ -349,15 +354,15 @@ public Mono<Map<String, Object>> getLiveDSLByApplicationId(String applicationId)

@Override
public Mono<Application> updateSlug(String applicationId, String newSlug) {
return repository.existsBySlug(newSlug).flatMap(exists -> {
return repository.findById(applicationId).flatMap(application -> repository.existsByOrganizationIdAndSlug(application.getOrganizationId(), newSlug).flatMap(exists -> {
if (!SlugUtils.validate(newSlug)) {
return Mono.error(new BizException(BizError.SLUG_INVALID, "SLUG_INVALID"));
}
if (exists) {
return Mono.error(new BizException(BizError.DUPLICATE_ENTRY, "Slug already exists"));
return Mono.error(new BizException(BizError.SLUG_DUPLICATE_ENTRY, "SLUG_DUPLICATE_ENTRY"));
}
return repository.findById(applicationId)
.flatMap(application -> {
application.setSlug(newSlug);
return repository.save(application);
});
});
application.setSlug(newSlug);
return repository.save(application);
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ public interface OrganizationRepository extends ReactiveMongoRepository<Organiza

Flux<Organization> findByIdInAndState(Collection<String> id, OrganizationState state);
Flux<Organization> findByGidInAndState(Collection<String> gid, OrganizationState state);
Flux<Organization> findBySlugInAndState(Collection<String> slug, OrganizationState state);
Flux<Organization> findByGid(String gid);
Flux<Organization> findBySlug(String slug);
Flux<Organization> findByState(OrganizationState state);

Mono<Organization> findByIdAndState(String id, OrganizationState state);
Mono<Organization> findByGidAndState(String gid, OrganizationState state);
Mono<Organization> findBySlugAndState(String slug, OrganizationState state);

Mono<Organization> findBySourceAndThirdPartyCompanyIdAndState(String source, String tpCompanyId, OrganizationState state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.lowcoder.domain.organization.repository.OrganizationRepository;
import org.lowcoder.domain.user.model.User;
import org.lowcoder.domain.user.repository.UserRepository;
import org.lowcoder.domain.util.SlugUtils;
import org.lowcoder.infra.annotation.PossibleEmptyMono;
import org.lowcoder.infra.mongo.MongoUpsertHelper;
import org.lowcoder.sdk.config.CommonConfig;
Expand Down Expand Up @@ -169,7 +170,7 @@ public Mono<Organization> getById(String id) {
if(FieldName.isGID(id))
return repository.findByGidAndState(id, ACTIVE)
.switchIfEmpty(deferredError(UNABLE_TO_FIND_VALID_ORG, "INVALID_ORG_ID"));
return repository.findByIdAndState(id, ACTIVE)
return repository.findBySlugAndState(id, ACTIVE).switchIfEmpty(repository.findByIdAndState(id, ACTIVE))
.switchIfEmpty(deferredError(UNABLE_TO_FIND_VALID_ORG, "INVALID_ORG_ID"));
}

Expand All @@ -179,7 +180,7 @@ public Mono<OrganizationCommonSettings> getOrgCommonSettings(String orgId) {
return repository.findByGidAndState(orgId, ACTIVE)
.switchIfEmpty(deferredError(UNABLE_TO_FIND_VALID_ORG, "INVALID_ORG_ID"))
.map(Organization::getCommonSettings);
return repository.findByIdAndState(orgId, ACTIVE)
return repository.findBySlugAndState(orgId, ACTIVE).switchIfEmpty(repository.findByIdAndState(orgId, ACTIVE))
.switchIfEmpty(deferredError(UNABLE_TO_FIND_VALID_ORG, "INVALID_ORG_ID"))
.map(Organization::getCommonSettings);
}
Expand All @@ -188,7 +189,7 @@ public Mono<OrganizationCommonSettings> getOrgCommonSettings(String orgId) {
public Flux<Organization> getByIds(Collection<String> ids) {
if(!ids.isEmpty() && FieldName.isGID(ids.stream().findFirst().get()))
return repository.findByGidInAndState(ids, ACTIVE);
return repository.findByIdInAndState(ids, ACTIVE);
return repository.findBySlugInAndState(ids, ACTIVE).switchIfEmpty(repository.findByIdInAndState(ids, ACTIVE));
}

@Override
Expand Down Expand Up @@ -221,7 +222,7 @@ public Mono<Boolean> uploadLogo(String organizationId, Part filePart) {
public Mono<Boolean> deleteLogo(String organizationId) {
Mono<Organization> organizationMono;
if(FieldName.isGID(organizationId)) organizationMono = repository.findByGidAndState(organizationId, ACTIVE);
else organizationMono = repository.findByIdAndState(organizationId, ACTIVE);
else organizationMono = repository.findBySlugAndState(organizationId, ACTIVE).switchIfEmpty(repository.findByIdAndState(organizationId, ACTIVE));
return organizationMono
.flatMap(organization -> {
// delete from asset repo.
Expand Down Expand Up @@ -292,8 +293,11 @@ private String buildCommonSettingsUpdateTimeKey(String key) {
@Override
public Mono<Organization> updateSlug(String organizationId, String newSlug) {
return repository.existsBySlug(newSlug).flatMap(exists -> {
if (!SlugUtils.validate(newSlug)) {
return Mono.error(new BizException(BizError.SLUG_INVALID, "SLUG_INVALID"));
}
if (exists) {
return Mono.error(new BizException(BizError.DUPLICATE_ENTRY, "Slug already exists"));
return Mono.error(new BizException(BizError.SLUG_DUPLICATE_ENTRY, "SLUG_DUPLICATE_ENTRY"));
}
return repository.findById(organizationId)
.flatMap(organization -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.lowcoder.domain.util;

public class SlugUtils {
public static Boolean validate(String slug) {
return slug.matches("^[a-zA-Z0-9_-]*$");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public enum BizError {
ILLEGAL_BUNDLE_PERMISSION_ID(500, 6404),

//slug 6501 - 6501
DUPLICATE_ENTRY(403, 6501);
SLUG_DUPLICATE_ENTRY(403, 6501),
SLUG_INVALID(403, 6502);

static {
checkDuplicates(values(), BizError::getBizErrorCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,6 @@ ORG_DELETED_FOR_ENTERPRISE_MODE=Provided enterpriseOrgId workspace has been dele
DISABLE_AUTH_CONFIG_FORBIDDEN=Can not disable current administrator''s last identity provider.
USER_NOT_EXIST=User not exist.
DUPLICATE_AUTH_CONFIG_ADDITION=Provider auth type already added to organization
EMAIL_PROVIDER_DISABLED=Email provider is disabled.
EMAIL_PROVIDER_DISABLED=Email provider is disabled.
SLUG_DUPLICATE_ENTRY=Slug already exists
SLUG_INVALID=Slug format is invalid
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ public class GidService {
private BundleRepository bundleRepository;

public Mono<String> convertApplicationIdToObjectId(String id) {
if(FieldName.isGID(id)) {
return applicationRepository.findByGid(id).next().mapNotNull(HasIdAndAuditing::getId);
}
return Mono.just(id);
return applicationRepository.findBySlug(id).next().mapNotNull(HasIdAndAuditing::getId).switchIfEmpty(
Mono.defer(() -> {
if (FieldName.isGID(id)) {
return applicationRepository.findByGid(id).next().mapNotNull(HasIdAndAuditing::getId);
}
return Mono.just(id);
}));
}

public Mono<String> convertDatasourceIdToObjectId(String id) {
Expand All @@ -54,10 +57,13 @@ public Mono<String> convertDatasourceIdToObjectId(String id) {
}

public Mono<String> convertOrganizationIdToObjectId(String id) {
if(FieldName.isGID(id)) {
return organizationRepository.findByGid(id).next().mapNotNull(HasIdAndAuditing::getId);
}
return Mono.just(id);
return organizationRepository.findBySlug(id).next().mapNotNull(HasIdAndAuditing::getId).switchIfEmpty(
Mono.defer(() -> {
if(FieldName.isGID(id)) {
return organizationRepository.findByGid(id).next().mapNotNull(HasIdAndAuditing::getId);
}
return Mono.just(id);
}));
}

public Mono<String> convertGroupIdToObjectId(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.concurrent.atomic.AtomicInteger;

@SuppressWarnings("UnstableApiUsage")
@TestConfiguration
//@TestConfiguration
public class TestRedisConfiguration {

private static final AtomicInteger STATE = new AtomicInteger(0);
Expand Down

0 comments on commit b0078ef

Please sign in to comment.